@nocobase/cli-v1 2.1.0-alpha.18 → 2.1.0-alpha.20

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-v1",
3
- "version": "2.1.0-alpha.18",
3
+ "version": "2.1.0-alpha.20",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./src/index.js",
@@ -8,7 +8,9 @@
8
8
  "nocobase-v1": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
+ "@nocobase/cli": "2.1.0-alpha.20",
11
12
  "@nocobase/license-kit": "^0.3.8",
13
+ "@nocobase/utils": "2.1.0-alpha.20",
12
14
  "@types/fs-extra": "^11.0.1",
13
15
  "@umijs/utils": "3.5.20",
14
16
  "chalk": "^4.1.1",
@@ -26,12 +28,12 @@
26
28
  "tsx": "^4.19.0"
27
29
  },
28
30
  "devDependencies": {
29
- "@nocobase/devtools": "2.1.0-alpha.18"
31
+ "@nocobase/devtools": "2.1.0-alpha.20"
30
32
  },
31
33
  "repository": {
32
34
  "type": "git",
33
35
  "url": "git+https://github.com/nocobase/nocobase.git",
34
36
  "directory": "packages/core/cli"
35
37
  },
36
- "gitHead": "e75843d4c557117bbcced047b88ed11d601ff86d"
38
+ "gitHead": "3d1535db6bf93ca23257faf474afee0d565f54c6"
37
39
  }
@@ -61,6 +61,10 @@ module.exports = (cli) => {
61
61
  return;
62
62
  }
63
63
 
64
+ if (pkgs.length === 0) {
65
+ await run('nocobase-v1', ['clean', '--dist']);
66
+ }
67
+
64
68
  if (options.compile || options.watch || isPackageValid('@nocobase/build/src/index.ts')) {
65
69
  await run('yarn', ['build', options.watch ? '--watch' : ''], {
66
70
  cwd: resolve(process.cwd(), 'packages/core/build'),
@@ -19,12 +19,24 @@ module.exports = (cli) => {
19
19
  cli
20
20
  .command('clean')
21
21
  .allowUnknownOption()
22
- .action(() => {
22
+ .option('--dist', 'only clean build output (lib,esm,es,dist), keep node_modules')
23
+ .action((options) => {
23
24
  if (!isDev()) {
24
25
  return;
25
26
  }
26
- run('rimraf', ['-rf', './storage/app-dev']);
27
- run('rimraf', ['-rf', 'packages/*/*/{lib,esm,es,dist,node_modules}']);
28
- run('rimraf', ['-rf', 'packages/*/@*/*/{lib,esm,es,dist,node_modules}']);
27
+ if (options.dist) {
28
+ run('rimraf', ['-rf', 'packages/*/*/{lib,esm,es}']);
29
+ run('rimraf', ['-rf', 'packages/*/@*/*/{lib,esm,es,dist}']);
30
+ // Clean dist separately, skip packages/core/cli/dist to keep the nb CLI functional
31
+ const fg = require('fast-glob');
32
+ const distDirs = fg.sync(['packages/*/*/dist', '!packages/core/cli/dist'], { onlyDirectories: true });
33
+ if (distDirs.length) {
34
+ run('rimraf', ['-rf', ...distDirs]);
35
+ }
36
+ } else {
37
+ run('rimraf', ['-rf', './storage/app-dev']);
38
+ run('rimraf', ['-rf', 'packages/*/*/{lib,esm,es,dist,node_modules}']);
39
+ run('rimraf', ['-rf', 'packages/*/@*/*/{lib,esm,es,dist,node_modules}']);
40
+ }
29
41
  });
30
42
  };
@@ -8,9 +8,9 @@
8
8
  */
9
9
 
10
10
  const { resolve, posix } = require('path');
11
+ const { storagePathJoin, resolvePublicPath, resolveV2PublicPath } = require('../util');
11
12
  const { Command } = require('commander');
12
13
  const { readFileSync, writeFileSync } = require('fs');
13
- const { resolvePublicPath, resolveV2PublicPath } = require('../util');
14
14
 
15
15
  /**
16
16
  *
@@ -47,7 +47,7 @@ module.exports = (cli) => {
47
47
  .replace(/\{\{v2PublicPathNoTrailingSlash\}\}/g, v2PublicPathWithoutTrailingSlash)
48
48
  .replace(/\{\{apiPort\}\}/g, process.env.APP_PORT)
49
49
  .replace(/\{\{otherLocation\}\}/g, otherLocation);
50
- const targetFile = resolve(process.cwd(), 'storage', 'nocobase.conf');
50
+ const targetFile = storagePathJoin('nocobase.conf');
51
51
  writeFileSync(targetFile, replaced);
52
52
  });
53
53
  };
@@ -93,14 +93,14 @@ async function appReady() {
93
93
 
94
94
  async function runApp(options = {}) {
95
95
  console.log('installing...');
96
- await run('nocobase', ['install', '-f']);
97
- await run('nocobase', ['pm', 'enable-all']);
96
+ await run('nocobase-v1', ['install', '-f']);
97
+ await run('nocobase-v1', ['pm', 'enable-all']);
98
98
  if (await isPortReachable(process.env.APP_PORT)) {
99
99
  console.log('app started');
100
100
  return;
101
101
  }
102
102
  console.log('starting...');
103
- run('nocobase', [process.env.APP_ENV === 'production' ? 'start' : 'dev'], options);
103
+ run('nocobase-v1', [process.env.APP_ENV === 'production' ? 'start' : 'dev'], options);
104
104
  }
105
105
 
106
106
  process.on('SIGINT', async () => {
@@ -235,8 +235,8 @@ module.exports = (cli) => {
235
235
  });
236
236
 
237
237
  e2e.command('reinstall-app').action(async (options) => {
238
- await run('nocobase', ['install', '-f'], options);
239
- await run('nocobase', ['pm2', 'enable-all']);
238
+ await run('nocobase-v1', ['install', '-f'], options);
239
+ await run('nocobase-v1', ['pm2', 'enable-all']);
240
240
  });
241
241
 
242
242
  e2e.command('install-deps').action(async () => {
@@ -13,7 +13,7 @@ const fs = require('fs-extra');
13
13
  const zlib = require('zlib');
14
14
  const tar = require('tar');
15
15
  const path = require('path');
16
- const { createStoragePluginsSymlink } = require('@nocobase/utils/plugin-symlink');
16
+ const { createStoragePluginsSymlink, resolvePluginStoragePath } = require('@nocobase/utils/plugin-symlink');
17
17
  const { getAccessKeyPair, showLicenseInfo, LicenseKeyError } = require('../license');
18
18
  const { logger } = require('../logger');
19
19
 
@@ -98,7 +98,7 @@ class Package {
98
98
 
99
99
  async isDepPackage() {
100
100
  const pkg1 = path.resolve(process.cwd(), 'node_modules', this.packageName, 'package.json');
101
- const pkg2 = path.resolve(process.cwd(), process.env.PLUGIN_STORAGE_PATH, this.packageName, 'package.json');
101
+ const pkg2 = path.resolve(resolvePluginStoragePath(), this.packageName, 'package.json');
102
102
  if ((await fs.exists(pkg1)) && (await fs.exists(pkg2))) {
103
103
  const readPath1 = fs.realpathSync(pkg1);
104
104
  const readPath2 = fs.realpathSync(pkg2);
@@ -110,7 +110,7 @@ class Package {
110
110
  }
111
111
 
112
112
  async isDownloaded(version) {
113
- const packageFile = path.resolve(process.env.PLUGIN_STORAGE_PATH, this.packageName, 'package.json');
113
+ const packageFile = path.resolve(resolvePluginStoragePath(), this.packageName, 'package.json');
114
114
  if (await fs.exists(packageFile)) {
115
115
  const json = await fs.readJson(packageFile);
116
116
  if (json.version === version) {
@@ -242,7 +242,7 @@ class PackageManager {
242
242
  }
243
243
 
244
244
  async removePackage(packageName) {
245
- const dir = path.resolve(process.env.PLUGIN_STORAGE_PATH, packageName);
245
+ const dir = path.resolve(resolvePluginStoragePath(), packageName);
246
246
  const r = await fs.exists(dir);
247
247
  if (r) {
248
248
  logger.info(`Removed: ${packageName}`);
@@ -40,8 +40,8 @@ module.exports = (cli) => {
40
40
  if (options.skipCodeUpdate) {
41
41
  await runAppCommand('upgrade');
42
42
  } else {
43
- await run('nocobase', ['update-deps']);
44
- await run('nocobase', ['upgrade', '--skip-code-update']);
43
+ await run('nocobase-v1', ['update-deps']);
44
+ await run('nocobase-v1', ['upgrade', '--skip-code-update']);
45
45
  }
46
46
  });
47
47
  };
package/src/logger.js CHANGED
@@ -9,6 +9,7 @@
9
9
 
10
10
  const fs = require('fs');
11
11
  const path = require('path');
12
+ const { storagePathJoin } = require('./util');
12
13
  const winston = require('winston');
13
14
  require('winston-daily-rotate-file');
14
15
 
@@ -62,7 +63,7 @@ function createSystemLogger({ dirname, filename, defaultMeta = {} }) {
62
63
  }
63
64
 
64
65
  const getLoggerFilePath = (...paths) => {
65
- return path.resolve(process.env.LOGGER_BASE_PATH || path.resolve(process.cwd(), 'storage', 'logs'), ...paths);
66
+ return path.resolve(process.env.LOGGER_BASE_PATH || storagePathJoin('logs'), ...paths);
66
67
  };
67
68
 
68
69
  const logger = createSystemLogger({
package/src/util.js CHANGED
@@ -18,6 +18,7 @@ const dotenv = require('dotenv');
18
18
  const fs = require('fs-extra');
19
19
  const os = require('os');
20
20
  const moment = require('moment-timezone');
21
+ const { resolvePluginStoragePath } = require('@nocobase/utils/plugin-symlink');
21
22
 
22
23
  exports.isPackageValid = (pkg) => {
23
24
  try {
@@ -297,7 +298,7 @@ exports.genTsConfigPaths = function genTsConfigPaths() {
297
298
 
298
299
  function generatePlaywrightPath(clean = false) {
299
300
  try {
300
- const playwright = resolve(process.cwd(), 'storage/playwright/tests');
301
+ const playwright = storagePathJoin('playwright', 'tests');
301
302
  if (clean && fs.existsSync(playwright)) {
302
303
  fs.rmSync(dirname(playwright), { force: true, recursive: true });
303
304
  }
@@ -399,6 +400,30 @@ function areTimeZonesEqual(timeZone1, timeZone2) {
399
400
  return moment.tz(timeZone1).format('Z') === moment.tz(timeZone2).format('Z');
400
401
  }
401
402
 
403
+ /**
404
+ * Absolute application storage root (same rules as `@nocobase/utils` `resolveStorageRoot`).
405
+ * Resolves STORAGE_PATH for initEnv; after initEnv, `process.env.STORAGE_PATH` is set to this absolute path.
406
+ */
407
+ function resolveStorageRoot() {
408
+ if (process.env.STORAGE_PATH) {
409
+ if (isAbsolute(process.env.STORAGE_PATH)) {
410
+ return process.env.STORAGE_PATH;
411
+ }
412
+ return resolve(process.cwd(), process.env.STORAGE_PATH);
413
+ }
414
+ return resolve(process.cwd(), 'storage');
415
+ }
416
+
417
+ /** Join segments under the storage root (same semantics as `@nocobase/utils` `storagePathJoin`). */
418
+ function storagePathJoin(...segments) {
419
+ return join(resolveStorageRoot(), ...segments);
420
+ }
421
+
422
+ exports.resolveStorageRoot = resolveStorageRoot;
423
+ exports.storagePathJoin = storagePathJoin;
424
+ /** @deprecated Use resolveStorageRoot — kept for backward compatibility */
425
+ exports.generateStoragePath = resolveStorageRoot;
426
+
402
427
  function generateGatewayPath() {
403
428
  if (process.env.SOCKET_PATH) {
404
429
  if (isAbsolute(process.env.SOCKET_PATH)) {
@@ -409,7 +434,7 @@ function generateGatewayPath() {
409
434
  if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
410
435
  return resolve(os.homedir(), '.nocobase', 'gateway.sock');
411
436
  }
412
- return resolve(process.cwd(), 'storage/gateway.sock');
437
+ return storagePathJoin('gateway.sock');
413
438
  }
414
439
 
415
440
  function generatePm2Home() {
@@ -422,7 +447,7 @@ function generatePm2Home() {
422
447
  if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
423
448
  return resolve(os.homedir(), '.nocobase', 'pm2');
424
449
  }
425
- return resolve(process.cwd(), './storage/.pm2');
450
+ return storagePathJoin('.pm2');
426
451
  }
427
452
 
428
453
  exports.initEnv = function initEnv() {
@@ -435,12 +460,10 @@ exports.initEnv = function initEnv() {
435
460
  API_CLIENT_SHARE_TOKEN: 'false',
436
461
  API_CLIENT_STORAGE_TYPE: 'localStorage',
437
462
  // DB_DIALECT: 'sqlite',
438
- DB_STORAGE: 'storage/db/nocobase.sqlite',
463
+ // DB_STORAGE, LOCAL_STORAGE_DEST, PLUGIN_STORAGE_PATH, etc. are set after dotenv from STORAGE_PATH
439
464
  // DB_TIMEZONE: '+00:00',
440
465
  DB_UNDERSCORED: parseEnv('DB_UNDERSCORED'),
441
466
  DEFAULT_STORAGE_TYPE: 'local',
442
- LOCAL_STORAGE_DEST: 'storage/uploads',
443
- PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
444
467
  MFSU_AD: 'none',
445
468
  MAKO_AD: 'none',
446
469
  WS_PATH: '/ws',
@@ -449,17 +472,14 @@ exports.initEnv = function initEnv() {
449
472
  NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
450
473
  PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
451
474
  SERVER_TSCONFIG_PATH: './tsconfig.server.json',
452
- PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
453
475
  CACHE_DEFAULT_STORE: 'memory',
454
476
  CACHE_MEMORY_MAX: 2000,
455
477
  BROWSERSLIST_IGNORE_OLD_DATA: true,
456
478
  PLUGIN_STATICS_PATH: '/static/plugins/',
457
- LOGGER_BASE_PATH: 'storage/logs',
458
479
  APP_SERVER_BASE_URL: '',
459
480
  APP_BASE_URL: '',
460
481
  CDN_BASE_URL: '',
461
482
  APP_PUBLIC_PATH: '/',
462
- WATCH_FILE: resolve(process.cwd(), 'storage/app.watch.ts'),
463
483
  ESM_CDN_BASE_URL: 'https://esm.sh',
464
484
  ESM_CDN_SUFFIX: '',
465
485
  };
@@ -491,6 +511,17 @@ exports.initEnv = function initEnv() {
491
511
  path: resolve(process.cwd(), process.env.APP_ENV_PATH || '.env'),
492
512
  });
493
513
 
514
+ const storagePath = resolveStorageRoot();
515
+ process.env.STORAGE_PATH = storagePath; // absolute; other modules may use process.env.STORAGE_PATH after this
516
+ Object.assign(env, {
517
+ DB_STORAGE: storagePathJoin('db', 'nocobase.sqlite'),
518
+ LOCAL_STORAGE_DEST: storagePathJoin('uploads'),
519
+ PLUGIN_STORAGE_PATH: storagePathJoin('plugins'),
520
+ PLAYWRIGHT_AUTH_FILE: storagePathJoin('playwright', '.auth', 'admin.json'),
521
+ LOGGER_BASE_PATH: storagePathJoin('logs'),
522
+ WATCH_FILE: storagePathJoin('app.watch.ts'),
523
+ });
524
+
494
525
  if (process.argv[2] === 'e2e' && !process.env.APP_BASE_URL) {
495
526
  process.env.APP_BASE_URL = `http://127.0.0.1:${process.env.APP_PORT}`;
496
527
  }
@@ -555,7 +586,7 @@ exports.initEnv = function initEnv() {
555
586
  '@nocobase/plugin-workflow-response-message',
556
587
  ];
557
588
  for (const pkg of pkgs) {
558
- const pkgDir = resolve(process.cwd(), 'storage/plugins', pkg);
589
+ const pkgDir = join(resolvePluginStoragePath(), pkg);
559
590
  fs.existsSync(pkgDir) && fs.rmdirSync(pkgDir, { recursive: true, force: true });
560
591
  }
561
592
  };