@shun-js/shun-cli 0.1.0 → 0.3.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/shun-start.js +18 -6
- package/package.json +2 -2
package/bin/shun-start.js
CHANGED
|
@@ -13,13 +13,17 @@ const { pm2Start } = require('./pm2.js');
|
|
|
13
13
|
const debug = require('debug')('@shun-js/shun-cli');
|
|
14
14
|
|
|
15
15
|
// cmd
|
|
16
|
-
cli.cmd
|
|
16
|
+
cli.cmd
|
|
17
|
+
.command('start <servers...>')
|
|
18
|
+
.description('待启动的服务名')
|
|
19
|
+
.option('-m, --max', '使用集群模式,CPU核心数最大化')
|
|
20
|
+
.action(startServers);
|
|
17
21
|
|
|
18
22
|
// start servers
|
|
19
|
-
async function startServers(servers) {
|
|
23
|
+
async function startServers(servers, options) {
|
|
20
24
|
try {
|
|
21
25
|
for (let i = 0; i < servers.length; i++) {
|
|
22
|
-
await startServer(servers[i]);
|
|
26
|
+
await startServer(servers[i], options);
|
|
23
27
|
}
|
|
24
28
|
} catch (error) {
|
|
25
29
|
console.log(cli.colors.red('启动服务出错。'));
|
|
@@ -29,7 +33,7 @@ async function startServers(servers) {
|
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
// start servers
|
|
32
|
-
async function startServer(serverName) {
|
|
36
|
+
async function startServer(serverName, options) {
|
|
33
37
|
const methodName = 'startServer';
|
|
34
38
|
console.log(cli.colors.gray(`开始启动服务:${serverName}`));
|
|
35
39
|
|
|
@@ -64,12 +68,20 @@ async function startServer(serverName) {
|
|
|
64
68
|
|
|
65
69
|
// pm2
|
|
66
70
|
try {
|
|
67
|
-
|
|
71
|
+
const pm2Config = {
|
|
68
72
|
name: serverConfigPrefix,
|
|
69
73
|
cwd: serverRootPath,
|
|
70
74
|
script: serverAppPath,
|
|
71
75
|
args: serverConfigPath,
|
|
72
|
-
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// 集群模式
|
|
79
|
+
if (options && options.max) {
|
|
80
|
+
pm2Config.instances = 'max';
|
|
81
|
+
pm2Config.exec_mode = 'cluster';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await pm2Start(pm2Config);
|
|
73
85
|
} catch (error) {
|
|
74
86
|
console.log(cli.colors.red(`服务启动失败:${serverName}`));
|
|
75
87
|
console.log();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/shun-cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "shun.js cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shun.js",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"access": "public",
|
|
33
33
|
"registry": "https://registry.npmjs.org/"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0ebfcf6ace36b6a4f9311791106b5506ceeb9a27"
|
|
36
36
|
}
|