@nocobase/cli 0.18.0-alpha.1 → 0.18.0-alpha.9
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 +5 -4
- package/src/commands/dev.js +8 -2
- package/src/commands/e2e.js +9 -0
- package/src/commands/p-test.js +72 -0
- package/src/util.js +8 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "0.18.0-alpha.
|
|
3
|
+
"version": "0.18.0-alpha.9",
|
|
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.18.0-alpha.
|
|
11
|
+
"@nocobase/app": "0.18.0-alpha.9",
|
|
12
12
|
"@types/fs-extra": "^11.0.1",
|
|
13
13
|
"@umijs/utils": "3.5.20",
|
|
14
14
|
"chalk": "^4.1.1",
|
|
@@ -17,18 +17,19 @@
|
|
|
17
17
|
"execa": "^5.1.1",
|
|
18
18
|
"fast-glob": "^3.3.1",
|
|
19
19
|
"fs-extra": "^11.1.1",
|
|
20
|
+
"p-all": "3.0.0",
|
|
20
21
|
"pm2": "^5.2.0",
|
|
21
22
|
"portfinder": "^1.0.28",
|
|
22
23
|
"serve": "^13.0.2",
|
|
23
24
|
"tsx": "^4.6.2"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@nocobase/devtools": "0.18.0-alpha.
|
|
27
|
+
"@nocobase/devtools": "0.18.0-alpha.9"
|
|
27
28
|
},
|
|
28
29
|
"repository": {
|
|
29
30
|
"type": "git",
|
|
30
31
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
31
32
|
"directory": "packages/core/cli"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "34ca0df4eede2e83fc86297b0fe19eba970e2b1b"
|
|
34
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
|
@@ -2,6 +2,7 @@ const { Command } = require('commander');
|
|
|
2
2
|
const { run, isPortReachable } = require('../util');
|
|
3
3
|
const { execSync } = require('node:child_process');
|
|
4
4
|
const axios = require('axios');
|
|
5
|
+
const { pTest } = require('./p-test');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 检查服务是否启动成功
|
|
@@ -200,4 +201,12 @@ module.exports = (cli) => {
|
|
|
200
201
|
e2e.command('install-deps').action(async () => {
|
|
201
202
|
await run('npx', ['playwright', 'install', '--with-deps']);
|
|
202
203
|
});
|
|
204
|
+
|
|
205
|
+
e2e
|
|
206
|
+
.command('p-test')
|
|
207
|
+
.option('--stop-on-error')
|
|
208
|
+
.option('--concurrency [concurrency]', '', 3)
|
|
209
|
+
.action(async (opts) => {
|
|
210
|
+
await pTest(opts);
|
|
211
|
+
});
|
|
203
212
|
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const execa = require('execa');
|
|
2
|
+
const { resolve } = require('path');
|
|
3
|
+
const pAll = require('p-all');
|
|
4
|
+
const dotenv = require('dotenv');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const { Client } = require('pg');
|
|
7
|
+
const glob = require('glob');
|
|
8
|
+
const _ = require('lodash');
|
|
9
|
+
|
|
10
|
+
let ENV_FILE = resolve(process.cwd(), '.env.e2e');
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(ENV_FILE)) {
|
|
13
|
+
ENV_FILE = resolve(process.cwd(), '.env.e2e.example');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const data = fs.readFileSync(ENV_FILE, 'utf-8');
|
|
17
|
+
const config = {
|
|
18
|
+
...dotenv.parse(data),
|
|
19
|
+
...process.env,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
async function runApp(dir, index = 0) {
|
|
23
|
+
// 一个进程需要占用两个端口? (一个是应用端口,一个是 socket 端口)
|
|
24
|
+
index = index * 2;
|
|
25
|
+
|
|
26
|
+
const database = `nocobase${index}`;
|
|
27
|
+
const client = new Client({
|
|
28
|
+
host: config['DB_HOST'],
|
|
29
|
+
port: Number(config['DB_PORT']),
|
|
30
|
+
user: config['DB_USER'],
|
|
31
|
+
password: config['DB_PASSWORD'],
|
|
32
|
+
database: 'postgres',
|
|
33
|
+
});
|
|
34
|
+
await client.connect();
|
|
35
|
+
await client.query(`DROP DATABASE IF EXISTS "${database}"`);
|
|
36
|
+
await client.query(`CREATE DATABASE "${database}";`);
|
|
37
|
+
await client.end();
|
|
38
|
+
return execa('yarn', ['nocobase', 'e2e', 'test', dir, '-x', '--skip-reporter'], {
|
|
39
|
+
shell: true,
|
|
40
|
+
stdio: 'inherit',
|
|
41
|
+
env: {
|
|
42
|
+
...config,
|
|
43
|
+
CI: true,
|
|
44
|
+
__E2E__: true,
|
|
45
|
+
APP_BASE_URL: undefined,
|
|
46
|
+
LOGGER_LEVEL: 'error',
|
|
47
|
+
APP_ENV: 'production',
|
|
48
|
+
APP_PORT: 20000 + index,
|
|
49
|
+
DB_DATABASE: `nocobase${index}`,
|
|
50
|
+
SOCKET_PATH: `storage/gateway-e2e-${index}.sock`,
|
|
51
|
+
PM2_HOME: resolve(process.cwd(), `storage/.pm2-${index}`),
|
|
52
|
+
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), `storage/playwright/.auth/admin-${index}.json`),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.pTest = async (options) => {
|
|
58
|
+
const files = glob.sync('packages/**/__e2e__/**/*.test.ts', {
|
|
59
|
+
root: process.cwd(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const commands = splitArrayIntoParts(files, options.concurrency || 3).map((v, i) => {
|
|
63
|
+
return () => runApp(v.join(' '), i);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
await pAll(commands, { concurrency: 3, stopOnError: false, ...options });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function splitArrayIntoParts(array, parts) {
|
|
70
|
+
let chunkSize = Math.ceil(array.length / parts);
|
|
71
|
+
return _.chunk(array, chunkSize);
|
|
72
|
+
}
|
package/src/util.js
CHANGED
|
@@ -57,6 +57,10 @@ exports.nodeCheck = () => {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
exports.run = (command, args, options = {}) => {
|
|
60
|
+
if (command === 'tsx') {
|
|
61
|
+
command = 'node';
|
|
62
|
+
args = ['./node_modules/tsx/dist/cli.mjs'].concat(args || []);
|
|
63
|
+
}
|
|
60
64
|
return execa(command, args, {
|
|
61
65
|
shell: true,
|
|
62
66
|
stdio: 'inherit',
|
|
@@ -213,6 +217,9 @@ exports.genTsConfigPaths = function genTsConfigPaths() {
|
|
|
213
217
|
paths[`${packageJsonName}/server`] = [`${relativePath}/src/server`];
|
|
214
218
|
paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];
|
|
215
219
|
}
|
|
220
|
+
if (packageJsonName === '@nocobase/plugin-workflow-test') {
|
|
221
|
+
paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];
|
|
222
|
+
}
|
|
216
223
|
});
|
|
217
224
|
|
|
218
225
|
const tsConfigJsonPath = join(cwd, './tsconfig.paths.json');
|
|
@@ -268,7 +275,7 @@ exports.initEnv = function initEnv() {
|
|
|
268
275
|
}
|
|
269
276
|
}
|
|
270
277
|
|
|
271
|
-
if (process.argv[2] === 'e2e') {
|
|
278
|
+
if (!process.env.APP_ENV_PATH && process.argv[2] === 'e2e') {
|
|
272
279
|
// 用于存放 playwright 自动生成的相关的文件
|
|
273
280
|
generatePlaywrightPath();
|
|
274
281
|
if (!fs.existsSync('.env.e2e') && fs.existsSync('.env.e2e.example')) {
|