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

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 (214) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +405 -19
  3. package/README.zh-CN.md +355 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +136 -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/destroy.js +225 -0
  15. package/dist/commands/app/down.js +71 -0
  16. package/dist/commands/app/logs.js +114 -0
  17. package/dist/commands/app/restart.js +158 -0
  18. package/dist/commands/app/shared.js +122 -0
  19. package/dist/commands/app/start.js +286 -0
  20. package/dist/commands/app/stop.js +161 -0
  21. package/dist/commands/app/upgrade.js +519 -0
  22. package/dist/commands/backup/create.js +147 -0
  23. package/dist/commands/backup/index.js +20 -0
  24. package/dist/commands/backup/restore.js +105 -0
  25. package/{src/cli.js → dist/commands/build.js} +4 -11
  26. package/dist/commands/config/delete.js +34 -0
  27. package/dist/commands/config/get.js +33 -0
  28. package/dist/commands/config/index.js +20 -0
  29. package/dist/commands/config/list.js +29 -0
  30. package/dist/commands/config/set.js +39 -0
  31. package/dist/commands/db/check.js +240 -0
  32. package/dist/commands/db/logs.js +85 -0
  33. package/dist/commands/db/ps.js +60 -0
  34. package/dist/commands/db/shared.js +96 -0
  35. package/dist/commands/db/start.js +86 -0
  36. package/dist/commands/db/stop.js +71 -0
  37. package/{templates/plugin/src/client/models/index.ts → dist/commands/dev.js} +4 -4
  38. package/{src/commands/locale/react-js-cron/index.js → dist/commands/down.js} +3 -8
  39. package/dist/commands/download.js +13 -0
  40. package/dist/commands/env/add.js +426 -0
  41. package/dist/commands/env/auth.js +189 -0
  42. package/dist/commands/env/current.js +21 -0
  43. package/dist/commands/env/info.js +201 -0
  44. package/dist/commands/env/list.js +44 -0
  45. package/dist/commands/env/remove.js +84 -0
  46. package/dist/commands/env/shared.js +196 -0
  47. package/dist/commands/env/status.js +90 -0
  48. package/dist/commands/env/update.js +74 -0
  49. package/dist/commands/env/use.js +38 -0
  50. package/dist/commands/examples/prompts-stages.js +150 -0
  51. package/dist/commands/examples/prompts-test.js +181 -0
  52. package/dist/commands/init.js +1152 -0
  53. package/dist/commands/install.js +2424 -0
  54. package/dist/commands/license/activate.js +360 -0
  55. package/dist/commands/license/env.js +94 -0
  56. package/dist/commands/license/generate-id.js +108 -0
  57. package/dist/commands/license/id.js +70 -0
  58. package/dist/commands/license/index.js +20 -0
  59. package/dist/commands/license/plugins/clean.js +115 -0
  60. package/dist/commands/license/plugins/index.js +20 -0
  61. package/dist/commands/license/plugins/list.js +64 -0
  62. package/dist/commands/license/plugins/shared.js +331 -0
  63. package/dist/commands/license/plugins/sync.js +314 -0
  64. package/dist/commands/license/shared.js +423 -0
  65. package/dist/commands/license/status.js +64 -0
  66. package/dist/commands/logs.js +12 -0
  67. package/dist/commands/plugin/disable.js +86 -0
  68. package/dist/commands/plugin/enable.js +86 -0
  69. package/dist/commands/plugin/list.js +82 -0
  70. package/dist/commands/pm/disable.js +12 -0
  71. package/dist/commands/pm/enable.js +12 -0
  72. package/dist/commands/pm/list.js +12 -0
  73. package/dist/commands/restart.js +12 -0
  74. package/dist/commands/scaffold/migration.js +38 -0
  75. package/dist/commands/scaffold/plugin.js +37 -0
  76. package/dist/commands/self/check.js +71 -0
  77. package/dist/commands/self/index.js +20 -0
  78. package/dist/commands/self/update.js +95 -0
  79. package/dist/commands/session/id.js +24 -0
  80. package/dist/commands/session/remove.js +57 -0
  81. package/dist/commands/session/setup.js +62 -0
  82. package/dist/commands/skills/check.js +69 -0
  83. package/dist/commands/skills/index.js +20 -0
  84. package/dist/commands/skills/install.js +80 -0
  85. package/dist/commands/skills/remove.js +80 -0
  86. package/dist/commands/skills/update.js +87 -0
  87. package/dist/commands/source/build.js +58 -0
  88. package/dist/commands/source/dev.js +182 -0
  89. package/dist/commands/source/download.js +884 -0
  90. package/dist/commands/source/publish.js +109 -0
  91. package/dist/commands/source/registry/logs.js +70 -0
  92. package/dist/commands/source/registry/start.js +57 -0
  93. package/dist/commands/source/registry/status.js +33 -0
  94. package/dist/commands/source/registry/stop.js +48 -0
  95. package/dist/commands/source/test.js +477 -0
  96. package/dist/commands/start.js +12 -0
  97. package/dist/commands/stop.js +12 -0
  98. package/dist/commands/test.js +12 -0
  99. package/dist/commands/upgrade.js +12 -0
  100. package/dist/commands/v1.js +210 -0
  101. package/dist/generated/command-registry.js +134 -0
  102. package/dist/help/runtime-help.js +23 -0
  103. package/dist/lib/api-client.js +335 -0
  104. package/dist/lib/api-command-compat.js +641 -0
  105. package/dist/lib/app-health.js +132 -0
  106. package/dist/lib/app-managed-resources.js +316 -0
  107. package/dist/lib/app-runtime.js +180 -0
  108. package/dist/lib/auth-store.js +396 -0
  109. package/dist/lib/backup.js +171 -0
  110. package/dist/lib/bootstrap.js +403 -0
  111. package/dist/lib/build-config.js +18 -0
  112. package/dist/lib/builtin-db.js +86 -0
  113. package/dist/lib/cli-config.js +271 -0
  114. package/dist/lib/cli-home.js +47 -0
  115. package/dist/lib/cli-locale.js +141 -0
  116. package/dist/lib/command-discovery.js +39 -0
  117. package/dist/lib/db-connection-check.js +219 -0
  118. package/dist/lib/docker-env-file.js +52 -0
  119. package/dist/lib/docker-image.js +37 -0
  120. package/dist/lib/env-auth.js +952 -0
  121. package/dist/lib/env-config.js +95 -0
  122. package/dist/lib/env-guard.js +62 -0
  123. package/dist/lib/generated-command.js +203 -0
  124. package/dist/lib/http-request.js +49 -0
  125. package/dist/lib/inquirer-theme.js +17 -0
  126. package/dist/lib/inquirer.js +244 -0
  127. package/dist/lib/naming.js +70 -0
  128. package/dist/lib/object-utils.js +76 -0
  129. package/dist/lib/openapi.js +62 -0
  130. package/dist/lib/plugin-storage.js +64 -0
  131. package/dist/lib/post-processors.js +23 -0
  132. package/dist/lib/prompt-catalog-core.js +185 -0
  133. package/dist/lib/prompt-catalog-terminal.js +375 -0
  134. package/{src/index.js → dist/lib/prompt-catalog.js} +2 -6
  135. package/dist/lib/prompt-validators.js +258 -0
  136. package/dist/lib/prompt-web-ui.js +2227 -0
  137. package/dist/lib/resource-command.js +357 -0
  138. package/dist/lib/resource-request.js +104 -0
  139. package/dist/lib/run-npm.js +385 -0
  140. package/dist/lib/runtime-env-vars.js +32 -0
  141. package/dist/lib/runtime-generator.js +498 -0
  142. package/dist/lib/runtime-store.js +56 -0
  143. package/dist/lib/self-manager.js +301 -0
  144. package/dist/lib/session-id.js +17 -0
  145. package/dist/lib/session-integration.js +703 -0
  146. package/dist/lib/session-store.js +118 -0
  147. package/dist/lib/skills-manager.js +436 -0
  148. package/dist/lib/source-publish.js +306 -0
  149. package/dist/lib/source-registry.js +188 -0
  150. package/dist/lib/startup-update.js +285 -0
  151. package/dist/lib/ui.js +158 -0
  152. package/dist/locale/en-US.json +425 -0
  153. package/dist/locale/zh-CN.json +425 -0
  154. package/dist/post-processors/data-modeling.js +84 -0
  155. package/dist/post-processors/data-source-manager.js +138 -0
  156. package/dist/post-processors/index.js +19 -0
  157. package/nocobase-ctl.config.json +388 -0
  158. package/package.json +132 -26
  159. package/LICENSE +0 -661
  160. package/bin/index.js +0 -39
  161. package/nocobase.conf.tpl +0 -95
  162. package/src/commands/benchmark.js +0 -73
  163. package/src/commands/build.js +0 -49
  164. package/src/commands/clean.js +0 -30
  165. package/src/commands/client.js +0 -166
  166. package/src/commands/create-nginx-conf.js +0 -37
  167. package/src/commands/create-plugin.js +0 -33
  168. package/src/commands/dev.js +0 -200
  169. package/src/commands/doc.js +0 -76
  170. package/src/commands/e2e.js +0 -265
  171. package/src/commands/global.js +0 -43
  172. package/src/commands/index.js +0 -45
  173. package/src/commands/instance-id.js +0 -47
  174. package/src/commands/locale/cronstrue.js +0 -122
  175. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  176. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  177. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  178. package/src/commands/locale.js +0 -81
  179. package/src/commands/p-test.js +0 -88
  180. package/src/commands/perf.js +0 -63
  181. package/src/commands/pkg.js +0 -321
  182. package/src/commands/pm2.js +0 -37
  183. package/src/commands/postinstall.js +0 -88
  184. package/src/commands/start.js +0 -148
  185. package/src/commands/tar.js +0 -36
  186. package/src/commands/test-coverage.js +0 -55
  187. package/src/commands/test.js +0 -107
  188. package/src/commands/umi.js +0 -33
  189. package/src/commands/update-deps.js +0 -72
  190. package/src/commands/upgrade.js +0 -47
  191. package/src/commands/view-license-key.js +0 -44
  192. package/src/license.js +0 -76
  193. package/src/logger.js +0 -75
  194. package/src/plugin-generator.js +0 -80
  195. package/src/util.js +0 -517
  196. package/templates/bundle-status.html +0 -338
  197. package/templates/create-app-package.json +0 -39
  198. package/templates/plugin/.npmignore.tpl +0 -2
  199. package/templates/plugin/README.md.tpl +0 -1
  200. package/templates/plugin/client.d.ts +0 -2
  201. package/templates/plugin/client.js +0 -1
  202. package/templates/plugin/package.json.tpl +0 -11
  203. package/templates/plugin/server.d.ts +0 -2
  204. package/templates/plugin/server.js +0 -1
  205. package/templates/plugin/src/client/client.d.ts +0 -249
  206. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  207. package/templates/plugin/src/client/locale.ts +0 -21
  208. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  209. package/templates/plugin/src/index.ts +0 -2
  210. package/templates/plugin/src/locale/en-US.json +0 -1
  211. package/templates/plugin/src/locale/zh-CN.json +0 -1
  212. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  213. package/templates/plugin/src/server/index.ts.tpl +0 -1
  214. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -0,0 +1,80 @@
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 { confirm } from "../../lib/inquirer.js";
11
+ import { setVerboseMode } from '../../lib/ui.js';
12
+ import { installNocoBaseSkills } from '../../lib/skills-manager.js';
13
+ export default class SkillsInstall extends Command {
14
+ static summary = 'Install the NocoBase AI coding skills globally';
15
+ static description = 'Install the NocoBase AI coding skills globally. If they are already installed, this command does not update them.';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %>',
18
+ '<%= config.bin %> <%= command.id %> --yes',
19
+ '<%= config.bin %> <%= command.id %> --json',
20
+ ];
21
+ static flags = {
22
+ yes: Flags.boolean({
23
+ char: 'y',
24
+ description: 'Skip the install confirmation prompt',
25
+ default: false,
26
+ }),
27
+ json: Flags.boolean({
28
+ description: 'Output the result as JSON',
29
+ default: false,
30
+ }),
31
+ verbose: Flags.boolean({
32
+ description: 'Show detailed install output',
33
+ default: false,
34
+ }),
35
+ };
36
+ async run() {
37
+ const { flags } = await this.parse(SkillsInstall);
38
+ setVerboseMode(flags.verbose);
39
+ if (!flags.yes) {
40
+ let confirmed = false;
41
+ try {
42
+ confirmed = await confirm({
43
+ message: 'Install the NocoBase AI coding skills globally?',
44
+ default: true,
45
+ });
46
+ }
47
+ catch {
48
+ return;
49
+ }
50
+ if (!confirmed) {
51
+ return;
52
+ }
53
+ }
54
+ const result = await installNocoBaseSkills({
55
+ verbose: flags.verbose,
56
+ });
57
+ if (flags.json) {
58
+ this.log(JSON.stringify({
59
+ ok: true,
60
+ kind: 'skills',
61
+ action: result.action,
62
+ globalRoot: result.status.globalRoot,
63
+ workspaceRoot: result.status.workspaceRoot,
64
+ installedSkillNames: result.status.installedSkillNames,
65
+ installedVersion: result.status.installedVersion,
66
+ installedRef: result.status.installedRef,
67
+ }, null, 2));
68
+ return;
69
+ }
70
+ if (result.action === 'noop') {
71
+ this.log(flags.verbose
72
+ ? 'NocoBase AI coding skills are already installed globally. Run `nb skills update` to refresh them.'
73
+ : 'NocoBase AI coding skills are already installed globally.');
74
+ return;
75
+ }
76
+ this.log(flags.verbose
77
+ ? 'Installed the NocoBase AI coding skills globally.'
78
+ : 'Installed NocoBase AI coding skills globally.');
79
+ }
80
+ }
@@ -0,0 +1,80 @@
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 { confirm } from "../../lib/inquirer.js";
11
+ import { setVerboseMode } from '../../lib/ui.js';
12
+ import { removeNocoBaseSkills } from '../../lib/skills-manager.js';
13
+ export default class SkillsRemove extends Command {
14
+ static summary = 'Remove the globally installed NocoBase AI coding skills';
15
+ static description = 'Remove the skills installed from nocobase/skills globally. This only removes the skills managed by `nb`.';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %>',
18
+ '<%= config.bin %> <%= command.id %> --yes',
19
+ '<%= config.bin %> <%= command.id %> --json',
20
+ ];
21
+ static flags = {
22
+ yes: Flags.boolean({
23
+ char: 'y',
24
+ description: 'Skip the remove confirmation prompt',
25
+ default: false,
26
+ }),
27
+ json: Flags.boolean({
28
+ description: 'Output the result as JSON',
29
+ default: false,
30
+ }),
31
+ verbose: Flags.boolean({
32
+ description: 'Show detailed remove output',
33
+ default: false,
34
+ }),
35
+ };
36
+ async run() {
37
+ const { flags } = await this.parse(SkillsRemove);
38
+ setVerboseMode(flags.verbose);
39
+ if (!flags.yes) {
40
+ let confirmed = false;
41
+ try {
42
+ confirmed = await confirm({
43
+ message: 'Remove the globally installed NocoBase AI coding skills?',
44
+ default: true,
45
+ });
46
+ }
47
+ catch {
48
+ return;
49
+ }
50
+ if (!confirmed) {
51
+ return;
52
+ }
53
+ }
54
+ const result = await removeNocoBaseSkills({
55
+ verbose: flags.verbose,
56
+ });
57
+ if (flags.json) {
58
+ this.log(JSON.stringify({
59
+ ok: true,
60
+ kind: 'skills',
61
+ action: result.action,
62
+ globalRoot: result.status.globalRoot,
63
+ workspaceRoot: result.status.workspaceRoot,
64
+ installedSkillNames: result.status.installedSkillNames,
65
+ installedVersion: result.status.installedVersion,
66
+ installedRef: result.status.installedRef,
67
+ }, null, 2));
68
+ return;
69
+ }
70
+ if (result.action === 'noop') {
71
+ this.log(flags.verbose
72
+ ? 'NocoBase AI coding skills are not installed globally.'
73
+ : 'NocoBase AI coding skills are not installed.');
74
+ return;
75
+ }
76
+ this.log(flags.verbose
77
+ ? 'Removed the global NocoBase AI coding skills.'
78
+ : 'Removed NocoBase AI coding skills globally.');
79
+ }
80
+ }
@@ -0,0 +1,87 @@
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 { confirm } from "../../lib/inquirer.js";
11
+ import { setVerboseMode } from '../../lib/ui.js';
12
+ import { updateNocoBaseSkills } from '../../lib/skills-manager.js';
13
+ export default class SkillsUpdate extends Command {
14
+ static summary = 'Update the globally installed NocoBase AI coding skills';
15
+ static description = 'Refresh the globally installed NocoBase AI coding skills. This command only updates an existing @nocobase/skills install.';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %>',
18
+ '<%= config.bin %> <%= command.id %> --yes',
19
+ '<%= config.bin %> <%= command.id %> --json',
20
+ ];
21
+ static flags = {
22
+ yes: Flags.boolean({
23
+ char: 'y',
24
+ description: 'Skip the update confirmation prompt',
25
+ default: false,
26
+ }),
27
+ json: Flags.boolean({
28
+ description: 'Output the result as JSON',
29
+ default: false,
30
+ }),
31
+ verbose: Flags.boolean({
32
+ description: 'Show detailed update output',
33
+ default: false,
34
+ }),
35
+ };
36
+ async run() {
37
+ const { flags } = await this.parse(SkillsUpdate);
38
+ setVerboseMode(flags.verbose);
39
+ if (!flags.yes) {
40
+ let confirmed = false;
41
+ try {
42
+ confirmed = await confirm({
43
+ message: 'Update the globally installed NocoBase AI coding skills?',
44
+ default: true,
45
+ });
46
+ }
47
+ catch {
48
+ return;
49
+ }
50
+ if (!confirmed) {
51
+ return;
52
+ }
53
+ }
54
+ const result = await updateNocoBaseSkills({
55
+ verbose: flags.verbose,
56
+ });
57
+ if (flags.json) {
58
+ this.log(JSON.stringify({
59
+ ok: true,
60
+ kind: 'skills',
61
+ action: result.action,
62
+ reason: result.action === 'noop' ? result.reason : undefined,
63
+ globalRoot: result.status.globalRoot,
64
+ workspaceRoot: result.status.workspaceRoot,
65
+ installedSkillNames: result.status.installedSkillNames,
66
+ installedVersion: result.status.installedVersion,
67
+ installedRef: result.status.installedRef,
68
+ }, null, 2));
69
+ return;
70
+ }
71
+ if (result.action === 'noop') {
72
+ if (result.reason === 'not-installed') {
73
+ this.log(flags.verbose
74
+ ? 'NocoBase AI coding skills are not installed globally. Run `nb skills install` first.'
75
+ : 'Skipped skills update because NocoBase AI coding skills are not installed.');
76
+ return;
77
+ }
78
+ this.log(flags.verbose
79
+ ? 'NocoBase AI coding skills are already up to date globally.'
80
+ : 'NocoBase AI coding skills are up to date.');
81
+ return;
82
+ }
83
+ this.log(flags.verbose
84
+ ? 'Updated the global NocoBase AI coding skills.'
85
+ : 'Updated NocoBase AI coding skills globally.');
86
+ }
87
+ }
@@ -0,0 +1,58 @@
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 { runNocoBaseCommand } from "../../lib/run-npm.js";
11
+ import { setVerboseMode } from '../../lib/ui.js';
12
+ export default class SourceBuild extends Command {
13
+ static hidden = false;
14
+ static args = {
15
+ /** Matches `nb source build @nocobase/acl @nocobase/actions` — zero or more package names. */
16
+ packages: Args.string({
17
+ description: 'package names to build',
18
+ multiple: true,
19
+ required: false,
20
+ }),
21
+ };
22
+ static description = 'Run the legacy NocoBase build for the local source project (forwards to `npm run build` in the repo root)';
23
+ static examples = [
24
+ '<%= config.bin %> <%= command.id %>',
25
+ '<%= config.bin %> <%= command.id %> --no-dts',
26
+ '<%= config.bin %> <%= command.id %> --sourcemap',
27
+ '<%= config.bin %> <%= command.id %> @nocobase/acl',
28
+ '<%= config.bin %> <%= command.id %> @nocobase/acl @nocobase/actions',
29
+ ];
30
+ static flags = {
31
+ 'cwd': Flags.string({ description: 'Current working directory', char: 'c', required: false }),
32
+ 'no-dts': Flags.boolean({ description: 'not generate dts' }),
33
+ sourcemap: Flags.boolean({ description: 'generate sourcemap' }),
34
+ verbose: Flags.boolean({ description: 'Show detailed command output', default: false }),
35
+ };
36
+ async run() {
37
+ const { args, flags } = await this.parse(SourceBuild);
38
+ setVerboseMode(flags.verbose);
39
+ const packages = args.packages ?? [];
40
+ const npmArgs = ['build', ...packages];
41
+ if (flags['no-dts']) {
42
+ npmArgs.push('--no-dts');
43
+ }
44
+ if (flags.sourcemap) {
45
+ npmArgs.push('--sourcemap');
46
+ }
47
+ try {
48
+ await runNocoBaseCommand(npmArgs, {
49
+ cwd: flags['cwd'],
50
+ stdio: flags.verbose ? 'inherit' : 'ignore',
51
+ });
52
+ }
53
+ catch (error) {
54
+ const message = error instanceof Error ? error.message : String(error);
55
+ this.error(message);
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,182 @@
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 { ensureCrossEnvConfirmed, hasExplicitEnvSelection } from '../../lib/env-guard.js';
11
+ import { ensureLocalPostinstall } from '../../lib/app-managed-resources.js';
12
+ import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runLocalNocoBaseCommand, } from '../../lib/app-runtime.js';
13
+ import { announceTargetEnv, failTask, printInfo, startTask, succeedTask } from '../../lib/ui.js';
14
+ function formatUnsupportedRuntimeMessage(kind, envName) {
15
+ if (kind === 'docker') {
16
+ return [
17
+ `Can't run dev mode for "${envName}".`,
18
+ 'This env is managed by Docker, but `nb source dev` requires a local npm or Git source directory.',
19
+ `Use \`nb app logs --env ${envName}\` to inspect the Docker app, or create a source-based env with \`nb init --env ${envName} --source git\`.`,
20
+ ].join('\n');
21
+ }
22
+ if (kind === 'ssh') {
23
+ return [
24
+ `Can't run dev mode for "${envName}" yet.`,
25
+ 'SSH env support is reserved but not implemented yet.',
26
+ `Create a source-based env with \`nb init --env ${envName} --source git\` if you want local development mode right now.`,
27
+ ].join('\n');
28
+ }
29
+ return [
30
+ `Can't run dev mode for "${envName}".`,
31
+ 'This env only has an API connection, but `nb source dev` requires a local npm or Git source directory.',
32
+ `Create a source-based env with \`nb init --env ${envName} --source git\` if you want local development mode.`,
33
+ ].join('\n');
34
+ }
35
+ function appUrlForPort(port) {
36
+ const value = String(port ?? '').trim();
37
+ if (!value) {
38
+ return undefined;
39
+ }
40
+ return `http://127.0.0.1:${value}`;
41
+ }
42
+ async function isAppAlreadyRunning(appUrl) {
43
+ if (!appUrl) {
44
+ return false;
45
+ }
46
+ const controller = new AbortController();
47
+ const timeout = setTimeout(() => controller.abort(), 1500);
48
+ try {
49
+ const response = await fetch(`${appUrl}/api/__health_check`, {
50
+ signal: controller.signal,
51
+ });
52
+ const text = await response.text();
53
+ return response.ok && text.trim().toLowerCase() === 'ok';
54
+ }
55
+ catch (_error) {
56
+ return false;
57
+ }
58
+ finally {
59
+ clearTimeout(timeout);
60
+ }
61
+ }
62
+ export default class SourceDev extends Command {
63
+ static hidden = false;
64
+ static description = 'Run NocoBase in local development mode for an npm or Git source env.';
65
+ static examples = [
66
+ '<%= config.bin %> <%= command.id %>',
67
+ '<%= config.bin %> <%= command.id %> --env app1',
68
+ '<%= config.bin %> <%= command.id %> --env app1 --db-sync',
69
+ '<%= config.bin %> <%= command.id %> --env app1 --port 12000',
70
+ '<%= config.bin %> <%= command.id %> --env app1 --client',
71
+ '<%= config.bin %> <%= command.id %> --env app1 --server',
72
+ '<%= config.bin %> <%= command.id %> --env app1 --inspect 9229',
73
+ ];
74
+ static flags = {
75
+ env: Flags.string({
76
+ char: 'e',
77
+ description: 'CLI env name to run dev mode for. Defaults to the current env when omitted',
78
+ required: false,
79
+ }),
80
+ yes: Flags.boolean({
81
+ char: 'y',
82
+ description: 'Confirm using --env when it targets a different env than the current env',
83
+ default: false,
84
+ required: false,
85
+ }),
86
+ 'db-sync': Flags.boolean({
87
+ description: 'Synchronize the database before starting dev mode',
88
+ required: false,
89
+ }),
90
+ port: Flags.string({
91
+ description: 'Development server port',
92
+ char: 'p',
93
+ required: false,
94
+ }),
95
+ client: Flags.boolean({
96
+ description: 'Run client dev mode only',
97
+ char: 'c',
98
+ required: false,
99
+ }),
100
+ server: Flags.boolean({
101
+ description: 'Run server dev mode only',
102
+ char: 's',
103
+ required: false,
104
+ }),
105
+ inspect: Flags.string({
106
+ description: 'Node.js inspect port for server debugging',
107
+ char: 'i',
108
+ required: false,
109
+ }),
110
+ };
111
+ async run() {
112
+ const { flags } = await this.parse(SourceDev);
113
+ const requestedEnv = flags.env?.trim() || undefined;
114
+ if (requestedEnv && hasExplicitEnvSelection(this.argv)) {
115
+ const confirmed = await ensureCrossEnvConfirmed({
116
+ command: this,
117
+ requestedEnv,
118
+ yes: flags.yes,
119
+ });
120
+ if (!confirmed) {
121
+ return;
122
+ }
123
+ }
124
+ const runtime = await resolveManagedAppRuntime(requestedEnv);
125
+ if (!runtime) {
126
+ this.error(formatMissingManagedAppEnvMessage(requestedEnv));
127
+ }
128
+ if (runtime.kind === 'docker' || runtime.kind === 'http' || runtime.kind === 'ssh') {
129
+ this.error(formatUnsupportedRuntimeMessage(runtime.kind, runtime.envName));
130
+ }
131
+ announceTargetEnv(runtime.envName);
132
+ const devPort = flags.port
133
+ || (runtime.env.appPort !== undefined && runtime.env.appPort !== null
134
+ ? String(runtime.env.appPort).trim()
135
+ : undefined);
136
+ const appUrl = appUrlForPort(devPort);
137
+ if (await isAppAlreadyRunning(appUrl)) {
138
+ this.error([
139
+ `NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`,
140
+ flags.port
141
+ ? `Choose another dev port with --port, or stop the running app with \`nb app stop --env ${runtime.envName}\` first.`
142
+ : `Run \`nb app stop --env ${runtime.envName}\` before starting dev mode, or choose another dev port with --port.`,
143
+ ].join('\n'));
144
+ }
145
+ const npmArgs = ['dev', '--rsbuild'];
146
+ if (flags['db-sync']) {
147
+ npmArgs.push('--db-sync');
148
+ }
149
+ if (devPort) {
150
+ npmArgs.push('--port', devPort);
151
+ }
152
+ if (flags.client) {
153
+ npmArgs.push('--client');
154
+ }
155
+ if (flags.server) {
156
+ npmArgs.push('--server');
157
+ }
158
+ if (flags.inspect) {
159
+ npmArgs.push('--inspect', flags.inspect);
160
+ }
161
+ printInfo(`Starting NocoBase dev mode for "${runtime.envName}" from ${runtime.projectRoot}. Press Ctrl+C to stop.`);
162
+ try {
163
+ await ensureLocalPostinstall(runtime, {
164
+ onStartTask: startTask,
165
+ onSucceedTask: succeedTask,
166
+ onFailTask: failTask,
167
+ verbose: true,
168
+ });
169
+ await runLocalNocoBaseCommand(runtime, npmArgs, {
170
+ stdio: 'inherit',
171
+ });
172
+ }
173
+ catch (error) {
174
+ const message = error instanceof Error ? error.message : String(error);
175
+ this.error([
176
+ `Couldn't start dev mode for "${runtime.envName}".`,
177
+ 'Check that dependencies are installed and the saved env settings are valid, then try again.',
178
+ `Details: ${message}`,
179
+ ].join('\n'));
180
+ }
181
+ }
182
+ }