@shun-js/shun-cli 0.3.0 → 0.3.2

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.
Files changed (2) hide show
  1. package/bin/shun-start.js +18 -6
  2. package/package.json +3 -3
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.command('start <servers...>').description('待启动的服务名').action(startServers);
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
- await pm2Start({
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.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "shun.js cli",
5
5
  "keywords": [
6
6
  "shun.js",
@@ -26,11 +26,11 @@
26
26
  "debug": "^4.4.3",
27
27
  "pm2": "^6.0.14",
28
28
  "qiao-cli": "^5.0.0",
29
- "qiao-file": "^5.0.1"
29
+ "qiao-file": "^5.0.6"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public",
33
33
  "registry": "https://registry.npmjs.org/"
34
34
  },
35
- "gitHead": "b287c9ec1a61be2cbdf8c9c4bfed5a26b1d62b0d"
35
+ "gitHead": "4fa47fe5cf1b00acfe54f47af836101291093f06"
36
36
  }