@nocobase/cli 2.1.0-beta.44.test.3 → 2.1.0-beta.44.test.4

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.
Files changed (77) hide show
  1. package/bin/run.js +40 -3
  2. package/dist/commands/app/destroy.js +13 -6
  3. package/dist/commands/app/restart.js +11 -2
  4. package/dist/commands/app/shared.js +3 -2
  5. package/dist/commands/app/start.js +10 -2
  6. package/dist/commands/app/upgrade.js +6 -4
  7. package/dist/commands/config/delete.js +2 -0
  8. package/dist/commands/config/get.js +2 -0
  9. package/dist/commands/config/set.js +2 -0
  10. package/dist/commands/env/add.js +5 -5
  11. package/dist/commands/init.js +117 -7
  12. package/dist/commands/install.js +50 -13
  13. package/dist/commands/source/download.js +1 -1
  14. package/dist/commands/source/test.js +13 -14
  15. package/dist/locale/en-US.json +13 -5
  16. package/dist/locale/zh-CN.json +13 -5
  17. package/package.json +1 -7
  18. package/scripts/build.mjs +34 -0
  19. package/scripts/clean.mjs +9 -0
  20. package/tsconfig.json +19 -0
  21. package/dist/lib/api-client.js +0 -335
  22. package/dist/lib/api-command-compat.js +0 -641
  23. package/dist/lib/app-health.js +0 -139
  24. package/dist/lib/app-managed-resources.js +0 -321
  25. package/dist/lib/app-public-path.js +0 -80
  26. package/dist/lib/app-runtime.js +0 -189
  27. package/dist/lib/auth-store.js +0 -498
  28. package/dist/lib/backup.js +0 -171
  29. package/dist/lib/bootstrap.js +0 -409
  30. package/dist/lib/build-config.js +0 -18
  31. package/dist/lib/builtin-db.js +0 -86
  32. package/dist/lib/cli-config.js +0 -398
  33. package/dist/lib/cli-entry-error.js +0 -44
  34. package/dist/lib/cli-home.js +0 -47
  35. package/dist/lib/cli-locale.js +0 -141
  36. package/dist/lib/command-discovery.js +0 -39
  37. package/dist/lib/db-connection-check.js +0 -219
  38. package/dist/lib/docker-env-file.js +0 -60
  39. package/dist/lib/docker-image.js +0 -37
  40. package/dist/lib/docker-log-stream.js +0 -45
  41. package/dist/lib/env-auth.js +0 -960
  42. package/dist/lib/env-command-config.js +0 -45
  43. package/dist/lib/env-config.js +0 -100
  44. package/dist/lib/env-guard.js +0 -61
  45. package/dist/lib/env-paths.js +0 -101
  46. package/dist/lib/env-proxy.js +0 -1295
  47. package/dist/lib/generated-command.js +0 -203
  48. package/dist/lib/http-request.js +0 -49
  49. package/dist/lib/inquirer-theme.js +0 -17
  50. package/dist/lib/inquirer.js +0 -243
  51. package/dist/lib/managed-env-file.js +0 -98
  52. package/dist/lib/naming.js +0 -70
  53. package/dist/lib/object-utils.js +0 -76
  54. package/dist/lib/openapi.js +0 -62
  55. package/dist/lib/plugin-import.js +0 -279
  56. package/dist/lib/plugin-storage.js +0 -64
  57. package/dist/lib/post-processors.js +0 -23
  58. package/dist/lib/prompt-catalog-core.js +0 -185
  59. package/dist/lib/prompt-catalog-terminal.js +0 -375
  60. package/dist/lib/prompt-catalog.js +0 -10
  61. package/dist/lib/prompt-validators.js +0 -258
  62. package/dist/lib/prompt-web-ui.js +0 -2227
  63. package/dist/lib/resource-command.js +0 -357
  64. package/dist/lib/resource-request.js +0 -104
  65. package/dist/lib/run-npm.js +0 -393
  66. package/dist/lib/runtime-env-vars.js +0 -32
  67. package/dist/lib/runtime-generator.js +0 -498
  68. package/dist/lib/runtime-store.js +0 -56
  69. package/dist/lib/self-manager.js +0 -301
  70. package/dist/lib/session-id.js +0 -17
  71. package/dist/lib/session-integration.js +0 -703
  72. package/dist/lib/session-store.js +0 -118
  73. package/dist/lib/skills-manager.js +0 -438
  74. package/dist/lib/source-publish.js +0 -326
  75. package/dist/lib/source-registry.js +0 -188
  76. package/dist/lib/startup-update.js +0 -309
  77. package/dist/lib/ui.js +0 -159
@@ -1,393 +0,0 @@
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
- * This file is part of the NocoBase (R) project.
11
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
- * Authors: NocoBase Team.
13
- *
14
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
15
- * For more information, please refer to: https://www.nocobase.com/agreement.
16
- */
17
- import fs from 'node:fs';
18
- import fsp from 'node:fs/promises';
19
- import os from 'node:os';
20
- import path from 'node:path';
21
- import spawn from 'cross-spawn';
22
- import { translateCli } from './cli-locale.js';
23
- import { resolveConfiguredCommandName } from './cli-config.js';
24
- const FORWARDED_SIGNALS = ['SIGINT', 'SIGTERM'];
25
- const PROCESS_TIMEOUT_FORCE_KILL_DELAY_MS = 1000;
26
- const MISSING_COMMAND_SPECS = {
27
- docker: {
28
- displayName: 'Docker',
29
- configKey: 'bin.docker',
30
- },
31
- caddy: {
32
- displayName: 'Caddy',
33
- configKey: 'bin.caddy',
34
- },
35
- git: {
36
- displayName: 'Git',
37
- configKey: 'bin.git',
38
- },
39
- nginx: {
40
- displayName: 'Nginx',
41
- configKey: 'bin.nginx',
42
- },
43
- yarn: {
44
- displayName: 'Yarn',
45
- configKey: 'bin.yarn',
46
- },
47
- };
48
- async function resolveCommandName(name) {
49
- return await resolveConfiguredCommandName(name);
50
- }
51
- function createMissingCommandError(name, label, error) {
52
- const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : undefined;
53
- if (code !== 'ENOENT') {
54
- return undefined;
55
- }
56
- if (!Object.prototype.hasOwnProperty.call(MISSING_COMMAND_SPECS, name)) {
57
- return undefined;
58
- }
59
- const spec = MISSING_COMMAND_SPECS[name];
60
- return new Error(translateCli('commands.shared.missingCommand', { action: label, displayName: spec.displayName, configKey: spec.configKey }, {
61
- fallback: `Couldn't run \`${label}\` because the ${spec.displayName} executable could not be found. Install ${spec.displayName} or update \`nb config set ${spec.configKey} <path>\` and try again.`,
62
- }));
63
- }
64
- function pathExists(candidate) {
65
- try {
66
- return Boolean(candidate) && fs.statSync(candidate) !== undefined;
67
- }
68
- catch {
69
- return false;
70
- }
71
- }
72
- function isDirectory(candidate) {
73
- try {
74
- return Boolean(candidate) && fs.statSync(candidate).isDirectory();
75
- }
76
- catch {
77
- return false;
78
- }
79
- }
80
- function hasLocalNocoBaseBinary(candidate) {
81
- return (pathExists(path.join(candidate, 'node_modules', '.bin', 'nocobase-v1')) ||
82
- pathExists(path.join(candidate, 'node_modules', '.bin', 'nocobase-v1.cmd')));
83
- }
84
- export function resolveCwd(cwd) {
85
- const next = cwd ?? process.cwd();
86
- if (path.isAbsolute(next)) {
87
- return next;
88
- }
89
- return path.resolve(process.cwd(), next);
90
- }
91
- export function resolveProjectCwd(cwd) {
92
- const normalizedCwd = typeof cwd === 'string' && cwd.trim() === '' ? undefined : cwd;
93
- const fallback = resolveCwd(normalizedCwd);
94
- const hasExplicitInput = normalizedCwd !== undefined;
95
- if (hasExplicitInput && !pathExists(fallback)) {
96
- throw new Error(`The specified --cwd does not exist: ${fallback}`);
97
- }
98
- if (hasExplicitInput && !isDirectory(fallback)) {
99
- throw new Error(`The specified --cwd is not a directory: ${fallback}`);
100
- }
101
- let current = hasExplicitInput ? fallback : process.cwd();
102
- while (!hasLocalNocoBaseBinary(current)) {
103
- const parent = path.dirname(current);
104
- if (parent === current) {
105
- if (hasExplicitInput) {
106
- throw new Error(`Couldn't find a NocoBase source project from --cwd: ${fallback}`);
107
- }
108
- return fallback;
109
- }
110
- current = parent;
111
- }
112
- return current;
113
- }
114
- export async function run(name, args, options) {
115
- const cwd = resolveCwd(options?.cwd);
116
- const label = options?.errorName ?? name;
117
- const command = await resolveCommandName(name);
118
- return await new Promise((resolve, reject) => {
119
- const child = spawn(command, [...args], {
120
- stdio: options?.stdio ?? 'inherit',
121
- cwd,
122
- env: {
123
- ...process.env,
124
- ...options?.env,
125
- },
126
- windowsHide: process.platform === 'win32',
127
- });
128
- if (options?.stdio === 'pipe') {
129
- child.stdout?.setEncoding('utf8');
130
- child.stderr?.setEncoding('utf8');
131
- if (options.onStdout) {
132
- child.stdout?.on('data', (chunk) => {
133
- options.onStdout?.(String(chunk));
134
- });
135
- }
136
- if (options.onStderr) {
137
- child.stderr?.on('data', (chunk) => {
138
- options.onStderr?.(String(chunk));
139
- });
140
- }
141
- }
142
- const cleanupSignalForwarding = forwardSignalsToChild(child);
143
- const timeoutController = attachProcessTimeout(child, options?.timeoutMs);
144
- child.once('error', (error) => {
145
- timeoutController.cleanup();
146
- cleanupSignalForwarding();
147
- reject(createMissingCommandError(name, label, error) ?? error);
148
- });
149
- child.once('close', (code, signal) => {
150
- timeoutController.cleanup();
151
- cleanupSignalForwarding();
152
- if (timeoutController.didTimeout()) {
153
- reject(new Error(`${label} timed out after ${options?.timeoutMs}ms`));
154
- return;
155
- }
156
- if (code === 0) {
157
- resolve();
158
- return;
159
- }
160
- if (signal) {
161
- reject(new Error(`${label} exited due to signal ${signal}`));
162
- return;
163
- }
164
- reject(new Error(`${label} exited with code ${code}`));
165
- });
166
- });
167
- }
168
- function attachProcessTimeout(child, timeoutMs) {
169
- if (!timeoutMs || timeoutMs <= 0) {
170
- return {
171
- cleanup: () => undefined,
172
- didTimeout: () => false,
173
- };
174
- }
175
- let didTimeout = false;
176
- let forceKillTimer;
177
- const isChildRunning = () => child.exitCode === null && child.signalCode === null;
178
- const terminateChild = (signal) => {
179
- if (!isChildRunning()) {
180
- return;
181
- }
182
- try {
183
- child.kill(signal);
184
- }
185
- catch {
186
- // Ignore kill errors here and let the child close/error handlers surface the failure.
187
- }
188
- };
189
- const timeoutTimer = setTimeout(() => {
190
- didTimeout = true;
191
- terminateChild('SIGTERM');
192
- forceKillTimer = setTimeout(() => {
193
- terminateChild('SIGKILL');
194
- }, PROCESS_TIMEOUT_FORCE_KILL_DELAY_MS);
195
- forceKillTimer.unref?.();
196
- }, timeoutMs);
197
- timeoutTimer.unref?.();
198
- return {
199
- cleanup: () => {
200
- clearTimeout(timeoutTimer);
201
- if (forceKillTimer) {
202
- clearTimeout(forceKillTimer);
203
- }
204
- },
205
- didTimeout: () => didTimeout,
206
- };
207
- }
208
- function forwardSignalsToChild(child) {
209
- let forwardedSignalCount = 0;
210
- const listeners = new Map();
211
- const isChildRunning = () => child.exitCode === null && child.signalCode === null;
212
- for (const signal of FORWARDED_SIGNALS) {
213
- const listener = () => {
214
- if (!isChildRunning()) {
215
- return;
216
- }
217
- const nextSignal = forwardedSignalCount > 0 ? 'SIGKILL' : signal;
218
- forwardedSignalCount += 1;
219
- try {
220
- child.kill(nextSignal);
221
- }
222
- catch {
223
- // Ignore kill errors here and let the child close/error handlers surface the failure.
224
- }
225
- };
226
- listeners.set(signal, listener);
227
- process.on(signal, listener);
228
- }
229
- return () => {
230
- for (const [signal, listener] of listeners) {
231
- process.off(signal, listener);
232
- }
233
- };
234
- }
235
- export async function commandSucceeds(name, args, options) {
236
- const cwd = resolveCwd(options?.cwd);
237
- const label = options?.errorName ?? name;
238
- const command = await resolveCommandName(name);
239
- return await new Promise((resolve, reject) => {
240
- const child = spawn(command, [...args], {
241
- cwd,
242
- env: {
243
- ...process.env,
244
- ...options?.env,
245
- },
246
- stdio: 'ignore',
247
- windowsHide: process.platform === 'win32',
248
- });
249
- const timeoutController = attachProcessTimeout(child, options?.timeoutMs);
250
- child.once('error', (error) => {
251
- timeoutController.cleanup();
252
- const missingCommandError = createMissingCommandError(name, label, error);
253
- if (missingCommandError) {
254
- reject(missingCommandError);
255
- return;
256
- }
257
- resolve(false);
258
- });
259
- child.once('close', (code) => {
260
- timeoutController.cleanup();
261
- if (timeoutController.didTimeout()) {
262
- resolve(false);
263
- return;
264
- }
265
- resolve(code === 0);
266
- });
267
- });
268
- }
269
- export async function commandOutput(name, args, options) {
270
- const cwd = resolveCwd(options?.cwd);
271
- const label = options?.errorName ?? name;
272
- const command = await resolveCommandName(name);
273
- return await new Promise((resolve, reject) => {
274
- const child = spawn(command, [...args], {
275
- cwd,
276
- env: {
277
- ...process.env,
278
- ...options?.env,
279
- },
280
- stdio: ['ignore', 'pipe', 'pipe'],
281
- windowsHide: process.platform === 'win32',
282
- });
283
- let stdout = '';
284
- let stderr = '';
285
- child.stdout.setEncoding('utf8');
286
- child.stderr.setEncoding('utf8');
287
- child.stdout.on('data', (chunk) => {
288
- stdout += chunk;
289
- });
290
- child.stderr.on('data', (chunk) => {
291
- stderr += chunk;
292
- });
293
- const timeoutController = attachProcessTimeout(child, options?.timeoutMs);
294
- child.once('error', (error) => {
295
- timeoutController.cleanup();
296
- reject(createMissingCommandError(name, label, error) ?? error);
297
- });
298
- child.once('close', (code, signal) => {
299
- timeoutController.cleanup();
300
- if (timeoutController.didTimeout()) {
301
- reject(new Error(`${label} timed out after ${options?.timeoutMs}ms`));
302
- return;
303
- }
304
- if (code === 0) {
305
- resolve(stdout.trim());
306
- return;
307
- }
308
- if (signal) {
309
- reject(new Error(`${label} exited due to signal ${signal}`));
310
- return;
311
- }
312
- const details = stderr.trim() || stdout.trim();
313
- reject(new Error(details ? `${label} exited with code ${code}: ${details}` : `${label} exited with code ${code}`));
314
- });
315
- });
316
- }
317
- async function readCommandOutputFile(filePath) {
318
- try {
319
- return await fsp.readFile(filePath, 'utf8');
320
- }
321
- catch {
322
- return '';
323
- }
324
- }
325
- export async function commandOutputViaFile(name, args, options) {
326
- const cwd = resolveCwd(options?.cwd);
327
- const label = options?.errorName ?? name;
328
- const command = await resolveCommandName(name);
329
- const captureDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'nocobase-cli-output-'));
330
- const stdoutPath = path.join(captureDir, 'stdout.log');
331
- const stderrPath = path.join(captureDir, 'stderr.log');
332
- const stdoutHandle = await fsp.open(stdoutPath, 'w');
333
- const stderrHandle = await fsp.open(stderrPath, 'w');
334
- try {
335
- const result = await new Promise((resolve, reject) => {
336
- const child = spawn(command, [...args], {
337
- cwd,
338
- env: {
339
- ...process.env,
340
- ...options?.env,
341
- },
342
- stdio: ['ignore', stdoutHandle.fd, stderrHandle.fd],
343
- windowsHide: process.platform === 'win32',
344
- });
345
- const timeoutController = attachProcessTimeout(child, options?.timeoutMs);
346
- child.once('error', (error) => {
347
- timeoutController.cleanup();
348
- reject(createMissingCommandError(name, label, error) ?? error);
349
- });
350
- child.once('close', (code, signal) => {
351
- timeoutController.cleanup();
352
- if (timeoutController.didTimeout()) {
353
- reject(new Error(`${label} timed out after ${options?.timeoutMs}ms`));
354
- return;
355
- }
356
- resolve({ code, signal });
357
- });
358
- });
359
- await stdoutHandle.close();
360
- await stderrHandle.close();
361
- const stdout = await readCommandOutputFile(stdoutPath);
362
- const stderr = await readCommandOutputFile(stderrPath);
363
- if (result.code === 0) {
364
- return stdout.trim();
365
- }
366
- if (result.signal) {
367
- throw new Error(`${label} exited due to signal ${result.signal}`);
368
- }
369
- const details = stderr.trim() || stdout.trim();
370
- throw new Error(details ? `${label} exited with code ${result.code}: ${details}` : `${label} exited with code ${result.code}`);
371
- }
372
- finally {
373
- await Promise.allSettled([stdoutHandle.close(), stderrHandle.close()]);
374
- await fsp.rm(captureDir, { recursive: true, force: true });
375
- }
376
- }
377
- /** Run `yarn` with the given argument list, inheriting stdio (errors label as `npm` for compatibility). */
378
- export function runNpm(args, options) {
379
- return run('yarn', [...args], { ...options, errorName: 'npm' });
380
- }
381
- export function runNocoBaseCommand(args, options) {
382
- const cwd = resolveProjectCwd(options?.cwd);
383
- const localBin = path.join(cwd, 'node_modules', '.bin');
384
- return run('nocobase-v1', [...args], {
385
- ...options,
386
- cwd,
387
- errorName: 'nocobase command',
388
- env: {
389
- PATH: `${localBin}${path.delimiter}${process.env.PATH ?? ''}`,
390
- ...options?.env,
391
- },
392
- });
393
- }
@@ -1,32 +0,0 @@
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
- import { resolveBuiltinDbConnection } from './builtin-db.js';
10
- function put(out, key, value) {
11
- if (value === undefined || value === null) {
12
- return;
13
- }
14
- out[key] = String(value);
15
- }
16
- export async function buildRuntimeEnvVars(runtime) {
17
- const config = runtime.env.config ?? {};
18
- const out = {
19
- ...runtime.env.envVars,
20
- };
21
- if (runtime.kind !== 'local' && runtime.kind !== 'docker') {
22
- return out;
23
- }
24
- if (!config.builtinDb) {
25
- return out;
26
- }
27
- const connection = await resolveBuiltinDbConnection(runtime);
28
- put(out, 'DB_DIALECT', connection.dbDialect);
29
- put(out, 'DB_HOST', connection.dbHost);
30
- put(out, 'DB_PORT', connection.dbPort);
31
- return out;
32
- }