|
|
@ -1,29 +1,6 @@ |
|
|
|
const fs = require('fs'); |
|
|
|
const fs = require('fs'); |
|
|
|
const path = require('path'); |
|
|
|
const path = require('path'); |
|
|
|
|
|
|
|
|
|
|
|
function getArgs (startIndex = 1) { |
|
|
|
|
|
|
|
const args = {}; |
|
|
|
|
|
|
|
process.argv |
|
|
|
|
|
|
|
.slice(startIndex, process.argv.length) |
|
|
|
|
|
|
|
.forEach(arg => { |
|
|
|
|
|
|
|
// long arg
|
|
|
|
|
|
|
|
if (arg.slice(0, 2) === '--') { |
|
|
|
|
|
|
|
const longArg = arg.split('='); |
|
|
|
|
|
|
|
const longArgFlag = longArg[0].slice(2, longArg[0].length); |
|
|
|
|
|
|
|
const longArgValue = longArg.length > 1 ? longArg[1] : true; |
|
|
|
|
|
|
|
args[longArgFlag] = longArgValue; |
|
|
|
|
|
|
|
// flags
|
|
|
|
|
|
|
|
} else if (arg[0] === '-') { |
|
|
|
|
|
|
|
const flags = arg.slice(1, arg.length).split(''); |
|
|
|
|
|
|
|
flags.forEach(flag => { |
|
|
|
|
|
|
|
args[flag] = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return args; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function scanAndCreate(structure, root = process.cwd()) { |
|
|
|
function scanAndCreate(structure, root = process.cwd()) { |
|
|
|
Object.keys(structure) |
|
|
|
Object.keys(structure) |
|
|
|
.forEach(name => { |
|
|
|
.forEach(name => { |
|
|
@ -42,18 +19,16 @@ function scanAndCreate(structure, root = process.cwd()) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|
exec: async () => { |
|
|
|
exec: async args => { |
|
|
|
const args = getArgs(process.argv); |
|
|
|
if (!args.init) { |
|
|
|
|
|
|
|
|
|
|
|
if (!args['-init']) { |
|
|
|
|
|
|
|
throw new Error('command not found'); |
|
|
|
throw new Error('command not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!args['--name']) { |
|
|
|
if (!args.name) { |
|
|
|
throw new Error('fileName not found'); |
|
|
|
throw new Error('fileName not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const name = args['--name']; |
|
|
|
const name = args.name; |
|
|
|
|
|
|
|
|
|
|
|
const structure = { |
|
|
|
const structure = { |
|
|
|
[`${name}_worker`]: { |
|
|
|
[`${name}_worker`]: { |
|
|
|