@nocobase/cli 1.5.0-alpha.4 → 1.5.0-beta.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/package.json +4 -4
- package/src/commands/dev.js +61 -19
- package/src/commands/start.js +31 -6
- package/src/util.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "1.5.0-
|
|
3
|
+
"version": "1.5.0-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"nocobase": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/app": "1.5.0-
|
|
11
|
+
"@nocobase/app": "1.5.0-beta.1",
|
|
12
12
|
"@types/fs-extra": "^11.0.1",
|
|
13
13
|
"@umijs/utils": "3.5.20",
|
|
14
14
|
"chalk": "^4.1.1",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"tsx": "^4.19.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@nocobase/devtools": "1.5.0-
|
|
28
|
+
"@nocobase/devtools": "1.5.0-beta.1"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
32
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
33
33
|
"directory": "packages/core/cli"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "10c6f1f3d90e91f3aabfa80449c7ef062e90f6af"
|
|
36
36
|
}
|
package/src/commands/dev.js
CHANGED
|
@@ -6,16 +6,21 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
const chalk = require('chalk');
|
|
9
|
+
const _ = require('lodash');
|
|
11
10
|
const { Command } = require('commander');
|
|
12
|
-
const { generatePlugins, run, postCheck, nodeCheck, promptForTs } = require('../util');
|
|
11
|
+
const { generatePlugins, run, postCheck, nodeCheck, promptForTs, isPortReachable } = require('../util');
|
|
13
12
|
const { getPortPromise } = require('portfinder');
|
|
14
13
|
const chokidar = require('chokidar');
|
|
15
14
|
const { uid } = require('@formily/shared');
|
|
16
15
|
const path = require('path');
|
|
17
16
|
const fs = require('fs');
|
|
18
17
|
|
|
18
|
+
function sleep(ms = 1000) {
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
setTimeout(resolve, ms);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
/**
|
|
20
25
|
*
|
|
21
26
|
* @param {Command} cli
|
|
@@ -31,6 +36,24 @@ module.exports = (cli) => {
|
|
|
31
36
|
.option('--inspect [port]')
|
|
32
37
|
.allowUnknownOption()
|
|
33
38
|
.action(async (opts) => {
|
|
39
|
+
let subprocess;
|
|
40
|
+
const runDevClient = () => {
|
|
41
|
+
console.log('starting client', 1 * clientPort);
|
|
42
|
+
subprocess = run('umi', ['dev'], {
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
stdio: 'inherit',
|
|
46
|
+
shell: true,
|
|
47
|
+
PORT: clientPort,
|
|
48
|
+
APP_ROOT: `${APP_PACKAGE_ROOT}/client`,
|
|
49
|
+
WEBSOCKET_URL:
|
|
50
|
+
process.env.WEBSOCKET_URL ||
|
|
51
|
+
(serverPort ? `ws://localhost:${serverPort}${process.env.WS_PATH}` : undefined),
|
|
52
|
+
PROXY_TARGET_URL:
|
|
53
|
+
process.env.PROXY_TARGET_URL || (serverPort ? `http://127.0.0.1:${serverPort}` : undefined),
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
};
|
|
34
57
|
const watcher = chokidar.watch('./storage/plugins/**/*', {
|
|
35
58
|
cwd: process.cwd(),
|
|
36
59
|
ignored: /(^|[\/\\])\../, // 忽略隐藏文件
|
|
@@ -39,15 +62,45 @@ module.exports = (cli) => {
|
|
|
39
62
|
});
|
|
40
63
|
|
|
41
64
|
await fs.promises.mkdir(path.dirname(process.env.WATCH_FILE), { recursive: true });
|
|
65
|
+
let isReady = false;
|
|
66
|
+
|
|
67
|
+
const restartClient = _.debounce(async () => {
|
|
68
|
+
if (!isReady) return;
|
|
69
|
+
generatePlugins();
|
|
70
|
+
if (subprocess) {
|
|
71
|
+
console.log('client restarting...');
|
|
72
|
+
subprocess.cancel();
|
|
73
|
+
let i = 0;
|
|
74
|
+
while (true) {
|
|
75
|
+
++i;
|
|
76
|
+
const result = await isPortReachable(clientPort);
|
|
77
|
+
if (!result) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
await sleep(500);
|
|
81
|
+
if (i > 10) {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
runDevClient();
|
|
86
|
+
await fs.promises.writeFile(process.env.WATCH_FILE, `export const watchId = '${uid()}';`, 'utf-8');
|
|
87
|
+
}
|
|
88
|
+
}, 500);
|
|
42
89
|
|
|
43
90
|
watcher
|
|
91
|
+
.on('ready', () => {
|
|
92
|
+
console.log('Initial scan complete.');
|
|
93
|
+
isReady = true;
|
|
94
|
+
})
|
|
44
95
|
.on('addDir', async (pathname) => {
|
|
45
|
-
|
|
46
|
-
|
|
96
|
+
console.log('addDir....', isReady);
|
|
97
|
+
if (!isReady) return;
|
|
98
|
+
restartClient();
|
|
47
99
|
})
|
|
48
100
|
.on('unlinkDir', async (pathname) => {
|
|
49
|
-
|
|
50
|
-
|
|
101
|
+
console.log('unlinkDir....', isReady);
|
|
102
|
+
if (!isReady) return;
|
|
103
|
+
restartClient();
|
|
51
104
|
});
|
|
52
105
|
|
|
53
106
|
promptForTs();
|
|
@@ -133,18 +186,7 @@ module.exports = (cli) => {
|
|
|
133
186
|
}
|
|
134
187
|
|
|
135
188
|
if (client || !server) {
|
|
136
|
-
|
|
137
|
-
run('umi', ['dev'], {
|
|
138
|
-
env: {
|
|
139
|
-
PORT: clientPort,
|
|
140
|
-
APP_ROOT: `${APP_PACKAGE_ROOT}/client`,
|
|
141
|
-
WEBSOCKET_URL:
|
|
142
|
-
process.env.WEBSOCKET_URL ||
|
|
143
|
-
(serverPort ? `ws://localhost:${serverPort}${process.env.WS_PATH}` : undefined),
|
|
144
|
-
PROXY_TARGET_URL:
|
|
145
|
-
process.env.PROXY_TARGET_URL || (serverPort ? `http://127.0.0.1:${serverPort}` : undefined),
|
|
146
|
-
},
|
|
147
|
-
});
|
|
189
|
+
runDevClient();
|
|
148
190
|
}
|
|
149
191
|
});
|
|
150
192
|
};
|
package/src/commands/start.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const _ = require('lodash');
|
|
10
10
|
const { Command } = require('commander');
|
|
11
11
|
const { isDev, run, postCheck, downloadPro, promptForTs } = require('../util');
|
|
12
12
|
const { existsSync, rmSync } = require('fs');
|
|
@@ -51,10 +51,26 @@ module.exports = (cli) => {
|
|
|
51
51
|
depth: 1, // 只监听第一层目录
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
console.log('
|
|
54
|
+
const restart = _.debounce(async () => {
|
|
55
|
+
console.log('restarting...');
|
|
56
56
|
await run('yarn', ['nocobase', 'pm2-restart']);
|
|
57
|
-
});
|
|
57
|
+
}, 500);
|
|
58
|
+
|
|
59
|
+
watcher
|
|
60
|
+
.on('ready', () => {
|
|
61
|
+
console.log('Initial scan complete.');
|
|
62
|
+
isReady = true;
|
|
63
|
+
})
|
|
64
|
+
.on('addDir', async (pathname) => {
|
|
65
|
+
console.log('addDir....', isReady);
|
|
66
|
+
if (!isReady) return;
|
|
67
|
+
restart();
|
|
68
|
+
})
|
|
69
|
+
.on('unlinkDir', async (pathname) => {
|
|
70
|
+
console.log('unlinkDir....', isReady);
|
|
71
|
+
if (!isReady) return;
|
|
72
|
+
restart();
|
|
73
|
+
});
|
|
58
74
|
|
|
59
75
|
if (opts.port) {
|
|
60
76
|
process.env.APP_PORT = opts.port;
|
|
@@ -79,11 +95,20 @@ module.exports = (cli) => {
|
|
|
79
95
|
return;
|
|
80
96
|
}
|
|
81
97
|
await postCheck(opts);
|
|
82
|
-
|
|
98
|
+
if (!opts.daemon) {
|
|
99
|
+
deleteSockFiles();
|
|
100
|
+
}
|
|
83
101
|
const instances = opts.instances || process.env.CLUSTER_MODE;
|
|
84
102
|
const instancesArgs = instances ? ['-i', instances] : [];
|
|
85
103
|
if (opts.daemon) {
|
|
86
|
-
run('pm2', [
|
|
104
|
+
await run('pm2', [
|
|
105
|
+
'start',
|
|
106
|
+
...instancesArgs,
|
|
107
|
+
`${APP_PACKAGE_ROOT}/lib/index.js`,
|
|
108
|
+
'--',
|
|
109
|
+
...process.argv.slice(2),
|
|
110
|
+
]);
|
|
111
|
+
process.exit();
|
|
87
112
|
} else {
|
|
88
113
|
run(
|
|
89
114
|
'pm2-runtime',
|
package/src/util.js
CHANGED
|
@@ -346,6 +346,7 @@ exports.initEnv = function initEnv() {
|
|
|
346
346
|
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
|
|
347
347
|
CACHE_DEFAULT_STORE: 'memory',
|
|
348
348
|
CACHE_MEMORY_MAX: 2000,
|
|
349
|
+
BROWSERSLIST_IGNORE_OLD_DATA: true,
|
|
349
350
|
PLUGIN_STATICS_PATH: '/static/plugins/',
|
|
350
351
|
LOGGER_BASE_PATH: 'storage/logs',
|
|
351
352
|
APP_SERVER_BASE_URL: '',
|