2 Star 0 Fork 0

TO1SOURCE / jsonql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
plopfile.js 3.08 KB
一键复制 编辑 原始数据 按行查看 历史
Joel Chu 提交于 2022-04-19 11:44 . fix up the plop script
const fs = require('fs-extra')
const { join } = require('path')
const { camelCase } = require('lodash')
const root = __dirname
// use some of the value as default
const rootPkgJson = fs.readJsonSync(join(root, 'package.json'))
/**
Tools for:
1. generate template for new packages
Files are inside the `.plop` folder
**/
module.exports = function(plop) {
plop.setGenerator('setupNewPackage', {
description: 'Setup new package',
prompts: [
{
type: 'input',
name: 'projectName',
message: 'Project name',
transform: camelCase
},
{
type: 'confirm',
name: 'sameAsProjectName',
message: 'Use project name as directory name',
default: false
},
{
type: 'input',
name: 'directoryName',
message: 'Directory name (No space allow)',
validate: (value) => !(/^[\w\s]{1,}$/.test(value)),
when: function(answers) {
return !answers.sameAsProjectName
},
default: function(answers) {
return camelCase(answers.projectName)
}
},
// just use the root package.json to fill out the blanks
],
actions:
function(answers) {
// prepare some vars
const projectRoot = join(root, 'packages', answers.sameAsProjectName ? answers.projectName : answers.directoryName)
const tmplRoot = join(root, '.plop', 'packages')
return [
// copy
function(answer) {
const { directoryName, projectName, sameAsProjectName } = answer
const directory = sameAsProjectName ? projectName : directoryName
// console.log(directory)
const dir = join(root, 'packages', directory )
// console.log(dir)
if (fs.existsSync( dir )) {
// keep it consistence, we don't necessary to return as Promise here
return Promise.resolve(`Directory ${dir} already exist! Aborted`)
} else {
const src = join(root, '.plop', 'packages')
const filter = (file) => !(file.indexOf('package.json.tpl') > -1) && !(file.indexOf('README.tpl') > -1)
return fs.copy(src, dir, { filter })
.then(() => `New package ${camelCase(projectName)} created in packages/${directory}`)
.catch(() => `Fail to create ${directory}`)
}
},
// update package.json
{
type: 'add',
templateFile: join(tmplRoot, 'package.json.tpl'),
path: join(projectRoot, 'package.json'),
data: {
// need to make it a scope package name
name: ['@' + rootPkgJson.name, camelCase(answers.projectName)].join('/'),
projectName: answers.projectName,
author: rootPkgJson.author,
license: rootPkgJson.license,
homepage: rootPkgJson.homepage
},
},
{
type: 'add',
templateFile: join(tmplRoot, 'README.tpl'),
path: join(projectRoot, 'README.md')
}
]
}
})
}
TypeScript
1
https://gitee.com/to1source/jsonql.git
git@gitee.com:to1source/jsonql.git
to1source
jsonql
jsonql
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891