@nocobase/cli 2.1.0-beta.2 → 2.1.0-beta.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.
Files changed (143) 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 +116 -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 +81 -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 +149 -0
  20. package/dist/commands/down.js +193 -0
  21. package/dist/commands/download.js +865 -0
  22. package/dist/commands/env/add.js +327 -0
  23. package/dist/commands/env/auth.js +62 -0
  24. package/dist/commands/env/list.js +41 -0
  25. package/dist/commands/env/remove.js +65 -0
  26. package/dist/commands/env/update.js +73 -0
  27. package/dist/commands/env/use.js +36 -0
  28. package/dist/commands/init.js +822 -0
  29. package/dist/commands/install.js +1888 -0
  30. package/dist/commands/logs.js +90 -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 +54 -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 +116 -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 +76 -0
  43. package/dist/commands/skills/check.js +63 -0
  44. package/dist/commands/skills/index.js +20 -0
  45. package/dist/commands/skills/install.js +58 -0
  46. package/dist/commands/skills/update.js +58 -0
  47. package/dist/commands/start.js +211 -0
  48. package/dist/commands/stop.js +90 -0
  49. package/dist/commands/test.js +466 -0
  50. package/dist/commands/upgrade.js +583 -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 +243 -0
  54. package/dist/lib/app-runtime.js +142 -0
  55. package/dist/lib/auth-store.js +241 -0
  56. package/dist/lib/bootstrap.js +387 -0
  57. package/dist/lib/build-config.js +10 -0
  58. package/dist/lib/cli-home.js +30 -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 +142 -0
  63. package/dist/lib/naming.js +70 -0
  64. package/dist/lib/openapi.js +62 -0
  65. package/dist/lib/post-processors.js +23 -0
  66. package/dist/lib/prompt-catalog.js +581 -0
  67. package/dist/lib/prompt-validators.js +185 -0
  68. package/dist/lib/prompt-web-ui.js +2096 -0
  69. package/dist/lib/resource-command.js +335 -0
  70. package/dist/lib/resource-request.js +104 -0
  71. package/dist/lib/run-npm.js +197 -0
  72. package/dist/lib/runtime-generator.js +419 -0
  73. package/dist/lib/runtime-store.js +56 -0
  74. package/dist/lib/self-manager.js +246 -0
  75. package/dist/lib/skills-manager.js +202 -0
  76. package/dist/lib/ui.js +175 -0
  77. package/dist/locale/en-US.json +333 -0
  78. package/dist/locale/zh-CN.json +333 -0
  79. package/dist/post-processors/data-modeling.js +66 -0
  80. package/dist/post-processors/data-source-manager.js +114 -0
  81. package/dist/post-processors/index.js +19 -0
  82. package/nocobase-ctl.config.json +287 -0
  83. package/package.json +60 -26
  84. package/LICENSE +0 -661
  85. package/bin/index.js +0 -39
  86. package/nocobase.conf.tpl +0 -95
  87. package/src/cli.js +0 -19
  88. package/src/commands/benchmark.js +0 -73
  89. package/src/commands/build.js +0 -49
  90. package/src/commands/clean.js +0 -30
  91. package/src/commands/client.js +0 -166
  92. package/src/commands/create-nginx-conf.js +0 -37
  93. package/src/commands/create-plugin.js +0 -33
  94. package/src/commands/dev.js +0 -200
  95. package/src/commands/doc.js +0 -76
  96. package/src/commands/e2e.js +0 -265
  97. package/src/commands/global.js +0 -43
  98. package/src/commands/index.js +0 -45
  99. package/src/commands/instance-id.js +0 -47
  100. package/src/commands/locale/cronstrue.js +0 -122
  101. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  102. package/src/commands/locale/react-js-cron/index.js +0 -17
  103. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  104. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  105. package/src/commands/locale.js +0 -81
  106. package/src/commands/p-test.js +0 -88
  107. package/src/commands/perf.js +0 -63
  108. package/src/commands/pkg.js +0 -321
  109. package/src/commands/pm2.js +0 -37
  110. package/src/commands/postinstall.js +0 -88
  111. package/src/commands/start.js +0 -148
  112. package/src/commands/tar.js +0 -36
  113. package/src/commands/test-coverage.js +0 -55
  114. package/src/commands/test.js +0 -107
  115. package/src/commands/umi.js +0 -33
  116. package/src/commands/update-deps.js +0 -72
  117. package/src/commands/upgrade.js +0 -47
  118. package/src/commands/view-license-key.js +0 -44
  119. package/src/index.js +0 -14
  120. package/src/license.js +0 -76
  121. package/src/logger.js +0 -75
  122. package/src/plugin-generator.js +0 -80
  123. package/src/util.js +0 -517
  124. package/templates/bundle-status.html +0 -338
  125. package/templates/create-app-package.json +0 -39
  126. package/templates/plugin/.npmignore.tpl +0 -2
  127. package/templates/plugin/README.md.tpl +0 -1
  128. package/templates/plugin/client.d.ts +0 -2
  129. package/templates/plugin/client.js +0 -1
  130. package/templates/plugin/package.json.tpl +0 -11
  131. package/templates/plugin/server.d.ts +0 -2
  132. package/templates/plugin/server.js +0 -1
  133. package/templates/plugin/src/client/client.d.ts +0 -249
  134. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  135. package/templates/plugin/src/client/locale.ts +0 -21
  136. package/templates/plugin/src/client/models/index.ts +0 -12
  137. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  138. package/templates/plugin/src/index.ts +0 -2
  139. package/templates/plugin/src/locale/en-US.json +0 -1
  140. package/templates/plugin/src/locale/zh-CN.json +0 -1
  141. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  142. package/templates/plugin/src/server/index.ts.tpl +0 -1
  143. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -0,0 +1,211 @@
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 === 'remote') {
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 === 'docker') {
122
+ const unsupportedFlags = [
123
+ flags.quickstart ? '--quickstart' : undefined,
124
+ flags.port ? '--port' : undefined,
125
+ daemonFlagWasProvided ? (flags.daemon ? '--daemon' : '--no-daemon') : undefined,
126
+ flags.instances !== undefined ? '--instances' : undefined,
127
+ flags['launch-mode'] ? '--launch-mode' : undefined,
128
+ ].filter(Boolean);
129
+ if (unsupportedFlags.length > 0) {
130
+ this.error([
131
+ `Can't apply ${unsupportedFlags.join(', ')} to "${runtime.envName}".`,
132
+ 'This env is managed by Docker, so those options are only available for local npm/git installs.',
133
+ `Run \`nb start --env ${runtime.envName}\` to start the saved container, or recreate the env if you need different runtime settings.`,
134
+ ].join('\n'));
135
+ }
136
+ const appUrl = formatAppUrl(runtime.env.appPort === undefined || runtime.env.appPort === null
137
+ ? undefined
138
+ : String(runtime.env.appPort));
139
+ startTask(`Starting NocoBase for "${runtime.envName}"...`);
140
+ try {
141
+ const state = await startDockerContainer(runtime.containerName, {
142
+ stdio: commandStdio,
143
+ });
144
+ succeedTask(state === 'already-running'
145
+ ? `NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`
146
+ : `NocoBase is running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`);
147
+ }
148
+ catch (error) {
149
+ const message = error instanceof Error ? error.message : String(error);
150
+ failTask(`Failed to start NocoBase for "${runtime.envName}".`);
151
+ this.error(formatDockerStartFailure(runtime.envName, message));
152
+ }
153
+ return;
154
+ }
155
+ const npmArgs = ['start'];
156
+ if (flags.quickstart) {
157
+ npmArgs.push('--quickstart');
158
+ }
159
+ if (flags.port) {
160
+ npmArgs.push('--port', flags.port);
161
+ }
162
+ else if (runtime.env.appPort !== undefined && runtime.env.appPort !== null && String(runtime.env.appPort).trim() !== '') {
163
+ npmArgs.push('--port', String(runtime.env.appPort));
164
+ }
165
+ if (flags.daemon !== false) {
166
+ npmArgs.push('--daemon');
167
+ }
168
+ if (flags.instances !== undefined) {
169
+ npmArgs.push('--instances', flags.instances.toString());
170
+ }
171
+ if (flags['launch-mode']) {
172
+ npmArgs.push('--launch-mode', flags['launch-mode']);
173
+ }
174
+ const appUrl = formatAppUrl(flags.port
175
+ || (runtime.env.appPort !== undefined && runtime.env.appPort !== null
176
+ ? String(runtime.env.appPort).trim()
177
+ : undefined));
178
+ if (await isAppAlreadyRunning(appUrl)) {
179
+ if (flags.daemon === false) {
180
+ printInfo(`NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}. Use \`nb stop --env ${runtime.envName}\` before starting it again in the foreground.`);
181
+ }
182
+ else {
183
+ succeedTask(`NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`);
184
+ }
185
+ return;
186
+ }
187
+ if (flags.daemon === false) {
188
+ printInfo(`Starting NocoBase for "${runtime.envName}" in the foreground${appUrl ? ` at ${appUrl}` : ''}. Press Ctrl+C to stop.`);
189
+ }
190
+ else {
191
+ startTask(`Starting NocoBase for "${runtime.envName}" in the background...`);
192
+ }
193
+ try {
194
+ await runLocalNocoBaseCommand(runtime, npmArgs, {
195
+ stdio: commandStdio,
196
+ });
197
+ if (flags.daemon !== false) {
198
+ succeedTask(`NocoBase is starting for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`);
199
+ }
200
+ }
201
+ catch (error) {
202
+ failTask(`Failed to start NocoBase for "${runtime.envName}".`);
203
+ this.error(formatLocalStartFailure(runtime.envName, {
204
+ port: flags.port || (runtime.env.appPort !== undefined && runtime.env.appPort !== null
205
+ ? String(runtime.env.appPort).trim()
206
+ : undefined),
207
+ source: runtime.source,
208
+ }));
209
+ }
210
+ }
211
+ }
@@ -0,0 +1,90 @@
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 === 'remote') {
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 === 'docker') {
61
+ startTask(`Stopping NocoBase for "${runtime.envName}"...`);
62
+ try {
63
+ const state = await stopDockerContainer(runtime.containerName, {
64
+ stdio: commandStdio,
65
+ });
66
+ succeedTask(state === 'already-stopped'
67
+ ? `NocoBase is already stopped for "${runtime.envName}".`
68
+ : `NocoBase has stopped for "${runtime.envName}".`);
69
+ }
70
+ catch (error) {
71
+ const message = error instanceof Error ? error.message : String(error);
72
+ failTask(`Failed to stop NocoBase for "${runtime.envName}".`);
73
+ this.error(formatStopFailure(runtime.envName, message));
74
+ }
75
+ return;
76
+ }
77
+ startTask(`Stopping NocoBase for "${runtime.envName}"...`);
78
+ try {
79
+ await runLocalNocoBaseCommand(runtime, ['pm2', 'kill'], {
80
+ stdio: commandStdio,
81
+ });
82
+ succeedTask(`NocoBase has stopped for "${runtime.envName}".`);
83
+ }
84
+ catch (error) {
85
+ const message = error instanceof Error ? error.message : String(error);
86
+ failTask(`Failed to stop NocoBase for "${runtime.envName}".`);
87
+ this.error(formatStopFailure(runtime.envName, message));
88
+ }
89
+ }
90
+ }