@nocobase/cli 2.1.0-beta.21 → 2.1.0-beta.22

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 (50) hide show
  1. package/README.md +28 -46
  2. package/README.zh-CN.md +27 -44
  3. package/dist/commands/app/down.js +260 -0
  4. package/dist/commands/app/info.js +140 -0
  5. package/dist/commands/app/logs.js +98 -0
  6. package/dist/commands/app/ps.js +60 -0
  7. package/dist/commands/app/restart.js +75 -0
  8. package/dist/commands/app/shared.js +95 -0
  9. package/dist/commands/app/start.js +252 -0
  10. package/dist/commands/app/stop.js +98 -0
  11. package/dist/commands/app/upgrade.js +595 -0
  12. package/dist/commands/build.js +3 -48
  13. package/dist/commands/dev.js +3 -147
  14. package/dist/commands/down.js +3 -188
  15. package/dist/commands/download.js +4 -856
  16. package/dist/commands/env/add.js +28 -23
  17. package/dist/commands/{prompts-stages.js → examples/prompts-stages.js} +3 -3
  18. package/dist/commands/{prompts-test.js → examples/prompts-test.js} +3 -3
  19. package/dist/commands/init.js +76 -5
  20. package/dist/commands/install.js +288 -61
  21. package/dist/commands/logs.js +3 -88
  22. package/dist/commands/plugin/disable.js +64 -0
  23. package/dist/commands/plugin/enable.js +64 -0
  24. package/dist/commands/plugin/list.js +62 -0
  25. package/dist/commands/pm/disable.js +3 -54
  26. package/dist/commands/pm/enable.js +3 -54
  27. package/dist/commands/pm/list.js +3 -52
  28. package/dist/commands/ps.js +3 -110
  29. package/dist/commands/restart.js +3 -65
  30. package/dist/commands/scaffold/migration.js +1 -1
  31. package/dist/commands/scaffold/plugin.js +1 -1
  32. package/dist/commands/skills/remove.js +71 -0
  33. package/dist/commands/skills/update.js +7 -0
  34. package/dist/commands/source/build.js +58 -0
  35. package/dist/commands/source/dev.js +157 -0
  36. package/dist/commands/source/download.js +866 -0
  37. package/dist/commands/source/test.js +467 -0
  38. package/dist/commands/start.js +3 -209
  39. package/dist/commands/stop.js +3 -88
  40. package/dist/commands/test.js +3 -457
  41. package/dist/commands/upgrade.js +3 -585
  42. package/dist/help/runtime-help.js +3 -0
  43. package/dist/lib/app-health.js +126 -0
  44. package/dist/lib/app-managed-resources.js +264 -0
  45. package/dist/lib/auth-store.js +5 -2
  46. package/dist/lib/cli-home.js +7 -6
  47. package/dist/lib/cli-locale.js +15 -1
  48. package/dist/lib/env-config.js +80 -0
  49. package/dist/lib/skills-manager.js +34 -7
  50. package/package.json +26 -3
@@ -6,151 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Command, Flags } from '@oclif/core';
10
- import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runLocalNocoBaseCommand, } from '../lib/app-runtime.js';
11
- import { printInfo } from '../lib/ui.js';
12
- function formatUnsupportedRuntimeMessage(kind, envName) {
13
- if (kind === 'docker') {
14
- return [
15
- `Can't run dev mode for "${envName}".`,
16
- 'This env is managed by Docker, but `nb dev` requires a local npm or Git source directory.',
17
- `Use \`nb logs --env ${envName}\` to inspect the Docker app, or create a source-based env with \`nb init --env ${envName} --source git\`.`,
18
- ].join('\n');
19
- }
20
- if (kind === 'ssh') {
21
- return [
22
- `Can't run dev mode for "${envName}" yet.`,
23
- 'SSH env support is reserved but not implemented yet.',
24
- `Create a source-based env with \`nb init --env ${envName} --source git\` if you want local development mode right now.`,
25
- ].join('\n');
26
- }
27
- return [
28
- `Can't run dev mode for "${envName}".`,
29
- 'This env only has an API connection, but `nb dev` requires a local npm or Git source directory.',
30
- `Create a source-based env with \`nb init --env ${envName} --source git\` if you want local development mode.`,
31
- ].join('\n');
32
- }
33
- function appUrlForPort(port) {
34
- const value = String(port ?? '').trim();
35
- if (!value) {
36
- return undefined;
37
- }
38
- return `http://127.0.0.1:${value}`;
39
- }
40
- async function isAppAlreadyRunning(appUrl) {
41
- if (!appUrl) {
42
- return false;
43
- }
44
- const controller = new AbortController();
45
- const timeout = setTimeout(() => controller.abort(), 1500);
46
- try {
47
- const response = await fetch(`${appUrl}/api/__health_check`, {
48
- signal: controller.signal,
49
- });
50
- const text = await response.text();
51
- return response.ok && text.trim().toLowerCase() === 'ok';
52
- }
53
- catch (_error) {
54
- return false;
55
- }
56
- finally {
57
- clearTimeout(timeout);
58
- }
59
- }
60
- export default class Dev extends Command {
61
- static description = 'Run NocoBase in local development mode for an npm or Git source env.';
62
- static examples = [
63
- '<%= config.bin %> <%= command.id %>',
64
- '<%= config.bin %> <%= command.id %> --env app1',
65
- '<%= config.bin %> <%= command.id %> --env app1 --db-sync',
66
- '<%= config.bin %> <%= command.id %> --env app1 --port 12000',
67
- '<%= config.bin %> <%= command.id %> --env app1 --client',
68
- '<%= config.bin %> <%= command.id %> --env app1 --server',
69
- '<%= config.bin %> <%= command.id %> --env app1 --inspect 9229',
70
- ];
71
- static flags = {
72
- env: Flags.string({
73
- char: 'e',
74
- description: 'CLI env name for dev mode. Defaults to the current env when omitted',
75
- required: false,
76
- }),
77
- 'db-sync': Flags.boolean({
78
- description: 'Synchronize the database before starting dev mode',
79
- required: false,
80
- }),
81
- port: Flags.string({
82
- description: 'Development server port',
83
- char: 'p',
84
- required: false,
85
- }),
86
- client: Flags.boolean({
87
- description: 'Run client dev mode only',
88
- char: 'c',
89
- required: false,
90
- }),
91
- server: Flags.boolean({
92
- description: 'Run server dev mode only',
93
- char: 's',
94
- required: false,
95
- }),
96
- inspect: Flags.string({
97
- description: 'Node.js inspect port for server debugging',
98
- char: 'i',
99
- required: false,
100
- }),
101
- };
102
- async run() {
103
- const { flags } = await this.parse(Dev);
104
- const requestedEnv = flags.env?.trim() || undefined;
105
- const runtime = await resolveManagedAppRuntime(requestedEnv);
106
- if (!runtime) {
107
- this.error(formatMissingManagedAppEnvMessage(requestedEnv));
108
- }
109
- if (runtime.kind === 'docker' || runtime.kind === 'http' || runtime.kind === 'ssh') {
110
- this.error(formatUnsupportedRuntimeMessage(runtime.kind, runtime.envName));
111
- }
112
- const devPort = flags.port
113
- || (runtime.env.appPort !== undefined && runtime.env.appPort !== null
114
- ? String(runtime.env.appPort).trim()
115
- : undefined);
116
- const appUrl = appUrlForPort(devPort);
117
- if (await isAppAlreadyRunning(appUrl)) {
118
- this.error([
119
- `NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`,
120
- flags.port
121
- ? `Choose another dev port with --port, or stop the running app with \`nb stop --env ${runtime.envName}\` first.`
122
- : `Run \`nb stop --env ${runtime.envName}\` before starting dev mode, or choose another dev port with --port.`,
123
- ].join('\n'));
124
- }
125
- const npmArgs = ['dev', '--rsbuild'];
126
- if (flags['db-sync']) {
127
- npmArgs.push('--db-sync');
128
- }
129
- if (devPort) {
130
- npmArgs.push('--port', devPort);
131
- }
132
- if (flags.client) {
133
- npmArgs.push('--client');
134
- }
135
- if (flags.server) {
136
- npmArgs.push('--server');
137
- }
138
- if (flags.inspect) {
139
- npmArgs.push('--inspect', flags.inspect);
140
- }
141
- printInfo(`Starting NocoBase dev mode for "${runtime.envName}" from ${runtime.projectRoot}. Press Ctrl+C to stop.`);
142
- try {
143
- await runLocalNocoBaseCommand(runtime, npmArgs, {
144
- stdio: 'inherit',
145
- });
146
- }
147
- catch (error) {
148
- const message = error instanceof Error ? error.message : String(error);
149
- this.error([
150
- `Couldn't start dev mode for "${runtime.envName}".`,
151
- 'Check that dependencies are installed and the saved env settings are valid, then try again.',
152
- `Details: ${message}`,
153
- ].join('\n'));
154
- }
155
- }
9
+ import SourceDev from './source/dev.js';
10
+ export default class Dev extends SourceDev {
11
+ static hidden = true;
156
12
  }
@@ -6,192 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Command, Flags } from '@oclif/core';
10
- import fsp from 'node:fs/promises';
11
- import os from 'node:os';
12
- import path from 'node:path';
13
- import { buildDockerDbContainerName, formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runLocalNocoBaseCommand, } from '../lib/app-runtime.js';
14
- import { removeEnv } from '../lib/auth-store.js';
15
- import { resolveConfiguredEnvPath } from '../lib/cli-home.js';
16
- import { commandSucceeds, run } from '../lib/run-npm.js';
17
- import { confirmAction, failTask, isInteractiveTerminal, printInfo, startTask, succeedTask, } from '../lib/ui.js';
18
- function resolveConfiguredPath(value) {
19
- return resolveConfiguredEnvPath(value);
20
- }
21
- function assertSafeRemovalPath(target, label) {
22
- const resolved = path.resolve(target);
23
- const cwd = path.resolve(process.cwd());
24
- const home = path.resolve(os.homedir());
25
- const root = path.parse(resolved).root;
26
- if (resolved === root || resolved === cwd || resolved === home) {
27
- throw new Error(`Refusing to remove ${label} at "${resolved}" because it is too broad.`);
28
- }
29
- }
30
- async function removePathIfExists(target, label) {
31
- const resolved = path.resolve(target);
32
- assertSafeRemovalPath(resolved, label);
33
- await fsp.rm(resolved, { recursive: true, force: true });
34
- }
35
- async function dockerContainerExists(containerName) {
36
- return await commandSucceeds('docker', ['container', 'inspect', containerName]);
37
- }
38
- async function removeDockerContainerIfExists(containerName) {
39
- if (!(await dockerContainerExists(containerName))) {
40
- return 'missing';
41
- }
42
- await run('docker', ['rm', '-f', containerName], {
43
- errorName: 'docker rm',
44
- stdio: 'ignore',
45
- });
46
- return 'removed';
47
- }
48
- function builtinDbContainerName(runtime) {
49
- if (!runtime.env.config.builtinDb) {
50
- return undefined;
51
- }
52
- const dbDialect = String(runtime.env.config.dbDialect ?? 'postgres').trim() || 'postgres';
53
- const workspaceName = runtime.workspaceName;
54
- return buildDockerDbContainerName(runtime.envName, dbDialect, workspaceName);
55
- }
56
- async function confirmRemoveData(envName, yes) {
57
- if (yes) {
58
- return true;
59
- }
60
- if (!isInteractiveTerminal()) {
61
- throw new Error(`Refusing to remove user data for "${envName}" without confirmation. Re-run with --yes only if you are sure.`);
62
- }
63
- return await confirmAction(`Delete storage and managed database data for "${envName}"? This cannot be undone.`, { defaultValue: false });
64
- }
65
- function formatDownFailure(envName, message) {
66
- return [
67
- `Couldn't bring down NocoBase for "${envName}".`,
68
- 'Some local runtime resources may still exist. Check Docker or the local app process, then try again.',
69
- `Details: ${message}`,
70
- ].join('\n');
71
- }
72
- export default class Down extends Command {
73
- static description = 'Stop NocoBase and remove local runtime containers for the selected env. Data, source files, and env config are kept unless explicitly requested.';
74
- static examples = [
75
- '<%= config.bin %> <%= command.id %> --env app1',
76
- '<%= config.bin %> <%= command.id %> --env app1 --remove-data',
77
- '<%= config.bin %> <%= command.id %> --env app1 --remove-source --remove-env',
78
- ];
79
- static flags = {
80
- env: Flags.string({
81
- char: 'e',
82
- description: 'CLI env name to bring down. Defaults to the current env when omitted',
83
- }),
84
- 'remove-data': Flags.boolean({
85
- description: 'Delete storage and managed database data after confirmation',
86
- default: false,
87
- }),
88
- 'remove-source': Flags.boolean({
89
- description: 'Delete the npm/git source directory for local installs',
90
- default: false,
91
- }),
92
- 'remove-env': Flags.boolean({
93
- description: 'Remove the CLI env config after local resources are removed',
94
- default: false,
95
- }),
96
- yes: Flags.boolean({
97
- char: 'y',
98
- description: 'Confirm destructive actions without prompting',
99
- default: false,
100
- }),
101
- verbose: Flags.boolean({
102
- description: 'Show raw output from shutdown commands',
103
- default: false,
104
- }),
105
- };
106
- async run() {
107
- const { flags } = await this.parse(Down);
108
- const requestedEnv = flags.env?.trim() || undefined;
109
- const runtime = await resolveManagedAppRuntime(requestedEnv);
110
- if (!runtime) {
111
- this.error(formatMissingManagedAppEnvMessage(requestedEnv));
112
- }
113
- if (runtime.kind === 'http') {
114
- this.error([
115
- `Can't bring down "${runtime.envName}" from this machine.`,
116
- 'This env only has an API connection, so there is no saved local app, Docker app, or managed database to remove here.',
117
- 'Use `nb env remove` if you only want to remove the CLI connection config.',
118
- ].join('\n'));
119
- }
120
- if (runtime.kind === 'ssh') {
121
- this.error([
122
- `Can't bring down "${runtime.envName}" yet.`,
123
- 'SSH env support is reserved but not implemented yet.',
124
- 'Use `nb env remove` if you only want to remove the saved CLI config for now.',
125
- ].join('\n'));
126
- }
127
- if (flags['remove-data']) {
128
- let confirmed = false;
129
- try {
130
- confirmed = await confirmRemoveData(runtime.envName, flags.yes);
131
- }
132
- catch (error) {
133
- this.error(error instanceof Error ? error.message : String(error));
134
- }
135
- if (!confirmed) {
136
- this.log('Canceled.');
137
- return;
138
- }
139
- }
140
- try {
141
- if (runtime.kind === 'docker') {
142
- startTask(`Removing Docker app container for "${runtime.envName}"...`);
143
- const state = await removeDockerContainerIfExists(runtime.containerName);
144
- succeedTask(state === 'removed'
145
- ? `Docker app container removed for "${runtime.envName}".`
146
- : `No Docker app container found for "${runtime.envName}".`);
147
- }
148
- else {
149
- startTask(`Stopping local NocoBase app for "${runtime.envName}"...`);
150
- await runLocalNocoBaseCommand(runtime, ['pm2', 'kill'], {
151
- stdio: flags.verbose ? 'inherit' : 'ignore',
152
- });
153
- succeedTask(`Local NocoBase app stopped for "${runtime.envName}".`);
154
- }
155
- const dbContainerName = builtinDbContainerName(runtime);
156
- if (dbContainerName) {
157
- startTask(`Removing built-in database container for "${runtime.envName}"...`);
158
- const state = await removeDockerContainerIfExists(dbContainerName);
159
- succeedTask(state === 'removed'
160
- ? `Built-in database container removed for "${runtime.envName}".`
161
- : `No built-in database container found for "${runtime.envName}".`);
162
- }
163
- if (flags['remove-data']) {
164
- const storagePath = resolveConfiguredPath(runtime.env.config.storagePath);
165
- if (storagePath) {
166
- startTask(`Deleting storage and managed database data for "${runtime.envName}"...`);
167
- await removePathIfExists(storagePath, 'storage data');
168
- succeedTask(`Storage and managed database data deleted for "${runtime.envName}".`);
169
- }
170
- else {
171
- printInfo(`No storage path is configured for "${runtime.envName}".`);
172
- }
173
- }
174
- if (flags['remove-source']) {
175
- if (runtime.kind === 'local') {
176
- startTask(`Deleting source files for "${runtime.envName}"...`);
177
- await removePathIfExists(runtime.projectRoot, 'source files');
178
- succeedTask(`Source files deleted for "${runtime.envName}".`);
179
- }
180
- else {
181
- printInfo(`No npm/git source directory is configured for "${runtime.envName}".`);
182
- }
183
- }
184
- if (flags['remove-env']) {
185
- startTask(`Removing CLI env config for "${runtime.envName}"...`);
186
- await removeEnv(runtime.envName);
187
- succeedTask(`CLI env config removed for "${runtime.envName}".`);
188
- }
189
- printInfo(`NocoBase is down for "${runtime.envName}".`);
190
- }
191
- catch (error) {
192
- const message = error instanceof Error ? error.message : String(error);
193
- failTask(`Failed to bring down NocoBase for "${runtime.envName}".`);
194
- this.error(formatDownFailure(runtime.envName, message));
195
- }
196
- }
9
+ import AppDown from './app/down.js';
10
+ export default class Down extends AppDown {
11
+ static hidden = true;
197
12
  }