-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (54 loc) · 1.7 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const path = require('path')
const Command = require('common-bin');
const chalk = require('chalk');
const figlet = require('figlet');
const Store = require('data-store');
const pkg = require('./package.json');
const { mkdirs } = require('./lib/file-generator');
console.log(
chalk.red(
figlet.textSync('WBHelper', {
horizontalLayout: 'fitted'
})
)
);
class MainCommand extends Command {
constructor(rawArgv) {
super(rawArgv);
this.yargs.usage('Usage: wbhelper <command> [options]');
// register the entire directory to commands 注册所有继承 Command 指令
this.load(path.join(__dirname, './lib/command'));
this.versionCheck();
}
versionCheck() {
let qiyuCache;
mkdirs(path.join(__dirname, './data/temp/'), () => {
qiyuCache = new Store({
path: `${__dirname}/./data/temp/cacheVersion.json`
});
});
const versionData = qiyuCache.get(pkg.name);
if (versionData) {
if (Date.now() - versionData.lastCheck > 1000 * 3600 * 24) {
this._checkUpdate();
}
} else {
this._checkUpdate()
}
}
_checkUpdate() {
try {
this.helper.spawn(
process.execPath,
[require('path').join(__dirname, './lib/checkUpdate.js'), JSON.stringify({
'name': pkg.name, // package 信息
'version': pkg.version,
'registry': 'https://registry.npmjs.org',
'updateMessage': 'Package update available: <%=colors.dim(current)%> -> <%=colors.green(latest)%> \nRun <%=colors.cyan(command)%> to update',
'level': 'minor' // 自定义强制更新的版本更新级别,默认是 major
})]);
} catch (e) {}
}
}
module.exports = MainCommand;