@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,307 @@
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 { Args, Command, Flags } from '@oclif/core';
10
+ import { upsertEnv } from '../../lib/auth-store.js';
11
+ import { resolveDefaultConfigScope } from '../../lib/cli-home.js';
12
+ import { runPromptCatalog, } from '../../lib/prompt-catalog.js';
13
+ import { applyCliLocale, CLI_LOCALE_FLAG_DESCRIPTION, CLI_LOCALE_FLAG_OPTIONS, localeText, } from '../../lib/cli-locale.js';
14
+ import { validateApiBaseUrl } from '../../lib/prompt-validators.js';
15
+ import { printVerbose, setVerboseMode } from '../../lib/ui.js';
16
+ import * as p from '@clack/prompts';
17
+ const ENV_RUNTIME_FLAG_MAP = {
18
+ source: 'source',
19
+ 'download-version': 'downloadVersion',
20
+ 'docker-registry': 'dockerRegistry',
21
+ 'docker-platform': 'dockerPlatform',
22
+ 'git-url': 'gitUrl',
23
+ 'npm-registry': 'npmRegistry',
24
+ 'app-root-path': 'appRootPath',
25
+ 'storage-path': 'storagePath',
26
+ 'app-port': 'appPort',
27
+ 'app-key': 'appKey',
28
+ timezone: 'timezone',
29
+ 'db-dialect': 'dbDialect',
30
+ 'builtin-db-image': 'builtinDbImage',
31
+ 'db-host': 'dbHost',
32
+ 'db-port': 'dbPort',
33
+ 'db-database': 'dbDatabase',
34
+ 'db-user': 'dbUser',
35
+ 'db-password': 'dbPassword',
36
+ };
37
+ const ENV_BOOLEAN_RUNTIME_FLAG_MAP = {
38
+ 'builtin-db': 'builtinDb',
39
+ 'dev-dependencies': 'devDependencies',
40
+ build: 'build',
41
+ 'build-dts': 'buildDts',
42
+ };
43
+ const envAddText = (key, values) => localeText(`commands.envAdd.${key}`, values);
44
+ export default class EnvAdd extends Command {
45
+ static summary = 'Save a named NocoBase API endpoint (token or OAuth), then switch the CLI to use it';
46
+ static examples = [
47
+ '<%= config.bin %> <%= command.id %>',
48
+ '<%= config.bin %> <%= command.id %> local',
49
+ '<%= config.bin %> <%= command.id %> local --api-base-url http://localhost:13000/api --auth-type oauth',
50
+ ];
51
+ static args = {
52
+ name: Args.string({
53
+ description: 'Label for this environment (optional first argument; in a TTY, prompted when omitted; required when not using a TTY)',
54
+ required: false,
55
+ }),
56
+ };
57
+ static flags = {
58
+ env: Flags.string({
59
+ char: 'e',
60
+ hidden: true,
61
+ deprecated: true,
62
+ description: 'Environment name (same as the optional positional argument; for compatibility with -e/--env on other commands)',
63
+ }),
64
+ verbose: Flags.boolean({
65
+ description: 'Print detailed progress while writing config',
66
+ default: false,
67
+ }),
68
+ locale: Flags.string({
69
+ description: CLI_LOCALE_FLAG_DESCRIPTION,
70
+ options: CLI_LOCALE_FLAG_OPTIONS,
71
+ }),
72
+ 'no-intro': Flags.boolean({
73
+ hidden: true,
74
+ description: 'Skip command intro when invoked by another CLI command',
75
+ default: false,
76
+ }),
77
+ 'default-api-base-url': Flags.string({
78
+ char: 'd',
79
+ hidden: true,
80
+ description: 'Default API base URL for HTTP API calls, including the /api prefix (e.g. http://localhost:13000/api); prompted in a TTY when omitted',
81
+ }),
82
+ 'api-base-url': Flags.string({
83
+ char: 'u',
84
+ description: 'Root URL for HTTP API calls, including the /api prefix (e.g. http://localhost:13000/api); prompted in a TTY when omitted',
85
+ }),
86
+ 'auth-type': Flags.string({
87
+ char: 'a',
88
+ description: 'Authentication: token (API key) or oauth (browser login via `nb env auth`); prompted in a TTY when omitted',
89
+ options: ['token', 'oauth'],
90
+ }),
91
+ 'access-token': Flags.string({
92
+ char: 't',
93
+ aliases: ['token'],
94
+ description: 'API key or access token when using --auth-type token (prompted in a TTY when omitted)',
95
+ }),
96
+ source: Flags.string({
97
+ hidden: true,
98
+ description: 'Application source saved with this env',
99
+ }),
100
+ 'download-version': Flags.string({
101
+ hidden: true,
102
+ description: 'Downloaded app version saved with this env',
103
+ }),
104
+ 'docker-registry': Flags.string({
105
+ hidden: true,
106
+ description: 'Docker registry saved with this env',
107
+ }),
108
+ 'docker-platform': Flags.string({
109
+ hidden: true,
110
+ description: 'Docker image platform saved with this env',
111
+ }),
112
+ 'git-url': Flags.string({
113
+ hidden: true,
114
+ description: 'Git repository URL saved with this env',
115
+ }),
116
+ 'npm-registry': Flags.string({
117
+ hidden: true,
118
+ description: 'npm registry saved with this env',
119
+ }),
120
+ 'dev-dependencies': Flags.boolean({
121
+ allowNo: true,
122
+ hidden: true,
123
+ description: 'Whether development dependencies were installed for this env',
124
+ }),
125
+ build: Flags.boolean({
126
+ allowNo: true,
127
+ hidden: true,
128
+ description: 'Whether the app was built after download for this env',
129
+ }),
130
+ 'build-dts': Flags.boolean({
131
+ allowNo: true,
132
+ hidden: true,
133
+ description: 'Whether declaration files were emitted during build for this env',
134
+ }),
135
+ 'app-root-path': Flags.string({
136
+ hidden: true,
137
+ description: 'Application root path saved with this env',
138
+ }),
139
+ 'storage-path': Flags.string({
140
+ hidden: true,
141
+ description: 'Storage path saved with this env',
142
+ }),
143
+ 'app-port': Flags.string({
144
+ hidden: true,
145
+ description: 'Application HTTP port saved with this env',
146
+ }),
147
+ 'app-key': Flags.string({
148
+ hidden: true,
149
+ description: 'Application secret key saved with this env',
150
+ }),
151
+ timezone: Flags.string({
152
+ hidden: true,
153
+ description: 'Application timezone saved with this env',
154
+ }),
155
+ 'builtin-db': Flags.boolean({
156
+ allowNo: true,
157
+ hidden: true,
158
+ description: 'Whether this env uses a CLI-managed built-in database',
159
+ }),
160
+ 'db-dialect': Flags.string({
161
+ hidden: true,
162
+ description: 'Database dialect saved with this env',
163
+ }),
164
+ 'builtin-db-image': Flags.string({
165
+ hidden: true,
166
+ description: 'Built-in database image saved with this env',
167
+ }),
168
+ 'db-host': Flags.string({
169
+ hidden: true,
170
+ description: 'Database host saved with this env',
171
+ }),
172
+ 'db-port': Flags.string({
173
+ hidden: true,
174
+ description: 'Database port saved with this env',
175
+ }),
176
+ 'db-database': Flags.string({
177
+ hidden: true,
178
+ description: 'Database name saved with this env',
179
+ }),
180
+ 'db-user': Flags.string({
181
+ hidden: true,
182
+ description: 'Database user saved with this env',
183
+ }),
184
+ 'db-password': Flags.string({
185
+ hidden: true,
186
+ description: 'Database password saved with this env',
187
+ }),
188
+ };
189
+ static prompts = {
190
+ name: {
191
+ type: 'text',
192
+ message: envAddText('prompts.name.message'),
193
+ placeholder: envAddText('prompts.name.placeholder'),
194
+ required: true,
195
+ },
196
+ apiBaseUrl: {
197
+ type: 'text',
198
+ message: envAddText('prompts.apiBaseUrl.message'),
199
+ placeholder: envAddText('prompts.apiBaseUrl.placeholder'),
200
+ required: true,
201
+ validate: validateApiBaseUrl,
202
+ },
203
+ authType: {
204
+ type: 'select',
205
+ message: envAddText('prompts.authType.message'),
206
+ options: [
207
+ {
208
+ value: 'oauth',
209
+ label: envAddText('prompts.authType.oauthLabel'),
210
+ hint: envAddText('prompts.authType.oauthHint'),
211
+ },
212
+ { value: 'token', label: envAddText('prompts.authType.tokenLabel') },
213
+ ],
214
+ initialValue: 'oauth',
215
+ required: true,
216
+ },
217
+ accessToken: {
218
+ type: 'text',
219
+ message: envAddText('prompts.accessToken.message'),
220
+ placeholder: envAddText('prompts.accessToken.placeholder'),
221
+ required: true,
222
+ hidden: (values) => values.authType !== 'token',
223
+ },
224
+ };
225
+ buildPromptValues(nameArg, flags) {
226
+ const values = {};
227
+ const name = nameArg?.trim() || flags.env?.trim();
228
+ if (name) {
229
+ values.name = name;
230
+ }
231
+ const apiFromFlag = flags['api-base-url'];
232
+ if (typeof apiFromFlag === 'string' && apiFromFlag.trim() !== '') {
233
+ values.apiBaseUrl = apiFromFlag.trim();
234
+ }
235
+ if (flags['auth-type']) {
236
+ values.authType = flags['auth-type'];
237
+ }
238
+ const token = flags['access-token'] ?? flags.token;
239
+ if (typeof token === 'string' && token !== '') {
240
+ values.accessToken = token;
241
+ }
242
+ return values;
243
+ }
244
+ buildPromptInitialValues(flags) {
245
+ const initialValues = {};
246
+ const defaultApiBaseUrl = flags['default-api-base-url']?.trim();
247
+ if (defaultApiBaseUrl) {
248
+ initialValues.apiBaseUrl = defaultApiBaseUrl;
249
+ }
250
+ return initialValues;
251
+ }
252
+ buildEnvConfig(results, flags) {
253
+ const source = String(flags.source ?? '').trim();
254
+ const appRootPath = String(flags['app-root-path'] ?? '').trim();
255
+ const kind = source === 'docker'
256
+ ? 'docker'
257
+ : source === 'npm' || source === 'git' || source === 'local' || appRootPath
258
+ ? 'local'
259
+ : 'http';
260
+ const envConfig = {
261
+ kind,
262
+ apiBaseUrl: String(results.apiBaseUrl ?? ''),
263
+ };
264
+ for (const [flagName, configKey] of Object.entries(ENV_RUNTIME_FLAG_MAP)) {
265
+ const value = flags[flagName];
266
+ if (typeof value === 'string' && value.trim() !== '') {
267
+ envConfig[configKey] = value.trim();
268
+ }
269
+ }
270
+ for (const [flagName, configKey] of Object.entries(ENV_BOOLEAN_RUNTIME_FLAG_MAP)) {
271
+ const value = flags[flagName];
272
+ if (typeof value === 'boolean') {
273
+ envConfig[configKey] = value;
274
+ }
275
+ }
276
+ if (flags['builtin-db'] === false) {
277
+ envConfig.builtinDbImage = undefined;
278
+ }
279
+ if (results.authType === 'token' && results.accessToken != null) {
280
+ envConfig.accessToken = String(results.accessToken);
281
+ }
282
+ return envConfig;
283
+ }
284
+ async run() {
285
+ const { args, flags } = await this.parse(EnvAdd);
286
+ const parsedFlags = flags;
287
+ applyCliLocale(parsedFlags.locale);
288
+ setVerboseMode(parsedFlags.verbose);
289
+ if (!parsedFlags['no-intro']) {
290
+ p.intro('Connect a NocoBase Environment');
291
+ }
292
+ const results = await runPromptCatalog(EnvAdd.prompts, {
293
+ values: this.buildPromptValues(args.name, parsedFlags),
294
+ initialValues: this.buildPromptInitialValues(parsedFlags),
295
+ command: this,
296
+ });
297
+ const envName = String(results.name);
298
+ const envConfig = this.buildEnvConfig(results, parsedFlags);
299
+ printVerbose(`Saving env "${envName}" globally.`);
300
+ await upsertEnv(envName, envConfig, { scope: resolveDefaultConfigScope() });
301
+ if (results.authType === 'oauth') {
302
+ await this.config.runCommand('env:auth', [envName]);
303
+ }
304
+ await this.config.runCommand('env:update', [envName]);
305
+ p.outro(`Env "${envName}" added successfully.`);
306
+ }
307
+ }
@@ -0,0 +1,55 @@
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 { Args, Command, Flags } from '@oclif/core';
10
+ import { getCurrentEnvName } from '../../lib/auth-store.js';
11
+ import { resolveDefaultConfigScope } from '../../lib/cli-home.js';
12
+ import { authenticateEnvWithOauth } from '../../lib/env-auth.js';
13
+ import { failTask, startTask, succeedTask } from '../../lib/ui.js';
14
+ export default class EnvAuth extends Command {
15
+ static summary = 'Sign in to a saved NocoBase environment with OAuth';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %>',
18
+ '<%= config.bin %> <%= command.id %> prod',
19
+ ];
20
+ static args = {
21
+ name: Args.string({
22
+ description: 'Environment name (omit to use the current env)',
23
+ required: false,
24
+ }),
25
+ };
26
+ static flags = {
27
+ env: Flags.string({
28
+ char: 'e',
29
+ hidden: true,
30
+ deprecated: true,
31
+ description: 'Environment name (same as the optional positional argument; for compatibility with -e/--env on other commands)',
32
+ }),
33
+ };
34
+ async run() {
35
+ const { args, flags } = await this.parse(EnvAuth);
36
+ const nameArg = args.name?.trim();
37
+ const nameFlag = flags.env?.trim() || undefined;
38
+ if (nameArg && nameFlag && nameArg !== nameFlag) {
39
+ this.error(`Environment name was provided both as the argument ("${nameArg}") and as --env ("${nameFlag}"). Please use only one.`);
40
+ }
41
+ const envName = nameArg || nameFlag || (await getCurrentEnvName({ scope: resolveDefaultConfigScope() }));
42
+ startTask(`Starting browser sign-in for "${envName}"...`);
43
+ try {
44
+ await authenticateEnvWithOauth({
45
+ envName,
46
+ scope: resolveDefaultConfigScope(),
47
+ });
48
+ succeedTask(`Signed in to "${envName}".`);
49
+ }
50
+ catch (error) {
51
+ failTask(`Sign-in failed for "${envName}".`);
52
+ throw error;
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,36 @@
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 } from '@oclif/core';
10
+ import { listEnvs } from '../../lib/auth-store.js';
11
+ import { resolveDefaultConfigScope } from '../../lib/cli-home.js';
12
+ import { renderTable } from '../../lib/ui.js';
13
+ function resolveApiBaseUrl(config) {
14
+ return String(config.apiBaseUrl ?? config.baseUrl ?? config.apibaseUrl ?? '').trim();
15
+ }
16
+ export default class EnvList extends Command {
17
+ static summary = 'List configured environments';
18
+ static examples = [
19
+ '<%= config.bin %> <%= command.id %>',
20
+ ];
21
+ async run() {
22
+ await this.parse(EnvList);
23
+ const { currentEnv, envs } = await listEnvs({ scope: resolveDefaultConfigScope() });
24
+ const names = Object.keys(envs).sort();
25
+ if (!names.length) {
26
+ this.log('No envs configured.');
27
+ this.log('Run `nb env add <name> --api-base-url <url>` to add one.');
28
+ return;
29
+ }
30
+ const rows = names.map((name) => {
31
+ const env = envs[name];
32
+ return [name === currentEnv ? '*' : '', name, resolveApiBaseUrl(env), env.auth?.type ?? '', env.runtime?.version ?? ''];
33
+ });
34
+ this.log(renderTable(['Current', 'Name', 'Base URL', 'Auth', 'Runtime'], rows));
35
+ }
36
+ }
@@ -0,0 +1,59 @@
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 { Args, Command, Flags } from '@oclif/core';
10
+ import { getCurrentEnvName, removeEnv } from '../../lib/auth-store.js';
11
+ import { resolveDefaultConfigScope } from '../../lib/cli-home.js';
12
+ import { confirmAction, isInteractiveTerminal, printVerbose, setVerboseMode } from '../../lib/ui.js';
13
+ export default class EnvRemove extends Command {
14
+ static summary = 'Remove a configured environment';
15
+ static examples = [
16
+ '<%= config.bin %> <%= command.id %> staging',
17
+ '<%= config.bin %> <%= command.id %> staging -f',
18
+ ];
19
+ static flags = {
20
+ force: Flags.boolean({
21
+ char: 'f',
22
+ description: 'Remove without confirmation',
23
+ default: false,
24
+ }),
25
+ verbose: Flags.boolean({
26
+ description: 'Show detailed progress output',
27
+ default: false,
28
+ }),
29
+ };
30
+ static args = {
31
+ name: Args.string({
32
+ description: 'Configured environment name',
33
+ required: true,
34
+ }),
35
+ };
36
+ async run() {
37
+ const { args, flags } = await this.parse(EnvRemove);
38
+ setVerboseMode(flags.verbose);
39
+ const currentEnv = await getCurrentEnvName({ scope: resolveDefaultConfigScope() });
40
+ if (args.name === currentEnv && !flags.force) {
41
+ if (!isInteractiveTerminal()) {
42
+ this.error('Refusing to remove the current env without confirmation. Re-run with `--force`.');
43
+ }
44
+ const confirmed = await confirmAction(`Remove current env "${args.name}"?`, { defaultValue: false });
45
+ if (!confirmed) {
46
+ this.log('Canceled.');
47
+ return;
48
+ }
49
+ }
50
+ printVerbose(`Removing env "${args.name}"`);
51
+ const result = await removeEnv(args.name, { scope: resolveDefaultConfigScope() });
52
+ this.log(`Removed env "${result.removed}".`);
53
+ if (result.hasEnvs) {
54
+ this.log(`Current env: ${result.currentEnv}`);
55
+ return;
56
+ }
57
+ this.log('No envs configured.');
58
+ }
59
+ }
@@ -0,0 +1,67 @@
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 path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { Args, Command, Flags } from '@oclif/core';
12
+ import { getCurrentEnvName } from '../../lib/auth-store.js';
13
+ import { updateEnvRuntime } from '../../lib/bootstrap.js';
14
+ import { resolveDefaultConfigScope } from '../../lib/cli-home.js';
15
+ import { failTask, startTask, succeedTask } from '../../lib/ui.js';
16
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
17
+ export default class EnvUpdate extends Command {
18
+ static summary = 'Refresh an environment runtime from swagger:get and persist connection overrides';
19
+ static examples = [
20
+ '<%= config.bin %> <%= command.id %>',
21
+ '<%= config.bin %> <%= command.id %> prod',
22
+ ];
23
+ static args = {
24
+ name: Args.string({
25
+ description: 'Environment name (omit to use the current env)',
26
+ required: false,
27
+ }),
28
+ };
29
+ static flags = {
30
+ verbose: Flags.boolean({
31
+ description: 'Show detailed progress output',
32
+ default: false,
33
+ }),
34
+ 'api-base-url': Flags.string({
35
+ description: 'NocoBase API base URL override. When provided, persist it to the target env before saving the refreshed runtime.',
36
+ }),
37
+ role: Flags.string({
38
+ description: 'Role override, sent as X-Role',
39
+ }),
40
+ token: Flags.string({
41
+ char: 't',
42
+ description: 'API key override. When provided, persist it to the target env before saving the refreshed runtime.',
43
+ }),
44
+ };
45
+ async run() {
46
+ const { args, flags } = await this.parse(EnvUpdate);
47
+ const envName = args.name;
48
+ const envLabel = envName ?? (await getCurrentEnvName({ scope: resolveDefaultConfigScope() }));
49
+ startTask(`Updating env runtime: ${envLabel}`);
50
+ try {
51
+ const runtime = await updateEnvRuntime({
52
+ envName,
53
+ scope: resolveDefaultConfigScope(),
54
+ baseUrl: flags['api-base-url'],
55
+ role: flags.role,
56
+ token: flags.token,
57
+ configFile: path.join(path.dirname(path.dirname(path.dirname(__dirname))), 'nocobase-ctl.config.json'),
58
+ verbose: flags.verbose,
59
+ });
60
+ succeedTask(`Updated env "${envLabel}" to runtime "${runtime.version}".`);
61
+ }
62
+ catch (error) {
63
+ failTask(`Failed to update env "${envLabel}".`);
64
+ throw error;
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,28 @@
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 { Args, Command } from '@oclif/core';
10
+ import { setCurrentEnv } from '../../lib/auth-store.js';
11
+ import { resolveDefaultConfigScope } from '../../lib/cli-home.js';
12
+ export default class EnvUse extends Command {
13
+ static summary = 'Switch the current environment';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> local',
16
+ ];
17
+ static args = {
18
+ name: Args.string({
19
+ description: 'Configured environment name',
20
+ required: true,
21
+ }),
22
+ };
23
+ async run() {
24
+ const { args } = await this.parse(EnvUse);
25
+ await setCurrentEnv(args.name, { scope: resolveDefaultConfigScope() });
26
+ this.log(`Current env: ${args.name}`);
27
+ }
28
+ }