@nocobase/cli-v1 2.1.9 → 2.1.11

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.9",
3
+ "version": "2.1.11",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./src/index.js",
@@ -9,9 +9,9 @@
9
9
  "nocobase-v1": "./bin/index.js"
10
10
  },
11
11
  "dependencies": {
12
- "@nocobase/cli": "2.1.9",
12
+ "@nocobase/cli": "2.1.11",
13
13
  "@nocobase/license-kit": "^0.3.8",
14
- "@nocobase/utils": "2.1.9",
14
+ "@nocobase/utils": "2.1.11",
15
15
  "chalk": "^4.1.1",
16
16
  "commander": "^9.2.0",
17
17
  "deepmerge": "^4.3.1",
@@ -33,5 +33,5 @@
33
33
  "url": "git+https://github.com/nocobase/nocobase.git",
34
34
  "directory": "packages/core/cli"
35
35
  },
36
- "gitHead": "2b612d81c6f6115af75ea7b279384751af869510"
36
+ "gitHead": "1ccf891d837e21089f65f84b892407b34a0a0cb9"
37
37
  }
@@ -82,6 +82,7 @@ describe('cli-v1 app-dev utils', () => {
82
82
  }),
83
83
  ).toEqual([
84
84
  'watch',
85
+ '--clear-screen=false',
85
86
  `--ignore=${path.resolve(process.cwd(), 'storage/plugins')}/**`,
86
87
  '--tsconfig',
87
88
  './tsconfig.server.json',
@@ -0,0 +1,33 @@
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
+ /* eslint-env jest */
11
+
12
+ const { colorizedDevLogEnv, createRunWithPrefixLabel } = require('../util')._test;
13
+
14
+ describe('cli-v1 util helpers', () => {
15
+ test('colorizedDevLogEnv enables color for dev child output by default', () => {
16
+ expect(colorizedDevLogEnv({})).toEqual({ FORCE_COLOR: '1' });
17
+ });
18
+
19
+ test('colorizedDevLogEnv keeps explicit FORCE_COLOR', () => {
20
+ expect(colorizedDevLogEnv({ FORCE_COLOR: '3' })).toEqual({ FORCE_COLOR: '3' });
21
+ });
22
+
23
+ test('colorizedDevLogEnv removes inherited NO_COLOR so dev logs stay colored', () => {
24
+ expect(colorizedDevLogEnv({ NO_COLOR: '1', TERM: 'dumb' })).toEqual({
25
+ FORCE_COLOR: '1',
26
+ TERM: 'dumb',
27
+ });
28
+ });
29
+
30
+ test('createRunWithPrefixLabel colorizes prefixed output even when the parent disables colors', () => {
31
+ expect(createRunWithPrefixLabel('client', 'cyan')).toBe('\u001b[36m[client]\u001b[39m');
32
+ });
33
+ });
@@ -150,7 +150,7 @@ function buildAppDevServerArgs({
150
150
  argv = process.argv,
151
151
  serverTsconfigPath = process.env.SERVER_TSCONFIG_PATH,
152
152
  } = {}) {
153
- const args = ['watch', `--ignore=${resolvePluginStoragePath()}/**`];
153
+ const args = ['watch', '--clear-screen=false', `--ignore=${resolvePluginStoragePath()}/**`];
154
154
 
155
155
  if (serverTsconfigPath) {
156
156
  args.push('--tsconfig', serverTsconfigPath);
@@ -13,6 +13,7 @@ const {
13
13
  hasCorePackages,
14
14
  run,
15
15
  runWithPrefix,
16
+ colorizedDevLogEnv,
16
17
  postCheck,
17
18
  nodeCheck,
18
19
  promptForTs,
@@ -198,16 +199,13 @@ module.exports = (cli) => {
198
199
  }
199
200
  subprocessRef.cancel();
200
201
  let i = 0;
201
- while (true) {
202
+ while (i <= 10) {
202
203
  ++i;
203
204
  const result = await isPortReachable(port);
204
205
  if (!result) {
205
206
  break;
206
207
  }
207
208
  await sleep(500);
208
- if (i > 10) {
209
- break;
210
- }
211
209
  }
212
210
  start();
213
211
  };
@@ -216,7 +214,7 @@ module.exports = (cli) => {
216
214
  const storagePluginPath = resolvePluginStoragePath();
217
215
  const watcher = chokidar.watch(`${storagePluginPath}/**/*`, {
218
216
  cwd: process.cwd(),
219
- ignored: /(^|[\/\\])\../, // 忽略隐藏文件
217
+ ignored: /(^|[/\\])\../, // 忽略隐藏文件
220
218
  persistent: true,
221
219
  depth: 1, // 只监听第一层目录
222
220
  });
@@ -260,6 +258,7 @@ module.exports = (cli) => {
260
258
 
261
259
  const argv = [
262
260
  'watch',
261
+ '--clear-screen=false',
263
262
  ...(inspect ? [`--inspect=${inspect === true ? 9229 : inspect}`] : []),
264
263
  `--ignore=${resolvePluginStoragePath()}/**`,
265
264
  '--tsconfig',
@@ -278,9 +277,9 @@ module.exports = (cli) => {
278
277
 
279
278
  const runDevServer = () => {
280
279
  run('tsx', argv, {
281
- env: {
280
+ env: colorizedDevLogEnv(process.env, {
282
281
  APP_PORT: serverPort,
283
- },
282
+ }),
284
283
  }).catch((err) => {
285
284
  if (err.exitCode == 100) {
286
285
  console.log('Restarting server...');
package/src/util.js CHANGED
@@ -84,6 +84,24 @@ exports.run = (command, args, options = {}) => {
84
84
  });
85
85
  };
86
86
 
87
+ function colorizedDevLogEnv(env = process.env, overrides = {}) {
88
+ const nextEnv = {
89
+ ...env,
90
+ ...overrides,
91
+ };
92
+ delete nextEnv.NO_COLOR;
93
+ if (!nextEnv.FORCE_COLOR) {
94
+ nextEnv.FORCE_COLOR = '1';
95
+ }
96
+ return nextEnv;
97
+ }
98
+
99
+ function createRunWithPrefixLabel(prefix, color) {
100
+ const forcedChalk = new chalk.Instance({ level: 1 });
101
+ const colorize = forcedChalk[color] || forcedChalk.cyan;
102
+ return colorize(`[${prefix}]`);
103
+ }
104
+
87
105
  exports.runWithPrefix = (command, args, options = {}) => {
88
106
  if (command === 'tsx') {
89
107
  command = 'node';
@@ -92,15 +110,12 @@ exports.runWithPrefix = (command, args, options = {}) => {
92
110
 
93
111
  const prefix = options.prefix || 'process';
94
112
  const color = options.color || 'cyan';
95
- const label = chalk[color](`[${prefix}]`);
113
+ const label = createRunWithPrefixLabel(prefix, color);
96
114
  const subprocess = execa(command, args, {
97
115
  shell: true,
98
116
  stdio: 'pipe',
99
117
  ...options,
100
- env: {
101
- ...process.env,
102
- ...options.env,
103
- },
118
+ env: colorizedDevLogEnv(process.env, options.env),
104
119
  });
105
120
 
106
121
  const writePrefixed = (chunk, writer) => {
@@ -122,6 +137,13 @@ exports.runWithPrefix = (command, args, options = {}) => {
122
137
  return subprocess;
123
138
  };
124
139
 
140
+ exports._test = {
141
+ createRunWithPrefixLabel,
142
+ colorizedDevLogEnv,
143
+ };
144
+
145
+ exports.colorizedDevLogEnv = colorizedDevLogEnv;
146
+
125
147
  exports.isPortReachable = async (port, { timeout = 1000, host } = {}) => {
126
148
  const promise = new Promise((resolve, reject) => {
127
149
  const socket = new net.Socket();