@nocobase/cli 2.1.0-alpha.4 → 2.1.0-alpha.40

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 (211) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +393 -19
  3. package/README.zh-CN.md +343 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +135 -0
  6. package/bin/session-env.js +39 -0
  7. package/dist/commands/api/resource/create.js +15 -0
  8. package/dist/commands/api/resource/destroy.js +15 -0
  9. package/dist/commands/api/resource/get.js +15 -0
  10. package/dist/commands/api/resource/index.js +20 -0
  11. package/dist/commands/api/resource/list.js +16 -0
  12. package/dist/commands/api/resource/query.js +15 -0
  13. package/dist/commands/api/resource/update.js +15 -0
  14. package/dist/commands/app/down.js +301 -0
  15. package/dist/commands/app/logs.js +114 -0
  16. package/dist/commands/app/restart.js +158 -0
  17. package/dist/commands/app/start.js +305 -0
  18. package/dist/commands/app/stop.js +115 -0
  19. package/dist/commands/app/upgrade.js +636 -0
  20. package/dist/commands/backup/create.js +147 -0
  21. package/dist/commands/backup/index.js +20 -0
  22. package/dist/commands/backup/restore.js +105 -0
  23. package/{src/cli.js → dist/commands/build.js} +4 -11
  24. package/dist/commands/config/delete.js +30 -0
  25. package/dist/commands/config/get.js +29 -0
  26. package/dist/commands/config/index.js +20 -0
  27. package/dist/commands/config/list.js +29 -0
  28. package/dist/commands/config/set.js +35 -0
  29. package/dist/commands/db/check.js +240 -0
  30. package/dist/commands/db/logs.js +85 -0
  31. package/dist/commands/db/ps.js +60 -0
  32. package/dist/commands/db/shared.js +96 -0
  33. package/dist/commands/db/start.js +71 -0
  34. package/dist/commands/db/stop.js +71 -0
  35. package/{templates/plugin/src/client/models/index.ts → dist/commands/dev.js} +4 -4
  36. package/{src/commands/locale/react-js-cron/index.js → dist/commands/down.js} +3 -8
  37. package/dist/commands/download.js +13 -0
  38. package/dist/commands/env/add.js +366 -0
  39. package/dist/commands/env/auth.js +130 -0
  40. package/dist/commands/env/current.js +21 -0
  41. package/dist/commands/env/info.js +157 -0
  42. package/dist/commands/env/list.js +44 -0
  43. package/dist/commands/env/remove.js +84 -0
  44. package/dist/commands/env/shared.js +158 -0
  45. package/dist/commands/env/status.js +90 -0
  46. package/dist/commands/env/update.js +74 -0
  47. package/dist/commands/env/use.js +38 -0
  48. package/dist/commands/examples/prompts-stages.js +150 -0
  49. package/dist/commands/examples/prompts-test.js +181 -0
  50. package/dist/commands/init.js +1092 -0
  51. package/dist/commands/install.js +2378 -0
  52. package/dist/commands/license/activate.js +360 -0
  53. package/dist/commands/license/env.js +94 -0
  54. package/dist/commands/license/generate-id.js +108 -0
  55. package/dist/commands/license/id.js +70 -0
  56. package/dist/commands/license/index.js +20 -0
  57. package/dist/commands/license/plugins/clean.js +115 -0
  58. package/dist/commands/license/plugins/index.js +20 -0
  59. package/dist/commands/license/plugins/list.js +64 -0
  60. package/dist/commands/license/plugins/shared.js +325 -0
  61. package/dist/commands/license/plugins/sync.js +285 -0
  62. package/dist/commands/license/shared.js +423 -0
  63. package/dist/commands/license/status.js +64 -0
  64. package/dist/commands/logs.js +12 -0
  65. package/dist/commands/plugin/disable.js +86 -0
  66. package/dist/commands/plugin/enable.js +86 -0
  67. package/dist/commands/plugin/list.js +82 -0
  68. package/dist/commands/pm/disable.js +12 -0
  69. package/dist/commands/pm/enable.js +12 -0
  70. package/dist/commands/pm/list.js +12 -0
  71. package/dist/commands/restart.js +12 -0
  72. package/dist/commands/scaffold/migration.js +38 -0
  73. package/dist/commands/scaffold/plugin.js +37 -0
  74. package/dist/commands/self/check.js +71 -0
  75. package/dist/commands/self/index.js +20 -0
  76. package/dist/commands/self/update.js +95 -0
  77. package/dist/commands/session/id.js +24 -0
  78. package/dist/commands/session/remove.js +57 -0
  79. package/dist/commands/session/setup.js +62 -0
  80. package/dist/commands/skills/check.js +69 -0
  81. package/dist/commands/skills/index.js +20 -0
  82. package/dist/commands/skills/install.js +80 -0
  83. package/dist/commands/skills/remove.js +80 -0
  84. package/dist/commands/skills/update.js +87 -0
  85. package/dist/commands/source/build.js +58 -0
  86. package/dist/commands/source/dev.js +182 -0
  87. package/dist/commands/source/download.js +880 -0
  88. package/dist/commands/source/publish.js +109 -0
  89. package/dist/commands/source/registry/logs.js +70 -0
  90. package/dist/commands/source/registry/start.js +57 -0
  91. package/dist/commands/source/registry/status.js +33 -0
  92. package/dist/commands/source/registry/stop.js +48 -0
  93. package/dist/commands/source/test.js +477 -0
  94. package/dist/commands/start.js +12 -0
  95. package/dist/commands/stop.js +12 -0
  96. package/dist/commands/test.js +12 -0
  97. package/dist/commands/upgrade.js +12 -0
  98. package/dist/commands/v1.js +210 -0
  99. package/dist/generated/command-registry.js +133 -0
  100. package/dist/help/runtime-help.js +23 -0
  101. package/dist/lib/api-client.js +329 -0
  102. package/dist/lib/app-health.js +126 -0
  103. package/dist/lib/app-managed-resources.js +316 -0
  104. package/dist/lib/app-runtime.js +180 -0
  105. package/dist/lib/auth-store.js +368 -0
  106. package/dist/lib/backup.js +171 -0
  107. package/dist/lib/bootstrap.js +403 -0
  108. package/dist/lib/build-config.js +18 -0
  109. package/dist/lib/builtin-db.js +86 -0
  110. package/dist/lib/cli-config.js +176 -0
  111. package/dist/lib/cli-home.js +47 -0
  112. package/dist/lib/cli-locale.js +129 -0
  113. package/dist/lib/command-discovery.js +39 -0
  114. package/dist/lib/db-connection-check.js +158 -0
  115. package/dist/lib/docker-env-file.js +52 -0
  116. package/dist/lib/docker-image.js +37 -0
  117. package/dist/lib/env-auth.js +873 -0
  118. package/dist/lib/env-config.js +94 -0
  119. package/dist/lib/env-guard.js +62 -0
  120. package/dist/lib/generated-command.js +186 -0
  121. package/dist/lib/http-request.js +49 -0
  122. package/dist/lib/inquirer-theme.js +17 -0
  123. package/dist/lib/inquirer.js +244 -0
  124. package/dist/lib/naming.js +70 -0
  125. package/dist/lib/object-utils.js +76 -0
  126. package/dist/lib/openapi.js +62 -0
  127. package/dist/lib/plugin-storage.js +64 -0
  128. package/dist/lib/post-processors.js +23 -0
  129. package/dist/lib/prompt-catalog-core.js +185 -0
  130. package/dist/lib/prompt-catalog-terminal.js +375 -0
  131. package/{src/index.js → dist/lib/prompt-catalog.js} +2 -6
  132. package/dist/lib/prompt-validators.js +240 -0
  133. package/dist/lib/prompt-web-ui.js +2103 -0
  134. package/dist/lib/resource-command.js +357 -0
  135. package/dist/lib/resource-request.js +104 -0
  136. package/dist/lib/run-npm.js +275 -0
  137. package/dist/lib/runtime-env-vars.js +32 -0
  138. package/dist/lib/runtime-generator.js +498 -0
  139. package/dist/lib/runtime-store.js +56 -0
  140. package/dist/lib/self-manager.js +301 -0
  141. package/dist/lib/session-id.js +17 -0
  142. package/dist/lib/session-integration.js +703 -0
  143. package/dist/lib/session-store.js +118 -0
  144. package/dist/lib/skills-manager.js +360 -0
  145. package/dist/lib/source-publish.js +306 -0
  146. package/dist/lib/source-registry.js +188 -0
  147. package/dist/lib/startup-update.js +285 -0
  148. package/dist/lib/ui.js +155 -0
  149. package/dist/locale/en-US.json +344 -0
  150. package/dist/locale/zh-CN.json +344 -0
  151. package/dist/post-processors/data-modeling.js +84 -0
  152. package/dist/post-processors/data-source-manager.js +138 -0
  153. package/dist/post-processors/index.js +19 -0
  154. package/nocobase-ctl.config.json +388 -0
  155. package/package.json +100 -26
  156. package/LICENSE +0 -661
  157. package/bin/index.js +0 -39
  158. package/nocobase.conf.tpl +0 -95
  159. package/src/commands/benchmark.js +0 -73
  160. package/src/commands/build.js +0 -49
  161. package/src/commands/clean.js +0 -30
  162. package/src/commands/client.js +0 -166
  163. package/src/commands/create-nginx-conf.js +0 -37
  164. package/src/commands/create-plugin.js +0 -33
  165. package/src/commands/dev.js +0 -200
  166. package/src/commands/doc.js +0 -76
  167. package/src/commands/e2e.js +0 -265
  168. package/src/commands/global.js +0 -43
  169. package/src/commands/index.js +0 -45
  170. package/src/commands/instance-id.js +0 -47
  171. package/src/commands/locale/cronstrue.js +0 -122
  172. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  173. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  174. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  175. package/src/commands/locale.js +0 -81
  176. package/src/commands/p-test.js +0 -88
  177. package/src/commands/perf.js +0 -63
  178. package/src/commands/pkg.js +0 -321
  179. package/src/commands/pm2.js +0 -37
  180. package/src/commands/postinstall.js +0 -88
  181. package/src/commands/start.js +0 -148
  182. package/src/commands/tar.js +0 -36
  183. package/src/commands/test-coverage.js +0 -55
  184. package/src/commands/test.js +0 -107
  185. package/src/commands/umi.js +0 -33
  186. package/src/commands/update-deps.js +0 -72
  187. package/src/commands/upgrade.js +0 -47
  188. package/src/commands/view-license-key.js +0 -44
  189. package/src/license.js +0 -76
  190. package/src/logger.js +0 -75
  191. package/src/plugin-generator.js +0 -80
  192. package/src/util.js +0 -517
  193. package/templates/bundle-status.html +0 -338
  194. package/templates/create-app-package.json +0 -39
  195. package/templates/plugin/.npmignore.tpl +0 -2
  196. package/templates/plugin/README.md.tpl +0 -1
  197. package/templates/plugin/client.d.ts +0 -2
  198. package/templates/plugin/client.js +0 -1
  199. package/templates/plugin/package.json.tpl +0 -11
  200. package/templates/plugin/server.d.ts +0 -2
  201. package/templates/plugin/server.js +0 -1
  202. package/templates/plugin/src/client/client.d.ts +0 -249
  203. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  204. package/templates/plugin/src/client/locale.ts +0 -21
  205. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  206. package/templates/plugin/src/index.ts +0 -2
  207. package/templates/plugin/src/locale/en-US.json +0 -1
  208. package/templates/plugin/src/locale/zh-CN.json +0 -1
  209. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  210. package/templates/plugin/src/server/index.ts.tpl +0 -1
  211. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -0,0 +1,147 @@
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 { BACKUP_CREATE_TIMEOUT_MS, BACKUP_POLL_INTERVAL_MS, BACKUP_RUNTIME_COMMANDS, buildBackupEnvArgv, ensureBackupRuntimeCommands, resolveBackupCreateOutputPath, resolveBackupTargetEnv, runBackupCliJsonCommand, sleep, } from '../../lib/backup.js';
11
+ import { ensureCrossEnvConfirmed, hasExplicitEnvSelection } from '../../lib/env-guard.js';
12
+ import { announceTargetEnv, failTask, startTask, succeedTask, updateTask } from '../../lib/ui.js';
13
+ function formatBackupCreateTimeoutError(envName, name) {
14
+ return [
15
+ `Backup "${name}" did not finish in time for "${envName}".`,
16
+ `Waited ${Math.floor(BACKUP_CREATE_TIMEOUT_MS / 1000)}s but it still reports \`inProgress: true\`.`,
17
+ ].join(' ');
18
+ }
19
+ function readBackupCreateResult(response) {
20
+ const name = String(response.data?.name ?? '').trim();
21
+ if (!name) {
22
+ throw new Error('Backup creation did not return a backup name.');
23
+ }
24
+ return {
25
+ name,
26
+ inProgress: Boolean(response.data?.inProgress),
27
+ };
28
+ }
29
+ function readBackupInProgress(response, name) {
30
+ const status = response.data?.[name];
31
+ if (!status || typeof status !== 'object') {
32
+ throw new Error(`Backup status did not include "${name}".`);
33
+ }
34
+ return Boolean(status.inProgress);
35
+ }
36
+ function readDownloadOutput(response) {
37
+ const output = String(response.data?.output ?? '').trim();
38
+ return output || undefined;
39
+ }
40
+ export default class BackupCreate extends Command {
41
+ static summary = 'Create a backup through the selected env and download it locally';
42
+ static examples = [
43
+ '<%= config.bin %> <%= command.id %>',
44
+ '<%= config.bin %> <%= command.id %> --output ./fixtures/base.nbdump',
45
+ '<%= config.bin %> <%= command.id %> --env e2e --output ./fixtures',
46
+ ];
47
+ static flags = {
48
+ env: Flags.string({
49
+ char: 'e',
50
+ description: 'CLI env name to back up. Defaults to the current env when omitted',
51
+ }),
52
+ yes: Flags.boolean({
53
+ char: 'y',
54
+ description: 'Confirm using --env when it targets a different env than the current env',
55
+ default: false,
56
+ }),
57
+ output: Flags.string({
58
+ char: 'o',
59
+ description: 'Download path. When omitted, save to the current directory using the remote backup filename',
60
+ }),
61
+ 'json-output': Flags.boolean({
62
+ char: 'j',
63
+ description: 'Print the final backup result as JSON',
64
+ default: false,
65
+ }),
66
+ };
67
+ async run() {
68
+ const { flags } = await this.parse(BackupCreate);
69
+ const requestedEnv = flags.env?.trim() || undefined;
70
+ const explicitEnvSelection = Boolean(requestedEnv && hasExplicitEnvSelection(this.argv));
71
+ const jsonOutput = Boolean(flags['json-output']);
72
+ if (explicitEnvSelection) {
73
+ const confirmed = await ensureCrossEnvConfirmed({
74
+ command: this,
75
+ requestedEnv,
76
+ yes: flags.yes,
77
+ });
78
+ if (!confirmed) {
79
+ return;
80
+ }
81
+ }
82
+ const { envName, env } = await resolveBackupTargetEnv(requestedEnv);
83
+ const envArgv = buildBackupEnvArgv({
84
+ requestedEnv,
85
+ explicitEnvSelection,
86
+ yes: flags.yes,
87
+ });
88
+ if (!jsonOutput) {
89
+ announceTargetEnv(envName);
90
+ }
91
+ await ensureBackupRuntimeCommands({
92
+ envName,
93
+ env,
94
+ commandIds: [
95
+ BACKUP_RUNTIME_COMMANDS.create,
96
+ BACKUP_RUNTIME_COMMANDS.status,
97
+ BACKUP_RUNTIME_COMMANDS.download,
98
+ ],
99
+ quiet: jsonOutput,
100
+ });
101
+ try {
102
+ if (!jsonOutput) {
103
+ startTask(`Creating backup for "${envName}"...`);
104
+ }
105
+ const createResponse = await runBackupCliJsonCommand(['api', 'backup', 'create', ...envArgv], { errorName: 'nb api backup create' });
106
+ const { name, inProgress } = readBackupCreateResult(createResponse);
107
+ const outputPath = await resolveBackupCreateOutputPath(flags.output, name);
108
+ const startedAt = Date.now();
109
+ let pending = inProgress;
110
+ while (pending) {
111
+ const now = Date.now();
112
+ const elapsedMs = now - startedAt;
113
+ if (elapsedMs >= BACKUP_CREATE_TIMEOUT_MS) {
114
+ throw new Error(formatBackupCreateTimeoutError(envName, name));
115
+ }
116
+ const elapsedSeconds = Math.max(1, Math.floor(elapsedMs / 1000));
117
+ if (!jsonOutput) {
118
+ updateTask(`Waiting for backup "${name}" to finish for "${envName}"... (${elapsedSeconds}s elapsed)`);
119
+ }
120
+ await sleep(BACKUP_POLL_INTERVAL_MS);
121
+ const statusResponse = await runBackupCliJsonCommand(['api', 'backup', 'status', '--name', name, ...envArgv], { errorName: 'nb api backup status' });
122
+ pending = readBackupInProgress(statusResponse, name);
123
+ }
124
+ if (!jsonOutput) {
125
+ updateTask(`Downloading backup "${name}" for "${envName}"...`);
126
+ }
127
+ const downloadResponse = await runBackupCliJsonCommand(['api', 'backup', 'download', '--name', name, '--output', outputPath, ...envArgv], { errorName: 'nb api backup download' });
128
+ const savedPath = readDownloadOutput(downloadResponse) ?? outputPath;
129
+ const result = {
130
+ env: envName,
131
+ name,
132
+ output: savedPath,
133
+ };
134
+ if (jsonOutput) {
135
+ this.log(JSON.stringify(result, null, 2));
136
+ return;
137
+ }
138
+ succeedTask(`Backup saved to ${savedPath}`);
139
+ }
140
+ catch (error) {
141
+ if (!jsonOutput) {
142
+ failTask(`Failed to create backup for "${envName}".`);
143
+ }
144
+ throw error;
145
+ }
146
+ }
147
+ }
@@ -0,0 +1,20 @@
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, loadHelpClass } from '@oclif/core';
10
+ export default class Backup extends Command {
11
+ static summary = 'Create or restore NocoBase backups';
12
+ async run() {
13
+ await this.parse(Backup);
14
+ const Help = await loadHelpClass(this.config);
15
+ await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
16
+ this.id ?? 'backup',
17
+ ...this.argv,
18
+ ]);
19
+ }
20
+ }
@@ -0,0 +1,105 @@
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 { BACKUP_RUNTIME_COMMANDS, buildBackupEnvArgv, ensureBackupRuntimeCommands, resolveBackupRestoreFilePath, resolveBackupTargetEnv, resolveBackupWaitApiBaseUrl, runBackupCliCommand, } from '../../lib/backup.js';
11
+ import { waitForAppReady } from '../../lib/app-health.js';
12
+ import { ensureCrossEnvConfirmed, hasExplicitEnvSelection } from '../../lib/env-guard.js';
13
+ import { confirm } from "../../lib/inquirer.js";
14
+ import { announceTargetEnv, failTask, isInteractiveTerminal, startTask, stopTask, succeedTask } from '../../lib/ui.js';
15
+ async function confirmBackupRestore(envName, filePath, force) {
16
+ if (force) {
17
+ return true;
18
+ }
19
+ if (!isInteractiveTerminal()) {
20
+ throw new Error(`\`nb backup restore\` needs confirmation. Re-run with \`--force\` to restore ${filePath} into "${envName}" in non-interactive mode.`);
21
+ }
22
+ try {
23
+ return await confirm({
24
+ message: `Restore backup "${filePath}" into "${envName}"? This will overwrite application data.`,
25
+ default: false,
26
+ });
27
+ }
28
+ catch {
29
+ return false;
30
+ }
31
+ }
32
+ export default class BackupRestore extends Command {
33
+ static summary = 'Restore a backup file into the selected env';
34
+ static examples = [
35
+ '<%= config.bin %> <%= command.id %> --file ./fixtures/base.nbdump --force',
36
+ '<%= config.bin %> <%= command.id %> --env e2e --file ./fixtures/base.nbdump --yes --force',
37
+ ];
38
+ static flags = {
39
+ env: Flags.string({
40
+ char: 'e',
41
+ description: 'CLI env name to restore into. Defaults to the current env when omitted',
42
+ }),
43
+ yes: Flags.boolean({
44
+ char: 'y',
45
+ description: 'Confirm using --env when it targets a different env than the current env',
46
+ default: false,
47
+ }),
48
+ file: Flags.string({
49
+ char: 'f',
50
+ description: 'Local backup file to upload and restore',
51
+ required: true,
52
+ }),
53
+ force: Flags.boolean({
54
+ description: 'Confirm overwriting application data during restore',
55
+ default: false,
56
+ }),
57
+ };
58
+ async run() {
59
+ const { flags } = await this.parse(BackupRestore);
60
+ const requestedEnv = flags.env?.trim() || undefined;
61
+ const explicitEnvSelection = Boolean(requestedEnv && hasExplicitEnvSelection(this.argv));
62
+ if (explicitEnvSelection) {
63
+ const confirmed = await ensureCrossEnvConfirmed({
64
+ command: this,
65
+ requestedEnv,
66
+ yes: flags.yes,
67
+ });
68
+ if (!confirmed) {
69
+ return;
70
+ }
71
+ }
72
+ const filePath = await resolveBackupRestoreFilePath(flags.file);
73
+ const { envName, env } = await resolveBackupTargetEnv(requestedEnv);
74
+ const restoreConfirmed = await confirmBackupRestore(envName, filePath, flags.force);
75
+ if (!restoreConfirmed) {
76
+ return;
77
+ }
78
+ const envArgv = buildBackupEnvArgv({
79
+ requestedEnv,
80
+ explicitEnvSelection,
81
+ yes: flags.yes,
82
+ });
83
+ announceTargetEnv(envName);
84
+ await ensureBackupRuntimeCommands({
85
+ envName,
86
+ env,
87
+ commandIds: [BACKUP_RUNTIME_COMMANDS.restoreUpload],
88
+ });
89
+ startTask(`Restoring backup for "${envName}" from ${filePath}...`);
90
+ try {
91
+ await runBackupCliCommand(['api', 'backup', 'restore-upload', '--file', filePath, '--force', ...envArgv], { errorName: 'nb api backup restore-upload' });
92
+ stopTask();
93
+ await waitForAppReady({
94
+ envName,
95
+ apiBaseUrl: resolveBackupWaitApiBaseUrl(env),
96
+ });
97
+ succeedTask(`Backup restored for "${envName}" from ${filePath}`);
98
+ }
99
+ catch (error) {
100
+ stopTask();
101
+ failTask(`Failed to restore backup for "${envName}".`);
102
+ throw error;
103
+ }
104
+ }
105
+ }
@@ -6,14 +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
-
10
- const { Command } = require('commander');
11
- const commands = require('./commands');
12
-
13
- const cli = new Command();
14
-
15
- cli.version(require('../package.json').version);
16
-
17
- commands(cli);
18
-
19
- module.exports = cli;
9
+ import SourceBuild from './source/build.js';
10
+ export default class Build extends SourceBuild {
11
+ static hidden = true;
12
+ }
@@ -0,0 +1,30 @@
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 { assertSupportedCliConfigKey, deleteCliConfigValue } from '../../lib/cli-config.js';
11
+ export default class ConfigDelete extends Command {
12
+ static summary = 'Delete an explicitly configured CLI setting';
13
+ static examples = [
14
+ '<%= config.bin %> <%= command.id %> license.pkg-url',
15
+ '<%= config.bin %> <%= command.id %> docker.network',
16
+ '<%= config.bin %> <%= command.id %> docker.container-prefix',
17
+ ];
18
+ static args = {
19
+ key: Args.string({
20
+ description: 'Configuration key',
21
+ required: true,
22
+ }),
23
+ };
24
+ async run() {
25
+ const { args } = await this.parse(ConfigDelete);
26
+ const key = assertSupportedCliConfigKey(args.key);
27
+ const removed = await deleteCliConfigValue(key);
28
+ this.log(removed ? `Deleted ${key}` : `${key} was not set`);
29
+ }
30
+ }
@@ -0,0 +1,29 @@
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 { assertSupportedCliConfigKey, getCliConfigValue } from '../../lib/cli-config.js';
11
+ export default class ConfigGet extends Command {
12
+ static summary = 'Get the effective CLI configuration value for a key';
13
+ static examples = [
14
+ '<%= config.bin %> <%= command.id %> license.pkg-url',
15
+ '<%= config.bin %> <%= command.id %> docker.network',
16
+ '<%= config.bin %> <%= command.id %> docker.container-prefix',
17
+ ];
18
+ static args = {
19
+ key: Args.string({
20
+ description: 'Configuration key',
21
+ required: true,
22
+ }),
23
+ };
24
+ async run() {
25
+ const { args } = await this.parse(ConfigGet);
26
+ const key = assertSupportedCliConfigKey(args.key);
27
+ this.log(await getCliConfigValue(key));
28
+ }
29
+ }
@@ -0,0 +1,20 @@
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, loadHelpClass } from '@oclif/core';
10
+ export default class Config extends Command {
11
+ static summary = 'Manage CLI configuration defaults';
12
+ async run() {
13
+ await this.parse(Config);
14
+ const Help = await loadHelpClass(this.config);
15
+ await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
16
+ this.id ?? 'config',
17
+ ...this.argv,
18
+ ]);
19
+ }
20
+ }
@@ -0,0 +1,29 @@
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 { listExplicitCliConfigValues, SUPPORTED_CLI_CONFIG_KEYS } from '../../lib/cli-config.js';
11
+ import { renderTable } from '../../lib/ui.js';
12
+ export default class ConfigList extends Command {
13
+ static summary = 'List explicitly configured CLI settings';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %>',
16
+ ];
17
+ async run() {
18
+ await this.parse(ConfigList);
19
+ const values = await listExplicitCliConfigValues();
20
+ const rows = SUPPORTED_CLI_CONFIG_KEYS
21
+ .filter((key) => Boolean(values[key]))
22
+ .map((key) => [key, values[key] ?? '']);
23
+ if (!rows.length) {
24
+ this.log('No CLI config values are set.');
25
+ return;
26
+ }
27
+ this.log(renderTable(['Key', 'Value'], rows));
28
+ }
29
+ }
@@ -0,0 +1,35 @@
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 { assertSupportedCliConfigKey, setCliConfigValue } from '../../lib/cli-config.js';
11
+ export default class ConfigSet extends Command {
12
+ static summary = 'Set a CLI configuration value';
13
+ static description = 'Set a supported CLI configuration key. Supported keys: license.pkg-url, docker.network, docker.container-prefix.';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> license.pkg-url https://pkg.nocobase.com/',
16
+ '<%= config.bin %> <%= command.id %> docker.network nocobase',
17
+ '<%= config.bin %> <%= command.id %> docker.container-prefix nb',
18
+ ];
19
+ static args = {
20
+ key: Args.string({
21
+ description: 'Configuration key',
22
+ required: true,
23
+ }),
24
+ value: Args.string({
25
+ description: 'Configuration value',
26
+ required: true,
27
+ }),
28
+ };
29
+ async run() {
30
+ const { args } = await this.parse(ConfigSet);
31
+ const key = assertSupportedCliConfigKey(args.key);
32
+ const value = await setCliConfigValue(key, args.value);
33
+ this.log(`${key}=${value}`);
34
+ }
35
+ }
@@ -0,0 +1,240 @@
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 } from '../../lib/app-runtime.js';
11
+ import { resolveBuiltinDbConnection } from '../../lib/builtin-db.js';
12
+ import { checkExternalDbConnection, formatDbCheckAddress, readExternalDbConnectionConfig, } from "../../lib/db-connection-check.js";
13
+ import { DEFAULT_DOCKER_REGISTRY, DEFAULT_DOCKER_VERSION, resolveDockerImageRef, } from "../../lib/docker-image.js";
14
+ import { commandOutput } from '../../lib/run-npm.js';
15
+ import { validateTcpPort } from "../../lib/prompt-validators.js";
16
+ function trimValue(value) {
17
+ const text = String(value ?? '').trim();
18
+ return text || undefined;
19
+ }
20
+ function resolveRequiredDbField(flagValue, envValue) {
21
+ return trimValue(flagValue) ?? trimValue(envValue);
22
+ }
23
+ function normalizeDockerPlatform(value) {
24
+ const text = trimValue(value);
25
+ if (!text || text === 'auto') {
26
+ return undefined;
27
+ }
28
+ if (text === 'linux/amd64' || text === 'linux/arm64') {
29
+ return text;
30
+ }
31
+ return undefined;
32
+ }
33
+ function formatMissingFieldsMessage(missing, hasEnv) {
34
+ return [
35
+ 'Missing database settings for connectivity check.',
36
+ `Required: ${missing.join(', ')}.`,
37
+ hasEnv
38
+ ? 'Pass `--env <name>` to reuse a saved env, or provide the missing `--db-*` flags explicitly.'
39
+ : 'Provide all required `--db-*` flags explicitly, or pass `--env <name>` to reuse a saved env.',
40
+ ].join('\n');
41
+ }
42
+ function resolveDbConfigFromFlags(flags, envConfig) {
43
+ return {
44
+ builtinDb: false,
45
+ dbDialect: resolveRequiredDbField(flags['db-dialect'], envConfig?.dbDialect),
46
+ dbHost: resolveRequiredDbField(flags['db-host'], envConfig?.dbHost),
47
+ dbPort: resolveRequiredDbField(flags['db-port'], envConfig?.dbPort),
48
+ dbDatabase: resolveRequiredDbField(flags['db-database'], envConfig?.dbDatabase),
49
+ dbUser: resolveRequiredDbField(flags['db-user'], envConfig?.dbUser),
50
+ dbPassword: flags['db-password'] !== undefined
51
+ ? String(flags['db-password'] ?? '')
52
+ : envConfig?.dbPassword !== undefined
53
+ ? String(envConfig.dbPassword ?? '')
54
+ : undefined,
55
+ };
56
+ }
57
+ function validateDbConfigOrThrow(command, dbConfig, hasEnv) {
58
+ const missing = [];
59
+ if (!dbConfig.dbDialect) {
60
+ missing.push('--db-dialect');
61
+ }
62
+ if (!dbConfig.dbHost) {
63
+ missing.push('--db-host');
64
+ }
65
+ if (!dbConfig.dbPort) {
66
+ missing.push('--db-port');
67
+ }
68
+ if (!dbConfig.dbDatabase) {
69
+ missing.push('--db-database');
70
+ }
71
+ if (!dbConfig.dbUser) {
72
+ missing.push('--db-user');
73
+ }
74
+ if (!dbConfig.dbPassword) {
75
+ missing.push('--db-password');
76
+ }
77
+ if (missing.length > 0) {
78
+ command.error(formatMissingFieldsMessage(missing, hasEnv));
79
+ }
80
+ const portError = validateTcpPort(dbConfig.dbPort);
81
+ if (portError) {
82
+ command.error(portError);
83
+ }
84
+ }
85
+ async function resolveDbCheckInput(command, flags) {
86
+ const envName = flags.env?.trim() || undefined;
87
+ if (!envName) {
88
+ const dbConfig = resolveDbConfigFromFlags(flags);
89
+ validateDbConfigOrThrow(command, dbConfig, false);
90
+ return {
91
+ dbConfig,
92
+ };
93
+ }
94
+ const runtime = await resolveManagedAppRuntime(envName);
95
+ if (!runtime) {
96
+ command.error(formatMissingManagedAppEnvMessage(envName));
97
+ }
98
+ const envConfig = { ...runtime.env.config };
99
+ if ((runtime.kind === 'local' || runtime.kind === 'docker') && runtime.env.config.builtinDb) {
100
+ const builtinDbConnection = await resolveBuiltinDbConnection(runtime);
101
+ envConfig.dbHost = builtinDbConnection.dbHost;
102
+ envConfig.dbPort = builtinDbConnection.dbPort;
103
+ envConfig.dbDialect = builtinDbConnection.dbDialect;
104
+ }
105
+ const dbConfig = resolveDbConfigFromFlags(flags, envConfig);
106
+ validateDbConfigOrThrow(command, dbConfig, true);
107
+ return {
108
+ envName: runtime.envName,
109
+ kind: runtime.kind,
110
+ runtime: runtime,
111
+ dbConfig,
112
+ };
113
+ }
114
+ function buildConnectionConfigOrThrow(command, dbConfig) {
115
+ const connectionConfig = readExternalDbConnectionConfig(dbConfig);
116
+ if (!connectionConfig) {
117
+ command.error('Unsupported or incomplete database settings for connectivity check.');
118
+ }
119
+ return connectionConfig;
120
+ }
121
+ async function runExplicitDbCheck(command, dbConfig) {
122
+ const connectionConfig = buildConnectionConfigOrThrow(command, dbConfig);
123
+ const address = formatDbCheckAddress(connectionConfig);
124
+ const validationError = await checkExternalDbConnection(connectionConfig);
125
+ return {
126
+ ok: !validationError,
127
+ dialect: connectionConfig.dialect,
128
+ address,
129
+ error: validationError ?? null,
130
+ };
131
+ }
132
+ async function runDockerDbCheck(command, runtime, dbConfig) {
133
+ const connectionConfig = buildConnectionConfigOrThrow(command, dbConfig);
134
+ const config = runtime.env.config ?? {};
135
+ const imageRef = resolveDockerImageRef(config.dockerRegistry, config.downloadVersion, {
136
+ defaultRegistry: DEFAULT_DOCKER_REGISTRY,
137
+ defaultVersion: DEFAULT_DOCKER_VERSION,
138
+ });
139
+ const args = [
140
+ 'run',
141
+ '--rm',
142
+ '--network',
143
+ runtime.dockerNetworkName || runtime.workspaceName,
144
+ ];
145
+ const dockerPlatform = normalizeDockerPlatform(config.dockerPlatform);
146
+ if (dockerPlatform) {
147
+ args.push('--platform', dockerPlatform);
148
+ }
149
+ args.push('--entrypoint', 'nb', imageRef, 'db', 'check', '--db-dialect', connectionConfig.dialect, '--db-host', connectionConfig.host, '--db-port', String(connectionConfig.port), '--db-database', connectionConfig.database, '--db-user', connectionConfig.user, '--db-password', connectionConfig.password, '--json');
150
+ const output = await commandOutput('docker', args, {
151
+ errorName: 'docker run',
152
+ });
153
+ let payload;
154
+ try {
155
+ payload = JSON.parse(output);
156
+ }
157
+ catch {
158
+ command.error(`Failed to parse database check response from Docker: ${output}`);
159
+ }
160
+ const ok = Boolean(payload.ok);
161
+ const dialect = trimValue(payload.dialect) || connectionConfig.dialect;
162
+ const address = trimValue(payload.address) || formatDbCheckAddress(connectionConfig);
163
+ const error = trimValue(payload.error) || null;
164
+ return {
165
+ ok,
166
+ dialect,
167
+ address,
168
+ error,
169
+ };
170
+ }
171
+ async function runDbCheckForRuntime(command, runtime, dbConfig) {
172
+ if (runtime.kind === 'docker') {
173
+ return await runDockerDbCheck(command, runtime, dbConfig);
174
+ }
175
+ if (runtime.kind === 'local') {
176
+ return await runExplicitDbCheck(command, dbConfig);
177
+ }
178
+ command.error(`Env "${runtime.envName}" does not support automatic database connectivity checks.`);
179
+ }
180
+ export default class DbCheck extends Command {
181
+ static description = 'Check whether a database is reachable using the selected env settings or explicit `--db-*` flags.';
182
+ static examples = [
183
+ '<%= config.bin %> <%= command.id %> --env app1',
184
+ '<%= config.bin %> <%= command.id %> --env app1 --db-password new-secret --json',
185
+ '<%= config.bin %> <%= command.id %> --db-dialect postgres --db-host 127.0.0.1 --db-port 5432 --db-database nocobase --db-user nocobase --db-password secret',
186
+ ];
187
+ static flags = {
188
+ env: Flags.string({
189
+ char: 'e',
190
+ description: 'CLI env name to read saved database settings from. Defaults to the current env when omitted',
191
+ }),
192
+ 'db-dialect': Flags.string({
193
+ description: 'Database dialect: postgres, kingbase, mysql, or mariadb.',
194
+ options: ['postgres', 'kingbase', 'mysql', 'mariadb'],
195
+ }),
196
+ 'db-host': Flags.string({
197
+ description: 'Database host name or IP address.',
198
+ }),
199
+ 'db-port': Flags.string({
200
+ description: 'Database TCP port.',
201
+ }),
202
+ 'db-database': Flags.string({
203
+ description: 'Database name.',
204
+ }),
205
+ 'db-user': Flags.string({
206
+ description: 'Database username.',
207
+ }),
208
+ 'db-password': Flags.string({
209
+ description: 'Database password.',
210
+ }),
211
+ json: Flags.boolean({
212
+ description: 'Output the check result as JSON.',
213
+ default: false,
214
+ }),
215
+ };
216
+ async run() {
217
+ const { flags } = await this.parse(DbCheck);
218
+ const input = await resolveDbCheckInput(this, flags);
219
+ const result = input.runtime
220
+ ? await runDbCheckForRuntime(this, input.runtime, input.dbConfig)
221
+ : await runExplicitDbCheck(this, input.dbConfig);
222
+ if (flags.json) {
223
+ this.log(JSON.stringify({
224
+ ok: result.ok,
225
+ env: input.envName,
226
+ kind: input.kind,
227
+ dialect: result.dialect,
228
+ address: result.address,
229
+ error: result.error,
230
+ }, null, 2));
231
+ return;
232
+ }
233
+ if (!result.ok) {
234
+ this.error(result.error ?? 'Database check failed.');
235
+ }
236
+ this.log(input.envName
237
+ ? `Database check passed for env "${input.envName}" (${result.dialect} ${result.address}).`
238
+ : `Database check passed (${result.dialect} ${result.address}).`);
239
+ }
240
+ }