Browse Source
* commit 'd4cc84dafdb8d84981f9f3ea4d074edfc0c60c20': chore: 去掉不需要的依赖 fix: 修改下bug chore: 小小重构下 chore: 增加环境 chore: 修改路径 chore: 更改npm包 chore: 增加npm打包 chore: 打包命令 feat: 设置template chore: 修改eslintes6
superman
3 years ago
8 changed files with 126 additions and 3 deletions
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const workerCmd = require('./worker/cli.worker'); |
||||
|
||||
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); |
||||
args[flags] = true; |
||||
} |
||||
}); |
||||
|
||||
return args; |
||||
} |
||||
|
||||
const cmds = new Map([ |
||||
['worker', workerCmd], |
||||
]); |
||||
|
||||
const baseCmd = 'fui-cli'; |
||||
|
||||
const startIndex = process.argv.findIndex(argv => argv.indexOf(baseCmd) !== -1); |
||||
|
||||
if (startIndex === -1) { |
||||
throw new Error(`Command ${baseCmd} not found in args`); |
||||
} |
||||
|
||||
const cmd = process.argv[startIndex + 1]; |
||||
|
||||
if (cmds.has(cmd)) { |
||||
cmds.get(cmd)?.exec(getArgs(startIndex + 2)); |
||||
} else { |
||||
throw new Error(`Command ${cmd} not supported`); |
||||
} |
@ -0,0 +1,62 @@
|
||||
const fs = require('fs'); |
||||
const path = require('path'); |
||||
|
||||
function scanAndCreate(structure, root = process.cwd()) { |
||||
Object.keys(structure) |
||||
.forEach(name => { |
||||
if (typeof structure[name] === 'object') { |
||||
fs.mkdirSync(path.resolve(root, name)); |
||||
|
||||
scanAndCreate(structure[name], path.resolve(root, `./${name}`)); |
||||
} else if (structure[name] === '') { |
||||
fs.appendFileSync(path.resolve(root, name), ''); |
||||
} else if (typeof structure[name] === 'string') { |
||||
const content = fs.readFileSync(structure[name]).toString(); |
||||
|
||||
fs.appendFileSync(path.resolve(root, name), content); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
module.exports = { |
||||
exec: async args => { |
||||
if (!args.init) { |
||||
throw new Error(`Command init not found in args`); |
||||
} |
||||
|
||||
if (!args.name) { |
||||
throw new Error('Command --name=... not found in args'); |
||||
} |
||||
|
||||
const name = args.name; |
||||
|
||||
const structure = { |
||||
[`${name}_worker`]: { |
||||
'main_thread': { |
||||
action: {}, |
||||
[`${name}_main_thread.ts`]: path.resolve(__dirname, './template/main_thread_template.ts'), |
||||
}, |
||||
utils: { |
||||
'action_type.ts': '', |
||||
}, |
||||
'worker_thread': { |
||||
action: {}, |
||||
[`${name}_worker_thread.ts`]: path.resolve(__dirname, './template/worker_thread_template.ts'), |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
scanAndCreate(structure); |
||||
}, |
||||
}; |
||||
|
||||
// 结构
|
||||
// -xxx_worker
|
||||
// -|--main_thread
|
||||
// -|--|--action
|
||||
// -|--|--xxx_main_thread.ts
|
||||
// -|--utils
|
||||
// -|--|--action_type.ts
|
||||
// -|--worker_thread
|
||||
// -|--|--action
|
||||
// -|--|--worker_main_thread.ts
|
@ -0,0 +1,5 @@
|
||||
class CrudMainTreadWorker extends BI.Workers.MainThreadWorker { |
||||
protected initActions(): void { |
||||
// to init some actions
|
||||
} |
||||
} |
@ -0,0 +1,5 @@
|
||||
class CrudWorkerTreadWorker extends BI.Workers.MainThreadWorker { |
||||
protected initActions(): void { |
||||
// to init some actions
|
||||
} |
||||
} |
Loading…
Reference in new issue