-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
76 lines (69 loc) · 3.17 KB
/
cli.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
const yParser = require('yargs-parser');
const npmview = require('npmview');
const semver = require('semver');
const { existsSync } = require('fs');
const { join } = require('path');
const chalk = require('chalk');
const run = require('./lib/run');
// get local package name and version from package.json (or wherever)
const pkgName = require('./package.json').name;
const pkgVersion = require('./package.json').version;
// print version and @local
const args = yParser(process.argv.slice(2));
if (args.v || args.version) {
console.log(require('./package').version);
if (existsSync(join(__dirname, '.local'))) {
console.log(chalk.cyan('@local'));
}
process.exit(0);
}
if (!semver.satisfies(process.version, '>= 10.0.0')) {
console.error(chalk.red('✘ The generator will only work with Node v10.0.0 and up!'));
process.exit(1);
}
const name = args._[0] || '';
const { type, subtype, ssubtype } = args;
delete args.type;
delete args.subtype;
delete args.ssubtype;
// get latest version on npm
npmview(pkgName, (err, version, moduleInfo) => {
// compare to local version
if (semver.gt(version, pkgVersion)) {
console.log(
chalk.green(`
**************************************************************
* 本地cli需要更新 *
* .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. *
* | ______ | *
* | .-" "-. | *
* | / \ | *
* | _ | | _ | *
* | ( \ |, .-. .-. ,| / ) | *
* | > "=._ | )(__/ \__)( | _.=" < | *
* | (_/"=._"=._ |/ /\ \| _.="_.="\_) | *
* | "=._"(_ ^^ _)"_.=" | *
* | "=\__|IIIIII|__/=" | *
* | _.="| \IIIIII/ |"=._ | *
* | _ _.="_.="\ /"=._"=._ _ | *
* | ( \_.="_.=" '--------' "=._"=._/ ) | *
* | > _.=" "=._ < | *
* | (_/ \_) | *
* | | *
* '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' *
* *
* 本地当前版本:${pkgVersion}, 最新版本:${version} *
* 执行 yarn global add create-wetrial 升级到最新版本 *
**************************************************************
`),
);
}
run({
name,
type,
subtype,
ssubtype,
args,
});
});