-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (37 loc) · 1.14 KB
/
index.js
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
const commander = require('./core')
const fs = require('fs')
const path = require('path')
const debug = require('debug')('lime:index')
const config = require('./lib/conf-store')
// 注册官方子命令
commander.registerGlobalCommand(require('./cmds/global'))
const innerCmdPath = path.resolve(__dirname, './cmds')
try {
const files = fs.readdirSync(innerCmdPath)
files.forEach(file => {
if (file === 'global') return
// const state = fs.statSync(path.resolve(innerCmdPath, file))
let cmdPlugin = require(path.resolve(innerCmdPath, file))
if (!Object.keys(cmdPlugin).length) return
commander.registerCommand(cmdPlugin)
})
}
catch(err) {
debug('info: ', err.message)
throw err
}
// 注册用户自定义子命令
const selfCmdDir = config.get('self_cmd_dir') || 'cmds'
const userCmdPath = path.resolve(process.cwd(), selfCmdDir)
try {
const files = fs.readdirSync(userCmdPath)
files.forEach(file => {
// const state = fs.statSync(path.resolve(userCmdPath, file))
commander.registerCommand(require(path.resolve(userCmdPath, file)))
})
}
catch(err) {
debug('info: ', err.message)
}
// 启动 commander
commander.start()