Browse Source

fix: 修改下bug

es6
iapyang 3 years ago
parent
commit
fe167b604b
  1. 10
      bin/cli/cli.js
  2. 4
      bin/cli/worker/cli.worker.js

10
bin/cli/cli.js

@ -15,7 +15,7 @@ function getArgs (startIndex = 1) {
args[longArgFlag] = longArgValue;
// flags
} else if (arg[0] === '-') {
const flags = arg.slice(1, arg.length).split('');
const flags = arg.slice(1, arg.length);
args[flags] = true;
}
});
@ -27,10 +27,12 @@ const cmds = new Map([
['worker', workerCmd],
]);
const startIndex = process.argv.findIndex(argv => argv === 'fui-cli');
const baseCmd = 'fui-cli';
const startIndex = process.argv.findIndex(argv => argv.indexOf(baseCmd) !== -1);
if (startIndex === -1) {
throw new Error('commad not found');
throw new Error(`Command ${baseCmd} not found in args`);
}
const cmd = process.argv[startIndex + 1];
@ -38,5 +40,5 @@ const cmd = process.argv[startIndex + 1];
if (cmds.has(cmd)) {
cmds.get(cmd)?.exec(getArgs(startIndex + 2));
} else {
throw new Error('命令不存在');
throw new Error(`Command ${cmd} not supported`);
}

4
bin/cli/worker/cli.worker.js

@ -21,11 +21,11 @@ function scanAndCreate(structure, root = process.cwd()) {
module.exports = {
exec: async args => {
if (!args.init) {
throw new Error('command not found');
throw new Error(`Command init not found in args`);
}
if (!args.name) {
throw new Error('fileName not found');
throw new Error('Command --name=... not found in args');
}
const name = args.name;

Loading…
Cancel
Save