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

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 (145) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +367 -19
  3. package/README.zh-CN.md +336 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +131 -0
  6. package/dist/commands/api/resource/create.js +15 -0
  7. package/dist/commands/api/resource/destroy.js +15 -0
  8. package/dist/commands/api/resource/get.js +15 -0
  9. package/dist/commands/api/resource/index.js +20 -0
  10. package/dist/commands/api/resource/list.js +16 -0
  11. package/dist/commands/api/resource/query.js +15 -0
  12. package/dist/commands/api/resource/update.js +15 -0
  13. package/dist/commands/build.js +57 -0
  14. package/dist/commands/db/logs.js +85 -0
  15. package/dist/commands/db/ps.js +60 -0
  16. package/dist/commands/db/shared.js +95 -0
  17. package/dist/commands/db/start.js +70 -0
  18. package/dist/commands/db/stop.js +70 -0
  19. package/dist/commands/dev.js +156 -0
  20. package/dist/commands/down.js +197 -0
  21. package/dist/commands/download.js +865 -0
  22. package/dist/commands/env/add.js +307 -0
  23. package/dist/commands/env/auth.js +55 -0
  24. package/dist/commands/env/list.js +36 -0
  25. package/dist/commands/env/remove.js +59 -0
  26. package/dist/commands/env/update.js +67 -0
  27. package/dist/commands/env/use.js +28 -0
  28. package/dist/commands/init.js +950 -0
  29. package/dist/commands/install.js +1927 -0
  30. package/dist/commands/logs.js +97 -0
  31. package/dist/commands/pm/disable.js +63 -0
  32. package/dist/commands/pm/enable.js +63 -0
  33. package/dist/commands/pm/list.js +61 -0
  34. package/dist/commands/prompts-stages.js +150 -0
  35. package/dist/commands/prompts-test.js +181 -0
  36. package/dist/commands/ps.js +119 -0
  37. package/dist/commands/restart.js +74 -0
  38. package/dist/commands/scaffold/migration.js +38 -0
  39. package/dist/commands/scaffold/plugin.js +37 -0
  40. package/dist/commands/self/check.js +71 -0
  41. package/dist/commands/self/index.js +20 -0
  42. package/dist/commands/self/update.js +86 -0
  43. package/dist/commands/skills/check.js +69 -0
  44. package/dist/commands/skills/index.js +20 -0
  45. package/dist/commands/skills/install.js +71 -0
  46. package/dist/commands/skills/update.js +71 -0
  47. package/dist/commands/start.js +218 -0
  48. package/dist/commands/stop.js +97 -0
  49. package/dist/commands/test.js +466 -0
  50. package/dist/commands/upgrade.js +594 -0
  51. package/dist/generated/command-registry.js +133 -0
  52. package/dist/help/runtime-help.js +20 -0
  53. package/dist/lib/api-client.js +244 -0
  54. package/dist/lib/app-runtime.js +153 -0
  55. package/dist/lib/auth-store.js +357 -0
  56. package/dist/lib/bootstrap.js +388 -0
  57. package/dist/lib/build-config.js +10 -0
  58. package/dist/lib/cli-home.js +61 -0
  59. package/dist/lib/cli-locale.js +115 -0
  60. package/dist/lib/command-discovery.js +39 -0
  61. package/dist/lib/env-auth.js +872 -0
  62. package/dist/lib/generated-command.js +150 -0
  63. package/dist/lib/http-request.js +49 -0
  64. package/dist/lib/naming.js +70 -0
  65. package/dist/lib/openapi.js +62 -0
  66. package/dist/lib/post-processors.js +23 -0
  67. package/dist/lib/prompt-catalog.js +581 -0
  68. package/dist/lib/prompt-validators.js +185 -0
  69. package/dist/lib/prompt-web-ui.js +2096 -0
  70. package/dist/lib/resource-command.js +343 -0
  71. package/dist/lib/resource-request.js +104 -0
  72. package/dist/lib/run-npm.js +197 -0
  73. package/dist/lib/runtime-generator.js +419 -0
  74. package/dist/lib/runtime-store.js +56 -0
  75. package/dist/lib/self-manager.js +246 -0
  76. package/dist/lib/skills-manager.js +269 -0
  77. package/dist/lib/startup-update.js +203 -0
  78. package/dist/lib/ui.js +175 -0
  79. package/dist/locale/en-US.json +336 -0
  80. package/dist/locale/zh-CN.json +336 -0
  81. package/dist/post-processors/data-modeling.js +66 -0
  82. package/dist/post-processors/data-source-manager.js +114 -0
  83. package/dist/post-processors/index.js +19 -0
  84. package/nocobase-ctl.config.json +287 -0
  85. package/package.json +60 -26
  86. package/LICENSE +0 -661
  87. package/bin/index.js +0 -39
  88. package/nocobase.conf.tpl +0 -95
  89. package/src/cli.js +0 -19
  90. package/src/commands/benchmark.js +0 -73
  91. package/src/commands/build.js +0 -49
  92. package/src/commands/clean.js +0 -30
  93. package/src/commands/client.js +0 -166
  94. package/src/commands/create-nginx-conf.js +0 -37
  95. package/src/commands/create-plugin.js +0 -33
  96. package/src/commands/dev.js +0 -200
  97. package/src/commands/doc.js +0 -76
  98. package/src/commands/e2e.js +0 -265
  99. package/src/commands/global.js +0 -43
  100. package/src/commands/index.js +0 -45
  101. package/src/commands/instance-id.js +0 -47
  102. package/src/commands/locale/cronstrue.js +0 -122
  103. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  104. package/src/commands/locale/react-js-cron/index.js +0 -17
  105. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  106. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  107. package/src/commands/locale.js +0 -81
  108. package/src/commands/p-test.js +0 -88
  109. package/src/commands/perf.js +0 -63
  110. package/src/commands/pkg.js +0 -321
  111. package/src/commands/pm2.js +0 -37
  112. package/src/commands/postinstall.js +0 -88
  113. package/src/commands/start.js +0 -148
  114. package/src/commands/tar.js +0 -36
  115. package/src/commands/test-coverage.js +0 -55
  116. package/src/commands/test.js +0 -107
  117. package/src/commands/umi.js +0 -33
  118. package/src/commands/update-deps.js +0 -72
  119. package/src/commands/upgrade.js +0 -47
  120. package/src/commands/view-license-key.js +0 -44
  121. package/src/index.js +0 -14
  122. package/src/license.js +0 -76
  123. package/src/logger.js +0 -75
  124. package/src/plugin-generator.js +0 -80
  125. package/src/util.js +0 -517
  126. package/templates/bundle-status.html +0 -338
  127. package/templates/create-app-package.json +0 -39
  128. package/templates/plugin/.npmignore.tpl +0 -2
  129. package/templates/plugin/README.md.tpl +0 -1
  130. package/templates/plugin/client.d.ts +0 -2
  131. package/templates/plugin/client.js +0 -1
  132. package/templates/plugin/package.json.tpl +0 -11
  133. package/templates/plugin/server.d.ts +0 -2
  134. package/templates/plugin/server.js +0 -1
  135. package/templates/plugin/src/client/client.d.ts +0 -249
  136. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  137. package/templates/plugin/src/client/locale.ts +0 -21
  138. package/templates/plugin/src/client/models/index.ts +0 -12
  139. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  140. package/templates/plugin/src/index.ts +0 -2
  141. package/templates/plugin/src/locale/en-US.json +0 -1
  142. package/templates/plugin/src/locale/zh-CN.json +0 -1
  143. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  144. package/templates/plugin/src/server/index.ts.tpl +0 -1
  145. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -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
+ import { Command, Flags } from '@oclif/core';
10
+ import { confirmAction, setVerboseMode } from '../../lib/ui.js';
11
+ import { updateNocoBaseSkills } from '../../lib/skills-manager.js';
12
+ export default class SkillsUpdate extends Command {
13
+ static summary = 'Update the globally installed NocoBase AI coding skills';
14
+ static description = 'Refresh the globally installed NocoBase AI coding skills. This command only updates an existing @nocobase/skills install.';
15
+ static examples = [
16
+ '<%= config.bin %> <%= command.id %>',
17
+ '<%= config.bin %> <%= command.id %> --yes',
18
+ '<%= config.bin %> <%= command.id %> --json',
19
+ ];
20
+ static flags = {
21
+ yes: Flags.boolean({
22
+ char: 'y',
23
+ description: 'Skip the update confirmation prompt',
24
+ default: false,
25
+ }),
26
+ json: Flags.boolean({
27
+ description: 'Output the result as JSON',
28
+ default: false,
29
+ }),
30
+ verbose: Flags.boolean({
31
+ description: 'Show detailed update output',
32
+ default: false,
33
+ }),
34
+ };
35
+ async run() {
36
+ const { flags } = await this.parse(SkillsUpdate);
37
+ setVerboseMode(flags.verbose);
38
+ if (!flags.yes) {
39
+ const confirmed = await confirmAction('Update the globally installed NocoBase AI coding skills?', { defaultValue: true });
40
+ if (!confirmed) {
41
+ this.log('Skipped skills update.');
42
+ return;
43
+ }
44
+ }
45
+ const result = await updateNocoBaseSkills({
46
+ verbose: flags.verbose,
47
+ });
48
+ if (flags.json) {
49
+ this.log(JSON.stringify({
50
+ ok: true,
51
+ kind: 'skills',
52
+ action: result.action,
53
+ globalRoot: result.status.globalRoot,
54
+ workspaceRoot: result.status.workspaceRoot,
55
+ installedSkillNames: result.status.installedSkillNames,
56
+ installedVersion: result.status.installedVersion,
57
+ installedRef: result.status.installedRef,
58
+ }, null, 2));
59
+ return;
60
+ }
61
+ if (result.action === 'noop') {
62
+ this.log(flags.verbose
63
+ ? 'NocoBase AI coding skills are already up to date globally.'
64
+ : 'NocoBase AI coding skills are up to date.');
65
+ return;
66
+ }
67
+ this.log(flags.verbose
68
+ ? 'Updated the global NocoBase AI coding skills.'
69
+ : 'Updated NocoBase AI coding skills globally.');
70
+ }
71
+ }
@@ -0,0 +1,218 @@
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 { Command, Flags } from '@oclif/core';
10
+ import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runLocalNocoBaseCommand, startDockerContainer, } from '../lib/app-runtime.js';
11
+ import { failTask, printInfo, startTask, succeedTask } from '../lib/ui.js';
12
+ function argvHasToken(argv, tokens) {
13
+ return tokens.some((token) => argv.includes(token));
14
+ }
15
+ function formatDockerStartFailure(envName, message) {
16
+ if (/does not exist/i.test(message)) {
17
+ return [
18
+ `Can't start NocoBase for "${envName}" yet.`,
19
+ 'The saved Docker app for this env could not be found on this machine.',
20
+ `Try reinstalling the env, or check whether the container was removed outside the CLI.`,
21
+ `Details: ${message}`,
22
+ ].join('\n');
23
+ }
24
+ return [
25
+ `Couldn't start NocoBase for "${envName}".`,
26
+ 'Check that the Docker runtime for this env is still available, then try again.',
27
+ `Details: ${message}`,
28
+ ].join('\n');
29
+ }
30
+ function formatLocalStartFailure(envName, options) {
31
+ const sourceLabel = options?.source === 'git'
32
+ ? 'the local Git checkout'
33
+ : options?.source === 'npm'
34
+ ? 'the local npm app'
35
+ : 'the local app';
36
+ const portHint = options?.port ? ` Expected app port: ${options.port}.` : '';
37
+ return [
38
+ `Couldn't start NocoBase for "${envName}".`,
39
+ `The CLI was not able to start ${sourceLabel} successfully.`,
40
+ `Check that the app dependencies, database connection, and local env settings are ready, then try again.${portHint}`,
41
+ ].join('\n');
42
+ }
43
+ function formatAppUrl(port) {
44
+ const value = String(port ?? '').trim();
45
+ if (!value) {
46
+ return undefined;
47
+ }
48
+ return `http://127.0.0.1:${value}`;
49
+ }
50
+ async function isAppAlreadyRunning(appUrl) {
51
+ if (!appUrl) {
52
+ return false;
53
+ }
54
+ const controller = new AbortController();
55
+ const timeout = setTimeout(() => controller.abort(), 1500);
56
+ try {
57
+ const response = await fetch(`${appUrl}/api/__health_check`, {
58
+ signal: controller.signal,
59
+ });
60
+ const text = await response.text();
61
+ return response.ok && text.trim().toLowerCase() === 'ok';
62
+ }
63
+ catch (_error) {
64
+ return false;
65
+ }
66
+ finally {
67
+ clearTimeout(timeout);
68
+ }
69
+ }
70
+ export default class Start extends Command {
71
+ static description = 'Start NocoBase for the selected env. Local npm/git installs run the app command, and Docker installs start the saved app container.';
72
+ static examples = [
73
+ '<%= config.bin %> <%= command.id %>',
74
+ '<%= config.bin %> <%= command.id %> --env local',
75
+ '<%= config.bin %> <%= command.id %> --env local --quickstart',
76
+ '<%= config.bin %> <%= command.id %> --env local --port 12000',
77
+ '<%= config.bin %> <%= command.id %> --env local --daemon',
78
+ '<%= config.bin %> <%= command.id %> --env local --no-daemon',
79
+ '<%= config.bin %> <%= command.id %> --env local --instances 2',
80
+ '<%= config.bin %> <%= command.id %> --env local --launch-mode pm2',
81
+ '<%= config.bin %> <%= command.id %> --env local --verbose',
82
+ '<%= config.bin %> <%= command.id %> --env local-docker',
83
+ ];
84
+ static flags = {
85
+ env: Flags.string({
86
+ char: 'e',
87
+ description: 'CLI env name to start. Defaults to the current env when omitted',
88
+ }),
89
+ quickstart: Flags.boolean({ description: 'Quickstart the application', required: false }),
90
+ port: Flags.string({ description: 'Port (overrides appPort from env config when set)', char: 'p', required: false }),
91
+ daemon: Flags.boolean({
92
+ description: 'Run the application as a daemon (default: true; use --no-daemon to stay in the foreground)',
93
+ char: 'd',
94
+ required: false,
95
+ default: true,
96
+ allowNo: true,
97
+ }),
98
+ instances: Flags.integer({ description: 'Number of instances to run', char: 'i', required: false }),
99
+ 'launch-mode': Flags.string({ description: 'Launch Mode', required: false, options: ['pm2', 'node'] }),
100
+ verbose: Flags.boolean({
101
+ description: 'Show raw startup output from the underlying local or Docker command',
102
+ default: false,
103
+ }),
104
+ };
105
+ async run() {
106
+ const { flags } = await this.parse(Start);
107
+ const requestedEnv = flags.env?.trim() || undefined;
108
+ const daemonFlagWasProvided = argvHasToken(this.argv, ['--daemon', '--no-daemon']);
109
+ const runtime = await resolveManagedAppRuntime(requestedEnv);
110
+ const commandStdio = flags.verbose ? 'inherit' : 'ignore';
111
+ if (!runtime) {
112
+ this.error(formatMissingManagedAppEnvMessage(requestedEnv));
113
+ }
114
+ if (runtime.kind === 'http') {
115
+ this.error([
116
+ `Can't start "${runtime.envName}" from this machine.`,
117
+ 'This env only has an API connection, so there is no saved local app or Docker runtime to launch here.',
118
+ 'Connect it to a local checkout or reinstall it with npm, git, or Docker if you want CLI-managed start and stop.',
119
+ ].join('\n'));
120
+ }
121
+ if (runtime.kind === 'ssh') {
122
+ this.error([
123
+ `Can't start "${runtime.envName}" yet.`,
124
+ 'SSH env support is reserved but not implemented yet.',
125
+ 'Use a local or Docker env if you need CLI-managed start and stop right now.',
126
+ ].join('\n'));
127
+ }
128
+ if (runtime.kind === 'docker') {
129
+ const unsupportedFlags = [
130
+ flags.quickstart ? '--quickstart' : undefined,
131
+ flags.port ? '--port' : undefined,
132
+ daemonFlagWasProvided ? (flags.daemon ? '--daemon' : '--no-daemon') : undefined,
133
+ flags.instances !== undefined ? '--instances' : undefined,
134
+ flags['launch-mode'] ? '--launch-mode' : undefined,
135
+ ].filter(Boolean);
136
+ if (unsupportedFlags.length > 0) {
137
+ this.error([
138
+ `Can't apply ${unsupportedFlags.join(', ')} to "${runtime.envName}".`,
139
+ 'This env is managed by Docker, so those options are only available for local npm/git installs.',
140
+ `Run \`nb start --env ${runtime.envName}\` to start the saved container, or recreate the env if you need different runtime settings.`,
141
+ ].join('\n'));
142
+ }
143
+ const appUrl = formatAppUrl(runtime.env.appPort === undefined || runtime.env.appPort === null
144
+ ? undefined
145
+ : String(runtime.env.appPort));
146
+ startTask(`Starting NocoBase for "${runtime.envName}"...`);
147
+ try {
148
+ const state = await startDockerContainer(runtime.containerName, {
149
+ stdio: commandStdio,
150
+ });
151
+ succeedTask(state === 'already-running'
152
+ ? `NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`
153
+ : `NocoBase is running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`);
154
+ }
155
+ catch (error) {
156
+ const message = error instanceof Error ? error.message : String(error);
157
+ failTask(`Failed to start NocoBase for "${runtime.envName}".`);
158
+ this.error(formatDockerStartFailure(runtime.envName, message));
159
+ }
160
+ return;
161
+ }
162
+ const npmArgs = ['start'];
163
+ if (flags.quickstart) {
164
+ npmArgs.push('--quickstart');
165
+ }
166
+ if (flags.port) {
167
+ npmArgs.push('--port', flags.port);
168
+ }
169
+ else if (runtime.env.appPort !== undefined && runtime.env.appPort !== null && String(runtime.env.appPort).trim() !== '') {
170
+ npmArgs.push('--port', String(runtime.env.appPort));
171
+ }
172
+ if (flags.daemon !== false) {
173
+ npmArgs.push('--daemon');
174
+ }
175
+ if (flags.instances !== undefined) {
176
+ npmArgs.push('--instances', flags.instances.toString());
177
+ }
178
+ if (flags['launch-mode']) {
179
+ npmArgs.push('--launch-mode', flags['launch-mode']);
180
+ }
181
+ const appUrl = formatAppUrl(flags.port
182
+ || (runtime.env.appPort !== undefined && runtime.env.appPort !== null
183
+ ? String(runtime.env.appPort).trim()
184
+ : undefined));
185
+ if (await isAppAlreadyRunning(appUrl)) {
186
+ if (flags.daemon === false) {
187
+ printInfo(`NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}. Use \`nb stop --env ${runtime.envName}\` before starting it again in the foreground.`);
188
+ }
189
+ else {
190
+ succeedTask(`NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`);
191
+ }
192
+ return;
193
+ }
194
+ if (flags.daemon === false) {
195
+ printInfo(`Starting NocoBase for "${runtime.envName}" in the foreground${appUrl ? ` at ${appUrl}` : ''}. Press Ctrl+C to stop.`);
196
+ }
197
+ else {
198
+ startTask(`Starting NocoBase for "${runtime.envName}" in the background...`);
199
+ }
200
+ try {
201
+ await runLocalNocoBaseCommand(runtime, npmArgs, {
202
+ stdio: commandStdio,
203
+ });
204
+ if (flags.daemon !== false) {
205
+ succeedTask(`NocoBase is starting for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`);
206
+ }
207
+ }
208
+ catch (error) {
209
+ failTask(`Failed to start NocoBase for "${runtime.envName}".`);
210
+ this.error(formatLocalStartFailure(runtime.envName, {
211
+ port: flags.port || (runtime.env.appPort !== undefined && runtime.env.appPort !== null
212
+ ? String(runtime.env.appPort).trim()
213
+ : undefined),
214
+ source: runtime.source,
215
+ }));
216
+ }
217
+ }
218
+ }
@@ -0,0 +1,97 @@
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 { Command, Flags } from '@oclif/core';
10
+ import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runLocalNocoBaseCommand, stopDockerContainer, } from '../lib/app-runtime.js';
11
+ import { failTask, startTask, succeedTask } from '../lib/ui.js';
12
+ function formatStopFailure(envName, message) {
13
+ if (/does not exist/i.test(message)) {
14
+ return [
15
+ `Can't stop NocoBase for "${envName}" yet.`,
16
+ 'The saved Docker app for this env could not be found on this machine.',
17
+ 'If it was removed manually, reinstall or reconnect the env before trying again.',
18
+ `Details: ${message}`,
19
+ ].join('\n');
20
+ }
21
+ return [
22
+ `Couldn't stop NocoBase for "${envName}".`,
23
+ 'Check that the local app or Docker runtime is still available, then try again.',
24
+ `Details: ${message}`,
25
+ ].join('\n');
26
+ }
27
+ export default class Stop extends Command {
28
+ static description = 'Stop NocoBase for the selected env. Local npm/git installs stop the app process, and Docker installs stop the saved app container.';
29
+ static examples = [
30
+ '<%= config.bin %> <%= command.id %>',
31
+ '<%= config.bin %> <%= command.id %> --env local',
32
+ '<%= config.bin %> <%= command.id %> --env local --verbose',
33
+ '<%= config.bin %> <%= command.id %> --env local-docker',
34
+ ];
35
+ static flags = {
36
+ env: Flags.string({
37
+ char: 'e',
38
+ description: 'CLI env name to stop. Defaults to the current env when omitted',
39
+ }),
40
+ verbose: Flags.boolean({
41
+ description: 'Show raw shutdown output from the underlying local or Docker command',
42
+ default: false,
43
+ }),
44
+ };
45
+ async run() {
46
+ const { flags } = await this.parse(Stop);
47
+ const requestedEnv = flags.env?.trim() || undefined;
48
+ const runtime = await resolveManagedAppRuntime(requestedEnv);
49
+ const commandStdio = flags.verbose ? 'inherit' : 'ignore';
50
+ if (!runtime) {
51
+ this.error(formatMissingManagedAppEnvMessage(requestedEnv));
52
+ }
53
+ if (runtime.kind === 'http') {
54
+ this.error([
55
+ `Can't stop "${runtime.envName}" from this machine.`,
56
+ 'This env only has an API connection, so there is no saved local app or Docker runtime to stop here.',
57
+ 'If the app is running on a server, stop it there or reconnect this env to a local runtime first.',
58
+ ].join('\n'));
59
+ }
60
+ if (runtime.kind === 'ssh') {
61
+ this.error([
62
+ `Can't stop "${runtime.envName}" yet.`,
63
+ 'SSH env support is reserved but not implemented yet.',
64
+ 'Use a local or Docker env if you need CLI-managed stop right now.',
65
+ ].join('\n'));
66
+ }
67
+ if (runtime.kind === 'docker') {
68
+ startTask(`Stopping NocoBase for "${runtime.envName}"...`);
69
+ try {
70
+ const state = await stopDockerContainer(runtime.containerName, {
71
+ stdio: commandStdio,
72
+ });
73
+ succeedTask(state === 'already-stopped'
74
+ ? `NocoBase is already stopped for "${runtime.envName}".`
75
+ : `NocoBase has stopped for "${runtime.envName}".`);
76
+ }
77
+ catch (error) {
78
+ const message = error instanceof Error ? error.message : String(error);
79
+ failTask(`Failed to stop NocoBase for "${runtime.envName}".`);
80
+ this.error(formatStopFailure(runtime.envName, message));
81
+ }
82
+ return;
83
+ }
84
+ startTask(`Stopping NocoBase for "${runtime.envName}"...`);
85
+ try {
86
+ await runLocalNocoBaseCommand(runtime, ['pm2', 'kill'], {
87
+ stdio: commandStdio,
88
+ });
89
+ succeedTask(`NocoBase has stopped for "${runtime.envName}".`);
90
+ }
91
+ catch (error) {
92
+ const message = error instanceof Error ? error.message : String(error);
93
+ failTask(`Failed to stop NocoBase for "${runtime.envName}".`);
94
+ this.error(formatStopFailure(runtime.envName, message));
95
+ }
96
+ }
97
+ }