@yuw-cli-dev/exec 1.0.37 → 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/lib/index.js +45 -3
- package/package.json +4 -3
package/lib/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const path = require("path");
|
|
4
|
+
const slash = require("slash");
|
|
5
|
+
const cp = require("child_process");
|
|
4
6
|
const Package = require("@yuw-cli-dev/package");
|
|
5
7
|
const log = require("@yuw-cli-dev/log");
|
|
8
|
+
const { normalizePath } = require("@yuw-cli-dev/utils");
|
|
6
9
|
|
|
7
10
|
const SETTINGS = {
|
|
8
11
|
init: "@yuw-cli-dev/init",
|
|
9
12
|
};
|
|
10
13
|
const CACHE_DIR = "dependencies";
|
|
14
|
+
|
|
11
15
|
async function exec() {
|
|
12
16
|
let targetPath = process.env.CLI_TARGET_PATH;
|
|
13
17
|
let storeDir = "";
|
|
@@ -36,9 +40,10 @@ async function exec() {
|
|
|
36
40
|
packageVersion,
|
|
37
41
|
});
|
|
38
42
|
|
|
39
|
-
if (pkg.exists()) {
|
|
43
|
+
if (await pkg.exists()) {
|
|
40
44
|
// 更新package
|
|
41
|
-
|
|
45
|
+
console.log("update package");
|
|
46
|
+
await pkg.update();
|
|
42
47
|
} else {
|
|
43
48
|
// 安装package
|
|
44
49
|
await pkg.install();
|
|
@@ -52,7 +57,44 @@ async function exec() {
|
|
|
52
57
|
}
|
|
53
58
|
const rootFile = pkg.getRootFilePath();
|
|
54
59
|
if (rootFile) {
|
|
55
|
-
|
|
60
|
+
try {
|
|
61
|
+
const args = Array.from(arguments);
|
|
62
|
+
const o = Object.create(null);
|
|
63
|
+
const cmdObj = args[args.length - 1];
|
|
64
|
+
Object.keys(cmdObj).forEach((key) => {
|
|
65
|
+
if (
|
|
66
|
+
cmdObj.hasOwnProperty(key) &&
|
|
67
|
+
!key.startsWith("_") &&
|
|
68
|
+
key !== "parent"
|
|
69
|
+
) {
|
|
70
|
+
o[key] = cmdObj[key];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
args[args.length - 1] = o;
|
|
74
|
+
const code = `require('${normalizePath(rootFile)}').call(null, ${JSON.stringify(args)})`;
|
|
75
|
+
const child = spawn("node", ["-e", code], {
|
|
76
|
+
cwd: process.cwd(),
|
|
77
|
+
stdio: "inherit",
|
|
78
|
+
});
|
|
79
|
+
child.on("error", (e) => {
|
|
80
|
+
log.error(e.message);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
|
83
|
+
child.on("exit", (e) => {
|
|
84
|
+
log.verbose("命令执行成功:" + e);
|
|
85
|
+
process.exit(e);
|
|
86
|
+
});
|
|
87
|
+
} catch (error) {
|
|
88
|
+
log.error(error.message);
|
|
89
|
+
}
|
|
56
90
|
}
|
|
57
91
|
}
|
|
92
|
+
|
|
93
|
+
function spawn(command, args, options) {
|
|
94
|
+
const win32 = process.platform === "win32";
|
|
95
|
+
const cmd = win32 ? "cmd" : command;
|
|
96
|
+
const cmdArgs = win32 ? ["/c"].concat(command, args) : args;
|
|
97
|
+
return cp.spawn(cmd, cmdArgs, options || {});
|
|
98
|
+
}
|
|
99
|
+
|
|
58
100
|
module.exports = exec;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuw-cli-dev/exec",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.38",
|
|
4
4
|
"description": "yuw-cli-dev execute package",
|
|
5
5
|
"author": "yuwei <yuwei@huya.com>",
|
|
6
6
|
"homepage": "https://github.com/yousanjin/yuw-cli#readme",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@yuw-cli-dev/log": "^1.0.36",
|
|
31
|
-
"@yuw-cli-dev/package": "file:../../models/package"
|
|
31
|
+
"@yuw-cli-dev/package": "file:../../models/package",
|
|
32
|
+
"@yuw-cli-dev/utils": "^1.0.38"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "f92c3015d6799312f5c9b446775cfb5ed577eeed"
|
|
34
35
|
}
|