@yuw-cli-dev/exec 1.0.38 → 1.0.39
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 +24 -32
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const path = require(
|
|
4
|
-
const slash = require(
|
|
5
|
-
const cp = require(
|
|
6
|
-
const Package = require(
|
|
7
|
-
const log = require(
|
|
8
|
-
const { normalizePath } = require(
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const slash = require('slash');
|
|
5
|
+
const cp = require('child_process');
|
|
6
|
+
const Package = require('@yuw-cli-dev/package');
|
|
7
|
+
const log = require('@yuw-cli-dev/log');
|
|
8
|
+
const { normalizePath, exec: spawn } = require('@yuw-cli-dev/utils');
|
|
9
9
|
|
|
10
10
|
const SETTINGS = {
|
|
11
|
-
init:
|
|
11
|
+
init: '@yuw-cli-dev/init',
|
|
12
12
|
};
|
|
13
|
-
const CACHE_DIR =
|
|
13
|
+
const CACHE_DIR = 'dependencies';
|
|
14
14
|
|
|
15
15
|
async function exec() {
|
|
16
16
|
let targetPath = process.env.CLI_TARGET_PATH;
|
|
17
|
-
let storeDir =
|
|
17
|
+
let storeDir = '';
|
|
18
18
|
let pkg;
|
|
19
19
|
const homePath = process.env.CLI_HOME_PATH;
|
|
20
20
|
|
|
21
|
-
log.verbose(
|
|
22
|
-
log.verbose(
|
|
21
|
+
log.verbose('targetPath', targetPath);
|
|
22
|
+
log.verbose('homePath', homePath);
|
|
23
23
|
|
|
24
24
|
const cmdObj = arguments[arguments.length - 1];
|
|
25
25
|
const cmdName = cmdObj.name();
|
|
26
26
|
const packageName = SETTINGS[cmdName];
|
|
27
|
-
const packageVersion =
|
|
27
|
+
const packageVersion = 'latest';
|
|
28
28
|
|
|
29
29
|
if (!targetPath) {
|
|
30
30
|
targetPath = path.resolve(homePath, CACHE_DIR);
|
|
31
|
-
storeDir = path.resolve(targetPath,
|
|
31
|
+
storeDir = path.resolve(targetPath, 'node_modules');
|
|
32
32
|
|
|
33
|
-
log.verbose(
|
|
34
|
-
log.verbose(
|
|
33
|
+
log.verbose('storeDir', storeDir);
|
|
34
|
+
log.verbose('targetPath', targetPath);
|
|
35
35
|
|
|
36
36
|
pkg = new Package({
|
|
37
37
|
targetPath,
|
|
@@ -42,7 +42,6 @@ async function exec() {
|
|
|
42
42
|
|
|
43
43
|
if (await pkg.exists()) {
|
|
44
44
|
// 更新package
|
|
45
|
-
console.log("update package");
|
|
46
45
|
await pkg.update();
|
|
47
46
|
} else {
|
|
48
47
|
// 安装package
|
|
@@ -61,27 +60,27 @@ async function exec() {
|
|
|
61
60
|
const args = Array.from(arguments);
|
|
62
61
|
const o = Object.create(null);
|
|
63
62
|
const cmdObj = args[args.length - 1];
|
|
64
|
-
Object.keys(cmdObj).forEach(
|
|
63
|
+
Object.keys(cmdObj).forEach(key => {
|
|
65
64
|
if (
|
|
66
65
|
cmdObj.hasOwnProperty(key) &&
|
|
67
|
-
!key.startsWith(
|
|
68
|
-
key !==
|
|
66
|
+
!key.startsWith('_') &&
|
|
67
|
+
key !== 'parent'
|
|
69
68
|
) {
|
|
70
69
|
o[key] = cmdObj[key];
|
|
71
70
|
}
|
|
72
71
|
});
|
|
73
72
|
args[args.length - 1] = o;
|
|
74
73
|
const code = `require('${normalizePath(rootFile)}').call(null, ${JSON.stringify(args)})`;
|
|
75
|
-
const child = spawn(
|
|
74
|
+
const child = spawn('node', ['-e', code], {
|
|
76
75
|
cwd: process.cwd(),
|
|
77
|
-
stdio:
|
|
76
|
+
stdio: 'inherit',
|
|
78
77
|
});
|
|
79
|
-
child.on(
|
|
78
|
+
child.on('error', e => {
|
|
80
79
|
log.error(e.message);
|
|
81
80
|
process.exit(1);
|
|
82
81
|
});
|
|
83
|
-
child.on(
|
|
84
|
-
log.verbose(
|
|
82
|
+
child.on('exit', e => {
|
|
83
|
+
log.verbose('命令执行成功:' + e);
|
|
85
84
|
process.exit(e);
|
|
86
85
|
});
|
|
87
86
|
} catch (error) {
|
|
@@ -90,11 +89,4 @@ async function exec() {
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
|
|
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
|
-
|
|
100
92
|
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.39",
|
|
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",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"url": "https://github.com/yousanjin/yuw-cli/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@yuw-cli-dev/log": "^1.0.
|
|
30
|
+
"@yuw-cli-dev/log": "^1.0.39",
|
|
31
31
|
"@yuw-cli-dev/package": "file:../../models/package",
|
|
32
|
-
"@yuw-cli-dev/utils": "^1.0.
|
|
32
|
+
"@yuw-cli-dev/utils": "^1.0.39"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "7bcace542ccccc47f518b0537cbb0cce93229adf"
|
|
35
35
|
}
|