@nocobase/cli 1.7.0-beta.8 → 1.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "1.7.0-beta.8",
3
+ "version": "1.8.0-beta.1",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./src/index.js",
@@ -8,29 +8,30 @@
8
8
  "nocobase": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@nocobase/app": "1.7.0-beta.8",
11
+ "@nocobase/app": "1.8.0-beta.1",
12
12
  "@types/fs-extra": "^11.0.1",
13
13
  "@umijs/utils": "3.5.20",
14
14
  "chalk": "^4.1.1",
15
15
  "commander": "^9.2.0",
16
+ "deepmerge": "^4.3.1",
16
17
  "dotenv": "^16.0.0",
17
18
  "execa": "^5.1.1",
18
19
  "fast-glob": "^3.3.1",
19
20
  "fs-extra": "^11.1.1",
20
21
  "p-all": "3.0.0",
21
- "pm2": "^5.2.0",
22
+ "pm2": "^6.0.5",
22
23
  "portfinder": "^1.0.28",
23
- "serve": "^13.0.2",
24
+ "tar": "^7.4.3",
24
25
  "tree-kill": "^1.2.2",
25
26
  "tsx": "^4.19.0"
26
27
  },
27
28
  "devDependencies": {
28
- "@nocobase/devtools": "1.7.0-beta.8"
29
+ "@nocobase/devtools": "1.8.0-beta.1"
29
30
  },
30
31
  "repository": {
31
32
  "type": "git",
32
33
  "url": "git+https://github.com/nocobase/nocobase.git",
33
34
  "directory": "packages/core/cli"
34
35
  },
35
- "gitHead": "9ad35ee90db98d95dfa660645d155f4f4e81b47c"
36
+ "gitHead": "103935669123174f2942247202e3d9ff15f0d4ed"
36
37
  }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ const glob = require('fast-glob');
11
+ const { Command } = require('commander');
12
+ const { run } = require('../util');
13
+
14
+ /**
15
+ *
16
+ * @param {Command} cli
17
+ */
18
+ module.exports = (cli) => {
19
+ return (
20
+ cli
21
+ .command('benchmark')
22
+ .description('Run benchmark tests')
23
+ // .option('--single-thread [singleThread]')
24
+ .option('-a, --all [all]', 'Run all benchmark files which ends with .benchmark.{js,ts}')
25
+ .arguments('[paths...]')
26
+ .allowUnknownOption()
27
+ .action(async (paths, opts) => {
28
+ process.env.NODE_ENV = 'test';
29
+ process.env.LOGGER_LEVEL = 'error';
30
+
31
+ const cliArgs = ['--max_old_space_size=14096'];
32
+
33
+ // if (process.argv.includes('-h') || process.argv.includes('--help')) {
34
+ // await run('node', cliArgs);
35
+ // return;
36
+ // }
37
+
38
+ // if (!opts.singleThread) {
39
+ // process.argv.splice(process.argv.indexOf('--single-thread=false'), 1);
40
+ // } else {
41
+ // process.argv.push('--poolOptions.threads.singleThread=true');
42
+ // }
43
+
44
+ if (!paths.length) {
45
+ if (opts.all) {
46
+ paths.push('**/*.benchmark.ts');
47
+ } else {
48
+ console.warn(
49
+ 'No benchmark files specified. Please provide at least 1 benchmark file or path to run. Or use --all to run all "*.benchmark.ts".',
50
+ );
51
+ return;
52
+ }
53
+ }
54
+
55
+ const files = [];
56
+
57
+ for (const pattern of paths) {
58
+ for (const file of glob.sync(pattern)) {
59
+ files.push(file);
60
+ }
61
+ }
62
+
63
+ if (!files.length) {
64
+ console.log('No benchmark files found');
65
+ return;
66
+ }
67
+
68
+ for (const file of files) {
69
+ await run('tsx', [...cliArgs, file]);
70
+ }
71
+ })
72
+ );
73
+ };
@@ -8,7 +8,7 @@
8
8
  */
9
9
  const _ = require('lodash');
10
10
  const { Command } = require('commander');
11
- const { generatePlugins, run, postCheck, nodeCheck, promptForTs, isPortReachable } = require('../util');
11
+ const { generatePlugins, run, postCheck, nodeCheck, promptForTs, isPortReachable, checkDBDialect } = require('../util');
12
12
  const { getPortPromise } = require('portfinder');
13
13
  const chokidar = require('chokidar');
14
14
  const { uid } = require('@formily/shared');
@@ -36,6 +36,7 @@ module.exports = (cli) => {
36
36
  .option('-i, --inspect [port]')
37
37
  .allowUnknownOption()
38
38
  .action(async (opts) => {
39
+ checkDBDialect();
39
40
  let subprocess;
40
41
  const runDevClient = () => {
41
42
  console.log('starting client', 1 * clientPort);
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  const { Command } = require('commander');
11
- const { run, isPortReachable } = require('../util');
11
+ const { run, isPortReachable, checkDBDialect } = require('../util');
12
12
  const { execSync } = require('node:child_process');
13
13
  const axios = require('axios');
14
14
  const { pTest } = require('./p-test');
@@ -165,6 +165,7 @@ const filterArgv = () => {
165
165
  */
166
166
  module.exports = (cli) => {
167
167
  const e2e = cli.command('e2e').hook('preAction', () => {
168
+ checkDBDialect();
168
169
  if (process.env.APP_BASE_URL) {
169
170
  process.env.APP_BASE_URL = process.env.APP_BASE_URL.replace('localhost', '127.0.0.1');
170
171
  console.log('APP_BASE_URL:', process.env.APP_BASE_URL);
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  const { Command } = require('commander');
11
- const { run, isDev, isProd, promptForTs, downloadPro } = require('../util');
11
+ const { run, isDev, isProd, promptForTs, downloadPro, checkDBDialect } = require('../util');
12
12
 
13
13
  /**
14
14
  *
@@ -21,6 +21,7 @@ module.exports = (cli) => {
21
21
  .option('-h, --help')
22
22
  .option('--ts-node-dev')
23
23
  .action(async (options) => {
24
+ checkDBDialect();
24
25
  const cmd = process.argv.slice(2)?.[0];
25
26
  if (cmd === 'install') {
26
27
  await downloadPro();
@@ -29,7 +29,9 @@ module.exports = (cli) => {
29
29
  require('./pm2')(cli);
30
30
  require('./test')(cli);
31
31
  require('./test-coverage')(cli);
32
+ require('./benchmark')(cli);
32
33
  require('./umi')(cli);
34
+ require('./update-deps')(cli);
33
35
  require('./upgrade')(cli);
34
36
  require('./postinstall')(cli);
35
37
  require('./pkg')(cli);
@@ -8,7 +8,7 @@
8
8
  */
9
9
  const _ = require('lodash');
10
10
  const { Command } = require('commander');
11
- const { run, postCheck, downloadPro, promptForTs } = require('../util');
11
+ const { run, postCheck, downloadPro, promptForTs, checkDBDialect } = require('../util');
12
12
  const { existsSync, rmSync } = require('fs');
13
13
  const { resolve, isAbsolute } = require('path');
14
14
  const chalk = require('chalk');
@@ -48,8 +48,10 @@ module.exports = (cli) => {
48
48
  .option('-i, --instances [instances]')
49
49
  .option('--db-sync')
50
50
  .option('--quickstart')
51
+ .option('--launch-mode [launchMode]')
51
52
  .allowUnknownOption()
52
53
  .action(async (opts) => {
54
+ checkDBDialect();
53
55
  if (opts.quickstart) {
54
56
  await downloadPro();
55
57
  }
@@ -118,17 +120,27 @@ module.exports = (cli) => {
118
120
  ]);
119
121
  process.exit();
120
122
  } else {
121
- run(
122
- 'pm2-runtime',
123
- [
124
- 'start',
125
- ...instancesArgs,
126
- `${APP_PACKAGE_ROOT}/lib/index.js`,
127
- NODE_ARGS ? `--node-args="${NODE_ARGS}"` : undefined,
128
- '--',
129
- ...process.argv.slice(2),
130
- ].filter(Boolean),
131
- );
123
+ const launchMode = opts.launchMode || process.env.APP_LAUNCH_MODE || 'pm2';
124
+ if (launchMode === 'pm2') {
125
+ run(
126
+ 'pm2-runtime',
127
+ [
128
+ 'start',
129
+ ...instancesArgs,
130
+ `${APP_PACKAGE_ROOT}/lib/index.js`,
131
+ NODE_ARGS ? `--node-args="${NODE_ARGS}"` : undefined,
132
+ '--',
133
+ ...process.argv.slice(2),
134
+ ].filter(Boolean),
135
+ );
136
+ } else {
137
+ run(
138
+ 'node',
139
+ [`${APP_PACKAGE_ROOT}/lib/index.js`, ...(NODE_ARGS || '').split(' '), ...process.argv.slice(2)].filter(
140
+ Boolean,
141
+ ),
142
+ );
143
+ }
132
144
  }
133
145
  });
134
146
  };
@@ -7,7 +7,7 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- const { run } = require('../util');
10
+ const { run, checkDBDialect } = require('../util');
11
11
  const fg = require('fast-glob');
12
12
 
13
13
  const coreClientPackages = ['packages/core/client', 'packages/core/sdk'];
@@ -30,6 +30,7 @@ const getPackagesDir = (isClient) => {
30
30
 
31
31
  module.exports = (cli) => {
32
32
  cli.command('test-coverage:server').action(async () => {
33
+ checkDBDialect();
33
34
  const packageRoots = getPackagesDir(false);
34
35
  for (const dir of packageRoots) {
35
36
  try {
@@ -41,6 +42,7 @@ module.exports = (cli) => {
41
42
  });
42
43
 
43
44
  cli.command('test-coverage:client').action(async () => {
45
+ checkDBDialect();
44
46
  const packageRoots = getPackagesDir(true);
45
47
  for (const dir of packageRoots) {
46
48
  try {
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  const { Command } = require('commander');
11
- const { run } = require('../util');
11
+ const { run, checkDBDialect } = require('../util');
12
12
  const path = require('path');
13
13
 
14
14
  /**
@@ -29,6 +29,7 @@ function addTestCommand(name, cli) {
29
29
  .arguments('[paths...]')
30
30
  .allowUnknownOption()
31
31
  .action(async (paths, opts) => {
32
+ checkDBDialect();
32
33
  if (name === 'test:server') {
33
34
  process.env.TEST_ENV = 'server-side';
34
35
  } else if (name === 'test:client') {
@@ -0,0 +1,71 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ const chalk = require('chalk');
11
+ const { Command } = require('commander');
12
+ const { resolve } = require('path');
13
+ const { run, promptForTs, runAppCommand, hasCorePackages, downloadPro, hasTsNode, checkDBDialect } = require('../util');
14
+ const { existsSync, rmSync } = require('fs');
15
+ const { readJSON, writeJSON } = require('fs-extra');
16
+ const deepmerge = require('deepmerge');
17
+
18
+ const rmAppDir = () => {
19
+ // If ts-node is not installed, do not do the following
20
+ const appDevDir = resolve(process.cwd(), './storage/.app-dev');
21
+ if (existsSync(appDevDir)) {
22
+ rmSync(appDevDir, { recursive: true, force: true });
23
+ }
24
+ };
25
+
26
+ /**
27
+ *
28
+ * @param {Command} cli
29
+ */
30
+ module.exports = (cli) => {
31
+ cli
32
+ .command('update-deps')
33
+ .option('--force')
34
+ .allowUnknownOption()
35
+ .action(async (options) => {
36
+ if (hasCorePackages() || !hasTsNode()) {
37
+ await downloadPro();
38
+ return;
39
+ }
40
+ const pkg = require('../../package.json');
41
+ let distTag = 'latest';
42
+ if (pkg.version.includes('alpha')) {
43
+ distTag = 'alpha';
44
+ } else if (pkg.version.includes('beta')) {
45
+ distTag = 'beta';
46
+ }
47
+ const { stdout } = await run('npm', ['info', `@nocobase/cli@${distTag}`, 'version'], {
48
+ stdio: 'pipe',
49
+ });
50
+ if (!options.force && pkg.version === stdout) {
51
+ await downloadPro();
52
+ rmAppDir();
53
+ return;
54
+ }
55
+ const descPath = resolve(process.cwd(), 'package.json');
56
+ const descJson = await readJSON(descPath, 'utf8');
57
+ const sourcePath = resolve(__dirname, '../../templates/create-app-package.json');
58
+ const sourceJson = await readJSON(sourcePath, 'utf8');
59
+ if (descJson['dependencies']?.['@nocobase/cli']) {
60
+ descJson['dependencies']['@nocobase/cli'] = stdout;
61
+ }
62
+ if (descJson['devDependencies']?.['@nocobase/devtools']) {
63
+ descJson['devDependencies']['@nocobase/devtools'] = stdout;
64
+ }
65
+ const json = deepmerge(descJson, sourceJson);
66
+ await writeJSON(descPath, json, { spaces: 2, encoding: 'utf8' });
67
+ await run('yarn', ['install']);
68
+ await downloadPro();
69
+ rmAppDir();
70
+ });
71
+ };
@@ -10,15 +10,25 @@
10
10
  const chalk = require('chalk');
11
11
  const { Command } = require('commander');
12
12
  const { resolve } = require('path');
13
- const { run, promptForTs, runAppCommand, hasCorePackages, downloadPro, hasTsNode } = require('../util');
13
+ const { run, promptForTs, runAppCommand, hasCorePackages, downloadPro, hasTsNode, checkDBDialect } = require('../util');
14
14
  const { existsSync, rmSync } = require('fs');
15
+ const { readJSON, writeJSON } = require('fs-extra');
16
+ const deepmerge = require('deepmerge');
17
+
18
+ async function updatePackage() {
19
+ const sourcePath = resolve(__dirname, '../../templates/create-app-package.json');
20
+ const descPath = resolve(process.cwd(), 'package.json');
21
+ const sourceJson = await readJSON(sourcePath, 'utf8');
22
+ const descJson = await readJSON(descPath, 'utf8');
23
+ const json = deepmerge(descJson, sourceJson);
24
+ await writeJSON(descPath, json, { spaces: 2, encoding: 'utf8' });
25
+ }
15
26
 
16
27
  /**
17
28
  *
18
29
  * @param {Command} cli
19
30
  */
20
31
  module.exports = (cli) => {
21
- const { APP_PACKAGE_ROOT } = process.env;
22
32
  cli
23
33
  .command('upgrade')
24
34
  .allowUnknownOption()
@@ -26,52 +36,12 @@ module.exports = (cli) => {
26
36
  .option('--next')
27
37
  .option('-S|--skip-code-update')
28
38
  .action(async (options) => {
29
- if (hasTsNode()) promptForTs();
30
- if (hasCorePackages()) {
31
- // await run('yarn', ['install']);
32
- await downloadPro();
33
- await runAppCommand('upgrade');
34
- return;
35
- }
39
+ checkDBDialect();
36
40
  if (options.skipCodeUpdate) {
37
- await downloadPro();
38
- await runAppCommand('upgrade');
39
- return;
40
- }
41
- // await runAppCommand('upgrade');
42
- if (!hasTsNode()) {
43
- await downloadPro();
44
- await runAppCommand('upgrade');
45
- return;
46
- }
47
- const rmAppDir = () => {
48
- // If ts-node is not installed, do not do the following
49
- const appDevDir = resolve(process.cwd(), './storage/.app-dev');
50
- if (existsSync(appDevDir)) {
51
- rmSync(appDevDir, { recursive: true, force: true });
52
- }
53
- };
54
- const pkg = require('../../package.json');
55
- let distTag = 'latest';
56
- if (pkg.version.includes('alpha')) {
57
- distTag = 'alpha';
58
- } else if (pkg.version.includes('beta')) {
59
- distTag = 'beta';
60
- }
61
- // get latest version
62
- const { stdout } = await run('npm', ['info', `@nocobase/cli@${distTag}`, 'version'], {
63
- stdio: 'pipe',
64
- });
65
- if (pkg.version === stdout) {
66
- await downloadPro();
67
41
  await runAppCommand('upgrade');
68
- await rmAppDir();
69
- return;
42
+ } else {
43
+ await run('nocobase', ['update-deps']);
44
+ await run('nocobase', ['upgrade', '--skip-code-update']);
70
45
  }
71
- await run('yarn', ['add', `@nocobase/cli@${distTag}`, `@nocobase/devtools@${distTag}`, '-W']);
72
- await run('yarn', ['install']);
73
- await downloadPro();
74
- await runAppCommand('upgrade');
75
- await rmAppDir();
76
46
  });
77
47
  };
package/src/util.js CHANGED
@@ -360,7 +360,7 @@ exports.initEnv = function initEnv() {
360
360
  API_BASE_PATH: '/api/',
361
361
  API_CLIENT_STORAGE_PREFIX: 'NOCOBASE_',
362
362
  API_CLIENT_STORAGE_TYPE: 'localStorage',
363
- DB_DIALECT: 'sqlite',
363
+ // DB_DIALECT: 'sqlite',
364
364
  DB_STORAGE: 'storage/db/nocobase.sqlite',
365
365
  // DB_TIMEZONE: '+00:00',
366
366
  DB_UNDERSCORED: parseEnv('DB_UNDERSCORED'),
@@ -389,7 +389,7 @@ exports.initEnv = function initEnv() {
389
389
  if (
390
390
  !process.env.APP_ENV_PATH &&
391
391
  process.argv[2] &&
392
- ['test', 'test:client', 'test:server'].includes(process.argv[2])
392
+ ['test', 'test:client', 'test:server', 'benchmark'].includes(process.argv[2])
393
393
  ) {
394
394
  if (fs.existsSync(resolve(process.cwd(), '.env.test'))) {
395
395
  process.env.APP_ENV_PATH = '.env.test';
@@ -460,8 +460,22 @@ exports.initEnv = function initEnv() {
460
460
  process.env.SOCKET_PATH = generateGatewayPath();
461
461
  fs.mkdirpSync(dirname(process.env.SOCKET_PATH), { force: true, recursive: true });
462
462
  fs.mkdirpSync(process.env.PM2_HOME, { force: true, recursive: true });
463
- const pkgDir = resolve(process.cwd(), 'storage/plugins', '@nocobase/plugin-multi-app-manager');
464
- fs.existsSync(pkgDir) && fs.rmdirSync(pkgDir, { force: true });
463
+ const pkgs = [
464
+ '@nocobase/plugin-multi-app-manager',
465
+ '@nocobase/plugin-departments',
466
+ '@nocobase/plugin-field-attachment-url',
467
+ '@nocobase/plugin-workflow-response-message',
468
+ ];
469
+ for (const pkg of pkgs) {
470
+ const pkgDir = resolve(process.cwd(), 'storage/plugins', pkg);
471
+ fs.existsSync(pkgDir) && fs.rmdirSync(pkgDir, { recursive: true, force: true });
472
+ }
473
+ };
474
+
475
+ exports.checkDBDialect = function () {
476
+ if (!process.env.DB_DIALECT) {
477
+ throw new Error('DB_DIALECT is required.');
478
+ }
465
479
  };
466
480
 
467
481
  exports.generatePlugins = function () {
@@ -0,0 +1,39 @@
1
+ {
2
+ "private": true,
3
+ "workspaces": ["packages/*/*", "packages/*/*/*"],
4
+ "engines": {
5
+ "node": ">=18"
6
+ },
7
+ "scripts": {
8
+ "nocobase": "nocobase",
9
+ "pm": "nocobase pm",
10
+ "pm2": "nocobase pm2",
11
+ "dev": "nocobase dev",
12
+ "start": "nocobase start",
13
+ "clean": "nocobase clean",
14
+ "build": "nocobase build",
15
+ "test": "nocobase test",
16
+ "e2e": "nocobase e2e",
17
+ "tar": "nocobase tar",
18
+ "postinstall": "nocobase postinstall",
19
+ "lint": "eslint ."
20
+ },
21
+ "resolutions": {
22
+ "cytoscape": "3.28.0",
23
+ "@types/react": "18.3.18",
24
+ "@types/react-dom": "^18.0.0",
25
+ "react-router-dom": "6.28.1",
26
+ "react-router": "6.28.1",
27
+ "async": "^3.2.6",
28
+ "antd": "5.12.8",
29
+ "rollup": "4.24.0",
30
+ "semver": "^7.7.1"
31
+ },
32
+ "dependencies": {
33
+ "pm2": "^6.0.5",
34
+ "mysql2": "^3.14.0",
35
+ "mariadb": "^2.5.6",
36
+ "pg": "^8.14.1",
37
+ "pg-hstore": "^2.3.4"
38
+ }
39
+ }