@nocobase/cli 0.18.0-alpha.8 → 0.19.0-alpha.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 +8 -2
- package/src/commands/e2e.js +21 -3
- package/src/commands/p-test.js +23 -13
- package/src/commands/test.js +10 -10
- package/src/util.js +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.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": "0.
|
|
11
|
+
"@nocobase/app": "0.19.0-alpha.1",
|
|
12
12
|
"@types/fs-extra": "^11.0.1",
|
|
13
13
|
"@umijs/utils": "3.5.20",
|
|
14
14
|
"chalk": "^4.1.1",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"tsx": "^4.6.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@nocobase/devtools": "0.
|
|
27
|
+
"@nocobase/devtools": "0.19.0-alpha.1"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
31
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
32
32
|
"directory": "packages/core/cli"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "64601944412fc4d2e2bd05f4b982118dd28247dc"
|
|
35
35
|
}
|
package/src/commands/dev.js
CHANGED
|
@@ -15,6 +15,7 @@ module.exports = (cli) => {
|
|
|
15
15
|
.option('--client')
|
|
16
16
|
.option('--server')
|
|
17
17
|
.option('--db-sync')
|
|
18
|
+
.option('--inspect [port]')
|
|
18
19
|
.allowUnknownOption()
|
|
19
20
|
.action(async (opts) => {
|
|
20
21
|
promptForTs();
|
|
@@ -33,7 +34,7 @@ module.exports = (cli) => {
|
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
const { port, client, server } = opts;
|
|
37
|
+
const { port, client, server, inspect } = opts;
|
|
37
38
|
|
|
38
39
|
if (port) {
|
|
39
40
|
process.env.APP_PORT = opts.port;
|
|
@@ -59,8 +60,13 @@ module.exports = (cli) => {
|
|
|
59
60
|
if (server || !client) {
|
|
60
61
|
console.log('starting server', serverPort);
|
|
61
62
|
|
|
63
|
+
const filteredArgs = process.argv.filter(
|
|
64
|
+
(item, i) => !item.startsWith('--inspect') && !(process.argv[i - 1] === '--inspect' && Number.parseInt(item)),
|
|
65
|
+
);
|
|
66
|
+
|
|
62
67
|
const argv = [
|
|
63
68
|
'watch',
|
|
69
|
+
...(inspect ? [`--inspect=${inspect === true ? 9229 : inspect}`] : []),
|
|
64
70
|
'--ignore=./storage/plugins/**',
|
|
65
71
|
'--tsconfig',
|
|
66
72
|
SERVER_TSCONFIG_PATH,
|
|
@@ -68,7 +74,7 @@ module.exports = (cli) => {
|
|
|
68
74
|
'tsconfig-paths/register',
|
|
69
75
|
`${APP_PACKAGE_ROOT}/src/index.ts`,
|
|
70
76
|
'start',
|
|
71
|
-
...
|
|
77
|
+
...filteredArgs.slice(3),
|
|
72
78
|
`--port=${serverPort}`,
|
|
73
79
|
];
|
|
74
80
|
|
package/src/commands/e2e.js
CHANGED
|
@@ -3,6 +3,7 @@ const { run, isPortReachable } = require('../util');
|
|
|
3
3
|
const { execSync } = require('node:child_process');
|
|
4
4
|
const axios = require('axios');
|
|
5
5
|
const { pTest } = require('./p-test');
|
|
6
|
+
const os = require('os');
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* 检查服务是否启动成功
|
|
@@ -148,7 +149,13 @@ module.exports = (cli) => {
|
|
|
148
149
|
.allowUnknownOption()
|
|
149
150
|
.option('--url [url]')
|
|
150
151
|
.option('--skip-reporter')
|
|
152
|
+
.option('--build')
|
|
151
153
|
.action(async (options) => {
|
|
154
|
+
process.env.__E2E__ = true;
|
|
155
|
+
if (options.build) {
|
|
156
|
+
process.env.APP_ENV = 'production';
|
|
157
|
+
await run('yarn', ['build']);
|
|
158
|
+
}
|
|
152
159
|
if (options.skipReporter) {
|
|
153
160
|
process.env.PLAYWRIGHT_SKIP_REPORTER = true;
|
|
154
161
|
}
|
|
@@ -183,8 +190,13 @@ module.exports = (cli) => {
|
|
|
183
190
|
e2e
|
|
184
191
|
.command('start-app')
|
|
185
192
|
.option('--production')
|
|
193
|
+
.option('--build')
|
|
186
194
|
.option('--port [port]')
|
|
187
195
|
.action(async (options) => {
|
|
196
|
+
process.env.__E2E__ = true;
|
|
197
|
+
if (options.build) {
|
|
198
|
+
await run('yarn', ['build']);
|
|
199
|
+
}
|
|
188
200
|
if (options.production) {
|
|
189
201
|
process.env.APP_ENV = 'production';
|
|
190
202
|
}
|
|
@@ -205,8 +217,14 @@ module.exports = (cli) => {
|
|
|
205
217
|
e2e
|
|
206
218
|
.command('p-test')
|
|
207
219
|
.option('--stop-on-error')
|
|
208
|
-
.option('--
|
|
209
|
-
.
|
|
210
|
-
|
|
220
|
+
.option('--build')
|
|
221
|
+
.option('--concurrency [concurrency]', '', os.cpus().length)
|
|
222
|
+
.action(async (options) => {
|
|
223
|
+
process.env.__E2E__ = true;
|
|
224
|
+
if (options.build) {
|
|
225
|
+
process.env.APP_ENV = 'production';
|
|
226
|
+
await run('yarn', ['build']);
|
|
227
|
+
}
|
|
228
|
+
await pTest(options);
|
|
211
229
|
});
|
|
212
230
|
};
|
package/src/commands/p-test.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const execa = require('execa');
|
|
2
|
-
const { resolve
|
|
2
|
+
const { resolve } = require('path');
|
|
3
3
|
const pAll = require('p-all');
|
|
4
4
|
const dotenv = require('dotenv');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const { Client } = require('pg');
|
|
7
7
|
const glob = require('glob');
|
|
8
|
+
const _ = require('lodash');
|
|
8
9
|
|
|
9
10
|
let ENV_FILE = resolve(process.cwd(), '.env.e2e');
|
|
10
11
|
|
|
@@ -18,7 +19,10 @@ const config = {
|
|
|
18
19
|
...process.env,
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
async function runApp(index =
|
|
22
|
+
async function runApp(dir, index = 0) {
|
|
23
|
+
// 一个进程需要占用两个端口? (一个是应用端口,一个是 socket 端口)
|
|
24
|
+
index = index * 2;
|
|
25
|
+
|
|
22
26
|
const database = `nocobase${index}`;
|
|
23
27
|
const client = new Client({
|
|
24
28
|
host: config['DB_HOST'],
|
|
@@ -31,7 +35,7 @@ async function runApp(index = 1, dir) {
|
|
|
31
35
|
await client.query(`DROP DATABASE IF EXISTS "${database}"`);
|
|
32
36
|
await client.query(`CREATE DATABASE "${database}";`);
|
|
33
37
|
await client.end();
|
|
34
|
-
return execa('yarn', ['nocobase', 'e2e', 'test', dir, '
|
|
38
|
+
return execa('yarn', ['nocobase', 'e2e', 'test', dir, '--skip-reporter'], {
|
|
35
39
|
shell: true,
|
|
36
40
|
stdio: 'inherit',
|
|
37
41
|
env: {
|
|
@@ -43,26 +47,32 @@ async function runApp(index = 1, dir) {
|
|
|
43
47
|
APP_ENV: 'production',
|
|
44
48
|
APP_PORT: 20000 + index,
|
|
45
49
|
DB_DATABASE: `nocobase${index}`,
|
|
46
|
-
SOCKET_PATH: `storage/gateway-e2e-${index}.sock`,
|
|
47
|
-
PM2_HOME: resolve(process.cwd(), `storage/.pm2-${index}`),
|
|
50
|
+
SOCKET_PATH: `storage/e2e/gateway-e2e-${index}.sock`,
|
|
51
|
+
PM2_HOME: resolve(process.cwd(), `storage/e2e/.pm2-${index}`),
|
|
48
52
|
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), `storage/playwright/.auth/admin-${index}.json`),
|
|
49
53
|
},
|
|
50
54
|
});
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
exports.pTest = async (options) => {
|
|
58
|
+
const dir = resolve(process.cwd(), 'storage/e2e');
|
|
59
|
+
|
|
60
|
+
if (!fs.existsSync(dir)) {
|
|
61
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
54
64
|
const files = glob.sync('packages/**/__e2e__/**/*.test.ts', {
|
|
55
65
|
root: process.cwd(),
|
|
56
66
|
});
|
|
57
|
-
const fileSet = new Set();
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const commands = [...fileSet.values()].map((v, i) => {
|
|
64
|
-
return () => runApp(i + 1, v);
|
|
68
|
+
const commands = splitArrayIntoParts(_.shuffle(files), options.concurrency || 4).map((v, i) => {
|
|
69
|
+
return () => runApp(v.join(' '), i);
|
|
65
70
|
});
|
|
66
71
|
|
|
67
|
-
await pAll(commands, { concurrency:
|
|
72
|
+
await pAll(commands, { concurrency: 4, stopOnError: false, ...options });
|
|
68
73
|
};
|
|
74
|
+
|
|
75
|
+
function splitArrayIntoParts(array, parts) {
|
|
76
|
+
let chunkSize = Math.ceil(array.length / parts);
|
|
77
|
+
return _.chunk(array, chunkSize);
|
|
78
|
+
}
|
package/src/commands/test.js
CHANGED
|
@@ -36,26 +36,26 @@ function addTestCommand(name, cli) {
|
|
|
36
36
|
if (!opts.watch && !opts.run) {
|
|
37
37
|
process.argv.push('--run');
|
|
38
38
|
}
|
|
39
|
+
const first = paths?.[0];
|
|
40
|
+
if (!process.env.TEST_ENV && first) {
|
|
41
|
+
const key = first.split(path.sep).join('/');
|
|
42
|
+
if (key.includes('/client/')) {
|
|
43
|
+
process.env.TEST_ENV = 'client-side';
|
|
44
|
+
} else {
|
|
45
|
+
process.env.TEST_ENV = 'server-side';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
39
48
|
if (process.env.TEST_ENV === 'server-side' && opts.singleThread !== 'false') {
|
|
40
49
|
process.argv.push('--poolOptions.threads.singleThread=true');
|
|
41
50
|
}
|
|
42
51
|
if (opts.singleThread === 'false') {
|
|
43
52
|
process.argv.splice(process.argv.indexOf('--single-thread=false'), 1);
|
|
44
53
|
}
|
|
45
|
-
const cliArgs = ['--max_old_space_size=
|
|
54
|
+
const cliArgs = ['--max_old_space_size=14096', './node_modules/.bin/vitest', ...process.argv.slice(3)];
|
|
46
55
|
if (process.argv.includes('-h') || process.argv.includes('--help')) {
|
|
47
56
|
await run('node', cliArgs);
|
|
48
57
|
return;
|
|
49
58
|
}
|
|
50
|
-
const first = paths?.[0];
|
|
51
|
-
if (!process.env.TEST_ENV && first) {
|
|
52
|
-
const key = first.split(path.sep).join('/');
|
|
53
|
-
if (key.includes('/client/')) {
|
|
54
|
-
process.env.TEST_ENV = 'client-side';
|
|
55
|
-
} else {
|
|
56
|
-
process.env.TEST_ENV = 'server-side';
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
59
|
if (process.env.TEST_ENV) {
|
|
60
60
|
console.log('process.env.TEST_ENV', process.env.TEST_ENV, cliArgs);
|
|
61
61
|
await run('node', cliArgs);
|
package/src/util.js
CHANGED
|
@@ -245,6 +245,18 @@ function generatePlaywrightPath(clean = false) {
|
|
|
245
245
|
|
|
246
246
|
exports.generatePlaywrightPath = generatePlaywrightPath;
|
|
247
247
|
|
|
248
|
+
function parseEnv(name) {
|
|
249
|
+
if (name === 'DB_UNDERSCORED') {
|
|
250
|
+
if (process.env.DB_UNDERSCORED === 'true') {
|
|
251
|
+
return 'true';
|
|
252
|
+
}
|
|
253
|
+
if (process.env.DB_UNDERSCORED) {
|
|
254
|
+
return 'true';
|
|
255
|
+
}
|
|
256
|
+
return 'false';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
248
260
|
exports.initEnv = function initEnv() {
|
|
249
261
|
const env = {
|
|
250
262
|
APP_ENV: 'development',
|
|
@@ -254,6 +266,7 @@ exports.initEnv = function initEnv() {
|
|
|
254
266
|
DB_DIALECT: 'sqlite',
|
|
255
267
|
DB_STORAGE: 'storage/db/nocobase.sqlite',
|
|
256
268
|
DB_TIMEZONE: '+00:00',
|
|
269
|
+
DB_UNDERSCORED: parseEnv('DB_UNDERSCORED'),
|
|
257
270
|
DEFAULT_STORAGE_TYPE: 'local',
|
|
258
271
|
LOCAL_STORAGE_DEST: 'storage/uploads',
|
|
259
272
|
PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
|