-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.js
More file actions
52 lines (40 loc) · 1.18 KB
/
command.js
File metadata and controls
52 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require('module-alias/register')
const { Command,program } = require('commander');
const glob = require('glob');
const { file } = require('./utils/global.functions');
function createCommand() {
program
.description('Kozmonos developer cli tool')
.version('1.0.0');
return program
}
module.exports.returnProgram = () => program
const scanSubFolder = (path, program) => {
file
.glob(`${path}/*`)
.map((folderPath)=>{
if(file.stat(folderPath).isFile())
return
const targetName=folderPath.replace(`${path}/`,'').split('/')[0]
if(file.exists(`${folderPath}/index.js`))
program.addCommand(require(`${folderPath}/index.js`))
else{
const subProgram = new Command(targetName);
scanSubFolder(folderPath,subProgram)
program.addCommand(subProgram)
}
})
}
module.exports.getCommands=() => {
let program=createCommand()
file
.glob("@app/*")
.map(commandFolder=>{
const projectName=commandFolder.replace(`${__dirname}/src/`,'').split('/')[0]
const projectApp=require(`${commandFolder}/index.js`)
scanSubFolder(commandFolder,projectApp)
program.addCommand(projectApp)
})
return program
}
module.exports.commander=() =>this.getCommands().parse()