@nocobase/cli 0.19.0-alpha.1 → 0.19.0-alpha.10

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.19.0-alpha.1",
3
+ "version": "0.19.0-alpha.10",
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.19.0-alpha.1",
11
+ "@nocobase/app": "0.19.0-alpha.10",
12
12
  "@types/fs-extra": "^11.0.1",
13
13
  "@umijs/utils": "3.5.20",
14
14
  "chalk": "^4.1.1",
@@ -21,15 +21,16 @@
21
21
  "pm2": "^5.2.0",
22
22
  "portfinder": "^1.0.28",
23
23
  "serve": "^13.0.2",
24
+ "tree-kill": "^1.2.2",
24
25
  "tsx": "^4.6.2"
25
26
  },
26
27
  "devDependencies": {
27
- "@nocobase/devtools": "0.19.0-alpha.1"
28
+ "@nocobase/devtools": "0.19.0-alpha.10"
28
29
  },
29
30
  "repository": {
30
31
  "type": "git",
31
32
  "url": "git+https://github.com/nocobase/nocobase.git",
32
33
  "directory": "packages/core/cli"
33
34
  },
34
- "gitHead": "64601944412fc4d2e2bd05f4b982118dd28247dc"
35
+ "gitHead": "d09d81eba67339da36bcec27939a85b35d180770"
35
36
  }
@@ -106,7 +106,9 @@ module.exports = (cli) => {
106
106
  env: {
107
107
  PORT: clientPort,
108
108
  APP_ROOT: `${APP_PACKAGE_ROOT}/client`,
109
- WEBSOCKET_URL: process.env.WEBSOCKET_URL || (serverPort ? `ws://localhost:${serverPort}/ws` : undefined),
109
+ WEBSOCKET_URL:
110
+ process.env.WEBSOCKET_URL ||
111
+ (serverPort ? `ws://localhost:${serverPort}${process.env.WS_PATH}` : undefined),
110
112
  PROXY_TARGET_URL:
111
113
  process.env.PROXY_TARGET_URL || (serverPort ? `http://127.0.0.1:${serverPort}` : undefined),
112
114
  },
@@ -4,6 +4,8 @@ const { execSync } = require('node:child_process');
4
4
  const axios = require('axios');
5
5
  const { pTest } = require('./p-test');
6
6
  const os = require('os');
7
+ const treeKill = require('tree-kill');
8
+ const chalk = require('chalk');
7
9
 
8
10
  /**
9
11
  * 检查服务是否启动成功
@@ -33,7 +35,7 @@ const checkServer = async (duration = 1000, max = 60 * 10) => {
33
35
  }
34
36
  })
35
37
  .catch((error) => {
36
- console.error('Request error:', error.message);
38
+ console.error('Request error:', error?.response?.data?.error);
37
39
  });
38
40
  }, duration);
39
41
  });
@@ -91,6 +93,17 @@ async function runApp(options = {}) {
91
93
  run('nocobase', [process.env.APP_ENV === 'production' ? 'start' : 'dev'], options);
92
94
  }
93
95
 
96
+ process.on('SIGINT', async () => {
97
+ treeKill(process.pid, (error) => {
98
+ if (error) {
99
+ console.error(error);
100
+ } else {
101
+ console.log(chalk.yellow('Force killing...'));
102
+ }
103
+ process.exit();
104
+ });
105
+ });
106
+
94
107
  const commonConfig = {
95
108
  stdio: 'inherit',
96
109
  };
@@ -128,6 +141,12 @@ const filterArgv = () => {
128
141
  if (element === '--skip-reporter') {
129
142
  continue;
130
143
  }
144
+ if (element === '--build') {
145
+ continue;
146
+ }
147
+ if (element === '--production') {
148
+ continue;
149
+ }
131
150
  argv.push(element);
132
151
  }
133
152
  return argv;
@@ -144,14 +163,19 @@ module.exports = (cli) => {
144
163
  console.log('APP_BASE_URL:', process.env.APP_BASE_URL);
145
164
  }
146
165
  });
166
+
147
167
  e2e
148
168
  .command('test')
149
169
  .allowUnknownOption()
150
170
  .option('--url [url]')
151
171
  .option('--skip-reporter')
152
172
  .option('--build')
173
+ .option('--production')
153
174
  .action(async (options) => {
154
175
  process.env.__E2E__ = true;
176
+ if (options.production) {
177
+ process.env.APP_ENV = 'production';
178
+ }
155
179
  if (options.build) {
156
180
  process.env.APP_ENV = 'production';
157
181
  await run('yarn', ['build']);
@@ -225,6 +249,6 @@ module.exports = (cli) => {
225
249
  process.env.APP_ENV = 'production';
226
250
  await run('yarn', ['build']);
227
251
  }
228
- await pTest(options);
252
+ await pTest({ ...options, concurrency: 1 * options.concurrency });
229
253
  });
230
254
  };
@@ -3,7 +3,6 @@ const { resolve } = require('path');
3
3
  const pAll = require('p-all');
4
4
  const dotenv = require('dotenv');
5
5
  const fs = require('fs');
6
- const { Client } = require('pg');
7
6
  const glob = require('glob');
8
7
  const _ = require('lodash');
9
8
 
@@ -22,7 +21,7 @@ const config = {
22
21
  async function runApp(dir, index = 0) {
23
22
  // 一个进程需要占用两个端口? (一个是应用端口,一个是 socket 端口)
24
23
  index = index * 2;
25
-
24
+ const { Client } = require('pg');
26
25
  const database = `nocobase${index}`;
27
26
  const client = new Client({
28
27
  host: config['DB_HOST'],
@@ -3,7 +3,7 @@ const { run, isDev, isPackageValid, generatePlaywrightPath } = require('../util'
3
3
  const { resolve } = require('path');
4
4
  const { existsSync } = require('fs');
5
5
  const { readFile, writeFile } = require('fs').promises;
6
- const { createStoragePluginsSymlink } = require('@nocobase/utils/plugin-symlink');
6
+ const { createStoragePluginsSymlink, createDevPluginsSymlink } = require('@nocobase/utils/plugin-symlink');
7
7
 
8
8
  /**
9
9
  * @param {Command} cli
@@ -13,12 +13,14 @@ module.exports = (cli) => {
13
13
  cli
14
14
  .command('postinstall')
15
15
  .allowUnknownOption()
16
- .action(async () => {
16
+ .option('--skip-umi')
17
+ .action(async (options) => {
17
18
  generatePlaywrightPath(true);
18
19
  await createStoragePluginsSymlink();
19
20
  if (!isDev()) {
20
21
  return;
21
22
  }
23
+ await createDevPluginsSymlink();
22
24
  const cwd = process.cwd();
23
25
  if (!existsSync(resolve(cwd, '.env')) && existsSync(resolve(cwd, '.env.example'))) {
24
26
  const content = await readFile(resolve(cwd, '.env.example'), 'utf-8');
@@ -31,11 +33,13 @@ module.exports = (cli) => {
31
33
  if (!isPackageValid('umi')) {
32
34
  return;
33
35
  }
34
- run('umi', ['generate', 'tmp'], {
35
- stdio: 'pipe',
36
- env: {
37
- APP_ROOT: `${APP_PACKAGE_ROOT}/client`,
38
- },
39
- });
36
+ if (!options.skipUmi) {
37
+ run('umi', ['generate', 'tmp'], {
38
+ stdio: 'pipe',
39
+ env: {
40
+ APP_ROOT: `${APP_PACKAGE_ROOT}/client`,
41
+ },
42
+ });
43
+ }
40
44
  });
41
45
  };
@@ -29,9 +29,10 @@ async function getProjectVersion() {
29
29
 
30
30
  class PluginGenerator extends Generator {
31
31
  constructor(options) {
32
- const { context = {}, ...opts } = options;
32
+ const { log, context = {}, ...opts } = options;
33
33
  super(opts);
34
34
  this.context = context;
35
+ this.log = log || console.log;
35
36
  }
36
37
 
37
38
  async getContext() {
@@ -51,20 +52,19 @@ class PluginGenerator extends Generator {
51
52
  const { name } = this.context;
52
53
  const target = resolve(process.cwd(), 'packages/plugins/', name);
53
54
  if (existsSync(target)) {
54
- console.log(chalk.red(`[${name}] plugin already exists.`));
55
+ this.log(chalk.red(`[${name}] plugin already exists.`));
55
56
  return;
56
57
  }
57
- console.log('Creating plugin');
58
+ this.log('Creating plugin');
58
59
  this.copyDirectory({
59
60
  target,
60
61
  context: await this.getContext(),
61
62
  path: join(__dirname, '../templates/plugin'),
62
63
  });
63
- console.log('');
64
+ this.log('');
64
65
  genTsConfigPaths();
65
- execa.sync('yarn', ['install'], { shell: true, stdio: 'inherit' });
66
- // execa.sync('yarn', ['build', `plugins/${name}`], { shell: true, stdio: 'inherit' });
67
- console.log(`The plugin folder is in ${chalk.green(`packages/plugins/${name}`)}`);
66
+ execa.sync('yarn', ['postinstall', '--skip-umi'], { shell: true, stdio: 'inherit' });
67
+ this.log(`The plugin folder is in ${chalk.green(`packages/plugins/${name}`)}`);
68
68
  }
69
69
  }
70
70
 
package/src/util.js CHANGED
@@ -271,11 +271,16 @@ exports.initEnv = function initEnv() {
271
271
  LOCAL_STORAGE_DEST: 'storage/uploads',
272
272
  PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
273
273
  MFSU_AD: 'none',
274
+ WS_PATH: '/ws',
275
+ SOCKET_PATH: 'storage/gateway.sock',
274
276
  NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
275
277
  PM2_HOME: resolve(process.cwd(), './storage/.pm2'),
276
278
  PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
277
279
  SERVER_TSCONFIG_PATH: './tsconfig.server.json',
278
280
  PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
281
+ CACHE_DEFAULT_STORE: 'memory',
282
+ CACHE_MEMORY_MAX: 2000,
283
+ LOGGER_BASE_PATH: 'storage/logs',
279
284
  };
280
285
 
281
286
  if (
@@ -1,13 +1,13 @@
1
- import { InstallOptions, Plugin } from '@nocobase/server';
1
+ import { Plugin } from '@nocobase/server';
2
2
 
3
3
  export class {{{pascalCaseName}}}Server extends Plugin {
4
- afterAdd() {}
4
+ async afterAdd() {}
5
5
 
6
- beforeLoad() {}
6
+ async beforeLoad() {}
7
7
 
8
8
  async load() {}
9
9
 
10
- async install(options?: InstallOptions) {}
10
+ async install() {}
11
11
 
12
12
  async afterEnable() {}
13
13