-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcmd-helper.js
42 lines (35 loc) · 992 Bytes
/
cmd-helper.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
42
const path = require('path')
class Cmd {
constructor (name, program) {
this.name = name
this.program = program || require('commander')
this.start = Date.now()
this.debug = {log: v => {}} // do nothing yet
this.vuetalConf
}
base () {
return this.program
.option('-q, --quiet', 'Quiet, do not write anyting on startard ouput')
}
run () {
const program = this.program
if (program.quiet) {
} else {
if (!process.env.DEBUG)
process.env.DEBUG = 'vuetal:*,-vuetal:debug:*'
}
this.debug = require('./debug')('cmd:' + this.name)
return this.debug
}
vuetalConf (root, confPath) {
if (!root) root = process.cwd()
if (!confPath) return require('./utils/config-loader').loadVuetalConfig(root)
return require(path.join(root, confPath))
}
timeEnd () {
this.debug.log('Done in %fs', (Date.now() - this.start)/1000)
}
}
module.exports = function (name, program) {
return new Cmd(name, program)
}