@yuw-cli-dev/core 1.0.36 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +7 -7
- package/lib/const.js +7 -7
- package/lib/index.js +93 -26
- package/package.json +7 -3
package/bin/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const importLocal = require("import-local");
|
|
4
|
-
if (importLocal(__filename)) {
|
|
5
|
-
require("npmlog").info("cli", "正在使用 yuw-cli-dev 本地版本");
|
|
6
|
-
} else {
|
|
7
|
-
require("../lib/index.js")(process.argv.slice(2));
|
|
8
|
-
}
|
|
2
|
+
|
|
3
|
+
const importLocal = require("import-local");
|
|
4
|
+
if (importLocal(__filename)) {
|
|
5
|
+
require("npmlog").info("cli", "正在使用 yuw-cli-dev 本地版本");
|
|
6
|
+
} else {
|
|
7
|
+
require("../lib/index.js")(process.argv.slice(2));
|
|
8
|
+
}
|
package/lib/const.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const LOWEST_NODE_VERSION =
|
|
2
|
-
const DEFAULT_CLI_HOME =
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
LOWEST_NODE_VERSION,
|
|
6
|
-
DEFAULT_CLI_HOME,
|
|
7
|
-
};
|
|
1
|
+
const LOWEST_NODE_VERSION = '16.0.0';
|
|
2
|
+
const DEFAULT_CLI_HOME = '.yuw-cli';
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
LOWEST_NODE_VERSION,
|
|
6
|
+
DEFAULT_CLI_HOME,
|
|
7
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = core;
|
|
4
4
|
|
|
5
|
-
const path = require(
|
|
6
|
-
const colors = require(
|
|
7
|
-
const semver = require(
|
|
8
|
-
const userHome = require(
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const colors = require('colors/safe');
|
|
7
|
+
const semver = require('semver');
|
|
8
|
+
const userHome = require('user-home');
|
|
9
|
+
const Commander = require('commander');
|
|
10
|
+
const pathExists = require('path-exists').sync;
|
|
11
|
+
const pkg = require('../package.json');
|
|
12
|
+
const log = require('@yuw-cli-dev/log');
|
|
13
|
+
const exec = require('@yuw-cli-dev/exec');
|
|
14
|
+
const constants = require('./const');
|
|
15
|
+
const program = new Commander.Command();
|
|
13
16
|
|
|
14
|
-
function core() {
|
|
17
|
+
async function core() {
|
|
15
18
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
checkRoot();
|
|
19
|
-
checkUserHome();
|
|
20
|
-
checkInputArgs();
|
|
21
|
-
checkEnv();
|
|
19
|
+
perpare();
|
|
20
|
+
registerCommand();
|
|
22
21
|
} catch (error) {
|
|
23
22
|
log.error(error.message);
|
|
24
23
|
}
|
|
25
24
|
}
|
|
25
|
+
|
|
26
|
+
async function perpare() {
|
|
27
|
+
checkPkgVersion();
|
|
28
|
+
checkNodeVersion();
|
|
29
|
+
checkRoot();
|
|
30
|
+
checkUserHome();
|
|
31
|
+
// checkInputArgs();
|
|
32
|
+
checkEnv();
|
|
33
|
+
await checkGlobalUpdate();
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
function checkPkgVersion() {
|
|
27
|
-
log.info(
|
|
37
|
+
log.info('cli', pkg.version);
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
function checkNodeVersion() {
|
|
@@ -40,42 +50,41 @@ function checkNodeVersion() {
|
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
function checkRoot() {
|
|
43
|
-
const rootCheck = require(
|
|
53
|
+
const rootCheck = require('root-check');
|
|
44
54
|
rootCheck();
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
function checkUserHome() {
|
|
48
|
-
console.log(userHome);
|
|
49
58
|
if (!userHome || !pathExists(userHome)) {
|
|
50
|
-
throw new Error(colors.red(
|
|
59
|
+
throw new Error(colors.red('当前登录用户主目录不存在!'));
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
function checkInputArgs() {
|
|
55
|
-
const minimist = require(
|
|
64
|
+
const minimist = require('minimist');
|
|
56
65
|
const args = minimist(process.argv.slice(2));
|
|
57
66
|
checkArgs(args);
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
function checkArgs(args) {
|
|
61
70
|
if (args.debug) {
|
|
62
|
-
process.env.LOG_LEVEL =
|
|
71
|
+
process.env.LOG_LEVEL = 'verbose';
|
|
63
72
|
} else {
|
|
64
|
-
process.env.LOG_LEVEL =
|
|
73
|
+
process.env.LOG_LEVEL = 'info';
|
|
65
74
|
}
|
|
66
75
|
log.level = process.env.LOG_LEVEL;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
function checkEnv() {
|
|
70
|
-
const dotenv = require(
|
|
71
|
-
const dotenvPath = path.resolve(userHome,
|
|
79
|
+
const dotenv = require('dotenv');
|
|
80
|
+
const dotenvPath = path.resolve(userHome, '.env');
|
|
72
81
|
if (pathExists(dotenvPath)) {
|
|
73
82
|
dotenv.config({
|
|
74
83
|
path: dotenvPath,
|
|
75
84
|
});
|
|
76
85
|
}
|
|
77
86
|
createDefaultConfig();
|
|
78
|
-
log.verbose(
|
|
87
|
+
log.verbose('环境变量', process.env.CLI_HOME_PATH);
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
function createDefaultConfig() {
|
|
@@ -89,3 +98,61 @@ function createDefaultConfig() {
|
|
|
89
98
|
}
|
|
90
99
|
process.env.CLI_HOME_PATH = cliConfig.cliHome;
|
|
91
100
|
}
|
|
101
|
+
|
|
102
|
+
async function checkGlobalUpdate() {
|
|
103
|
+
const currentVersion = pkg.version;
|
|
104
|
+
const npmName = pkg.name;
|
|
105
|
+
const { getNpmSemverVersion } = require('@yuw-cli-dev/get-npm-info');
|
|
106
|
+
const latestVersion = await getNpmSemverVersion(npmName, currentVersion);
|
|
107
|
+
if (latestVersion && semver.gt(latestVersion, currentVersion)) {
|
|
108
|
+
log.warn(
|
|
109
|
+
'更新提示',
|
|
110
|
+
colors.yellow(
|
|
111
|
+
`请手动更新 ${npmName},当前版本:${currentVersion},最新版本:${latestVersion},更新命令:npm install -g ${npmName}`,
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function registerCommand() {
|
|
118
|
+
program.name(Object.keys(pkg.bin)[0]);
|
|
119
|
+
program
|
|
120
|
+
.version(pkg.version)
|
|
121
|
+
.usage('<command> [options]')
|
|
122
|
+
.option('-d, --debug', '是否开启调试模式', false)
|
|
123
|
+
.option('-t, --targetPath <targetPath>', '是否指定本地调试文件路径', '');
|
|
124
|
+
|
|
125
|
+
program
|
|
126
|
+
.command('init [projectName]')
|
|
127
|
+
.option('-f, --force', '是否强制初始化项目')
|
|
128
|
+
.action(exec);
|
|
129
|
+
|
|
130
|
+
program.on('option:debug', function () {
|
|
131
|
+
const options = program.opts();
|
|
132
|
+
if (options.debug) {
|
|
133
|
+
process.env.LOG_LEVEL = 'verbose';
|
|
134
|
+
} else {
|
|
135
|
+
process.env.LOG_LEVEL = 'info';
|
|
136
|
+
}
|
|
137
|
+
log.level = process.env.LOG_LEVEL;
|
|
138
|
+
log.verbose('debug', '已开启调试模式');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
program.on('option:targetPath', function (targetPath) {
|
|
142
|
+
process.env.CLI_TARGET_PATH = targetPath;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
program.on('command:*', function (obj) {
|
|
146
|
+
const availableCommands = program.commands.map(cmd => cmd.name());
|
|
147
|
+
console.log(colors.red('未知的命令:' + obj[0]));
|
|
148
|
+
if (availableCommands.length > 0) {
|
|
149
|
+
console.log(colors.red('可用命令:' + availableCommands.join(',')));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
program.parse(process.argv);
|
|
154
|
+
if (program.args && program.args.length < 1) {
|
|
155
|
+
program.outputHelp();
|
|
156
|
+
console.log();
|
|
157
|
+
}
|
|
158
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuw-cli-dev/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.38",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "yuwei <yuwei@huya.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -20,9 +20,13 @@
|
|
|
20
20
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@yuw-cli-dev/exec": "^1.0.38",
|
|
24
|
+
"@yuw-cli-dev/get-npm-info": "^1.0.38",
|
|
25
|
+
"@yuw-cli-dev/init": "^1.0.38",
|
|
23
26
|
"@yuw-cli-dev/log": "^1.0.36",
|
|
24
|
-
"@yuw-cli-dev/utils": "^1.0.
|
|
27
|
+
"@yuw-cli-dev/utils": "^1.0.38",
|
|
25
28
|
"colors": "^1.4.0",
|
|
29
|
+
"commander": "^14.0.2",
|
|
26
30
|
"dotenv": "^17.2.3",
|
|
27
31
|
"import-local": "^3.2.0",
|
|
28
32
|
"minimist": "^1.2.8",
|
|
@@ -31,7 +35,7 @@
|
|
|
31
35
|
"root-check": "^1.0.0",
|
|
32
36
|
"user-home": "^3.0.0"
|
|
33
37
|
},
|
|
34
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f92c3015d6799312f5c9b446775cfb5ed577eeed",
|
|
35
39
|
"publishConfig": {
|
|
36
40
|
"access": "public"
|
|
37
41
|
}
|