@shun-js/shun-cli 1.0.0 → 1.0.1
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/log.js +10 -4
- package/bin/npm.js +18 -1
- package/bin/shun.js +5 -0
- package/package.json +2 -2
package/bin/log.js
CHANGED
|
@@ -2,16 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
const pc = require('picocolors');
|
|
4
4
|
|
|
5
|
+
const PREFIX = pc.bold('[shunjs]');
|
|
6
|
+
|
|
5
7
|
function info(msg) {
|
|
6
|
-
console.log(pc.gray(msg));
|
|
8
|
+
console.log(`${PREFIX} ${pc.gray(msg)}`);
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
function success(msg) {
|
|
10
|
-
console.log(pc.green(msg));
|
|
12
|
+
console.log(`${PREFIX} ${pc.green(msg)}`);
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
function error(msg) {
|
|
14
|
-
console.log(pc.red(msg));
|
|
16
|
+
console.log(`${PREFIX} ${pc.red(msg)}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function br() {
|
|
20
|
+
console.log();
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
module.exports = { info, success, error };
|
|
23
|
+
module.exports = { info, success, error, br };
|
package/bin/npm.js
CHANGED
|
@@ -25,4 +25,21 @@ function getGlobalPath() {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
function ensurePm2() {
|
|
29
|
+
try {
|
|
30
|
+
execSync('pm2 --version', { encoding: 'utf-8', stdio: 'pipe' });
|
|
31
|
+
log.info('pm2 is installed');
|
|
32
|
+
} catch {
|
|
33
|
+
log.info('pm2 not found, installing...');
|
|
34
|
+
try {
|
|
35
|
+
execSync('npm i -g pm2', { encoding: 'utf-8' });
|
|
36
|
+
log.success('pm2 installed');
|
|
37
|
+
} catch (e) {
|
|
38
|
+
log.error('failed to install pm2');
|
|
39
|
+
console.log(e.message);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = { installGlobal, getGlobalPath, ensurePm2 };
|
package/bin/shun.js
CHANGED
|
@@ -20,12 +20,15 @@ program
|
|
|
20
20
|
.description('install and start servers, e.g. @shun-js/xxx@1.0.0')
|
|
21
21
|
.action(async (servers) => {
|
|
22
22
|
try {
|
|
23
|
+
npm.ensurePm2();
|
|
24
|
+
log.br();
|
|
23
25
|
await pm2.connect();
|
|
24
26
|
|
|
25
27
|
for (const server of servers) {
|
|
26
28
|
await startServer(server);
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
log.br();
|
|
29
32
|
pm2.save();
|
|
30
33
|
} catch (e) {
|
|
31
34
|
log.error('failed to start servers');
|
|
@@ -47,9 +50,11 @@ async function startServer(input) {
|
|
|
47
50
|
const pkgWithVersion = `${pkg}@${version}`;
|
|
48
51
|
|
|
49
52
|
log.info(`starting server: ${pkgWithVersion}`);
|
|
53
|
+
log.br();
|
|
50
54
|
|
|
51
55
|
// 1. npm install -g
|
|
52
56
|
npm.installGlobal(pkgWithVersion);
|
|
57
|
+
log.br();
|
|
53
58
|
|
|
54
59
|
// 2. 定位 app.js
|
|
55
60
|
const globalPath = npm.getGlobalPath();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/shun-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "shun.js cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shun.js",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"access": "public",
|
|
32
32
|
"registry": "https://registry.npmjs.org/"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "219146d401816f457560facfb72ca3b3b2f60e63"
|
|
35
35
|
}
|