@nocobase/cli 0.18.0-alpha.9 → 0.19.0-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "0.18.0-alpha.9",
3
+ "version": "0.19.0-alpha.2",
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.9",
11
+ "@nocobase/app": "0.19.0-alpha.2",
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.18.0-alpha.9"
27
+ "@nocobase/devtools": "0.19.0-alpha.2"
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": "34ca0df4eede2e83fc86297b0fe19eba970e2b1b"
34
+ "gitHead": "cff5b77ecf12ccdb450d50d505b3aa44a68478c8"
35
35
  }
@@ -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('--concurrency [concurrency]', '', 3)
209
- .action(async (opts) => {
210
- await pTest(opts);
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
  };
@@ -35,7 +35,7 @@ async function runApp(dir, index = 0) {
35
35
  await client.query(`DROP DATABASE IF EXISTS "${database}"`);
36
36
  await client.query(`CREATE DATABASE "${database}";`);
37
37
  await client.end();
38
- return execa('yarn', ['nocobase', 'e2e', 'test', dir, '-x', '--skip-reporter'], {
38
+ return execa('yarn', ['nocobase', 'e2e', 'test', dir, '--skip-reporter'], {
39
39
  shell: true,
40
40
  stdio: 'inherit',
41
41
  env: {
@@ -47,23 +47,29 @@ async function runApp(dir, index = 0) {
47
47
  APP_ENV: 'production',
48
48
  APP_PORT: 20000 + index,
49
49
  DB_DATABASE: `nocobase${index}`,
50
- SOCKET_PATH: `storage/gateway-e2e-${index}.sock`,
51
- 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}`),
52
52
  PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), `storage/playwright/.auth/admin-${index}.json`),
53
53
  },
54
54
  });
55
55
  }
56
56
 
57
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
+
58
64
  const files = glob.sync('packages/**/__e2e__/**/*.test.ts', {
59
65
  root: process.cwd(),
60
66
  });
61
67
 
62
- const commands = splitArrayIntoParts(files, options.concurrency || 3).map((v, i) => {
68
+ const commands = splitArrayIntoParts(_.shuffle(files), options.concurrency || 4).map((v, i) => {
63
69
  return () => runApp(v.join(' '), i);
64
70
  });
65
71
 
66
- await pAll(commands, { concurrency: 3, stopOnError: false, ...options });
72
+ await pAll(commands, { concurrency: 4, stopOnError: false, ...options });
67
73
  };
68
74
 
69
75
  function splitArrayIntoParts(array, parts) {
@@ -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=4096', './node_modules/.bin/vitest', ...process.argv.slice(3)];
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'),