@nocobase/cli 2.1.0-beta.8 → 2.1.0

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 (263) hide show
  1. package/assets/env-proxy/nginx/app.conf.tpl +23 -0
  2. package/assets/env-proxy/nginx/nocobase.conf.tpl +5 -0
  3. package/assets/env-proxy/nginx/snippets/dist-location.conf +5 -0
  4. package/assets/env-proxy/nginx/snippets/gzip.conf +17 -0
  5. package/assets/env-proxy/nginx/snippets/log-format-http.conf +13 -0
  6. package/assets/env-proxy/nginx/snippets/maps-http.conf +14 -0
  7. package/assets/env-proxy/nginx/snippets/mime-types.conf +98 -0
  8. package/assets/env-proxy/nginx/snippets/proxy-location.conf +17 -0
  9. package/assets/env-proxy/nginx/snippets/spa-location.conf +6 -0
  10. package/assets/env-proxy/nginx/snippets/uploads-location.conf +21 -0
  11. package/bin/run.cmd +3 -0
  12. package/bin/run.js +145 -0
  13. package/bin/session-env.js +39 -0
  14. package/dist/commands/api/resource/create.js +15 -0
  15. package/dist/commands/api/resource/destroy.js +15 -0
  16. package/dist/commands/api/resource/get.js +15 -0
  17. package/dist/commands/api/resource/index.js +20 -0
  18. package/dist/commands/api/resource/list.js +16 -0
  19. package/dist/commands/api/resource/query.js +15 -0
  20. package/dist/commands/api/resource/update.js +15 -0
  21. package/dist/commands/app/autostart/disable.js +55 -0
  22. package/dist/commands/app/autostart/enable.js +55 -0
  23. package/dist/commands/app/autostart/list.js +37 -0
  24. package/dist/commands/app/autostart/run.js +84 -0
  25. package/dist/commands/app/autostart/shared.js +49 -0
  26. package/dist/commands/app/destroy.js +234 -0
  27. package/dist/commands/app/down.js +71 -0
  28. package/dist/commands/app/logs.js +115 -0
  29. package/dist/commands/app/restart.js +229 -0
  30. package/dist/commands/app/shared.js +123 -0
  31. package/dist/commands/app/start.js +416 -0
  32. package/dist/commands/app/stop.js +183 -0
  33. package/dist/commands/app/upgrade.js +523 -0
  34. package/dist/commands/backup/create.js +147 -0
  35. package/dist/commands/backup/index.js +20 -0
  36. package/dist/commands/backup/restore.js +105 -0
  37. package/{src/cli.js → dist/commands/build.js} +4 -11
  38. package/dist/commands/config/delete.js +42 -0
  39. package/dist/commands/config/get.js +39 -0
  40. package/dist/commands/config/index.js +20 -0
  41. package/dist/commands/config/list.js +29 -0
  42. package/dist/commands/config/set.js +49 -0
  43. package/dist/commands/db/check.js +240 -0
  44. package/dist/commands/db/logs.js +85 -0
  45. package/dist/commands/db/ps.js +47 -0
  46. package/dist/commands/db/shared.js +96 -0
  47. package/dist/commands/db/start.js +86 -0
  48. package/dist/commands/db/stop.js +71 -0
  49. package/{templates/plugin/src/client/models/index.ts → dist/commands/dev.js} +4 -4
  50. package/{src/commands/locale/react-js-cron/index.js → dist/commands/down.js} +3 -8
  51. package/dist/commands/download.js +13 -0
  52. package/dist/commands/env/add.js +406 -0
  53. package/dist/commands/env/auth.js +189 -0
  54. package/dist/commands/env/current.js +21 -0
  55. package/dist/commands/env/info.js +202 -0
  56. package/dist/commands/env/list.js +43 -0
  57. package/dist/commands/env/remove.js +174 -0
  58. package/dist/commands/env/shared.js +204 -0
  59. package/dist/commands/env/status.js +93 -0
  60. package/dist/commands/env/update.js +448 -0
  61. package/dist/commands/env/use.js +38 -0
  62. package/dist/commands/examples/prompts-stages.js +150 -0
  63. package/dist/commands/examples/prompts-test.js +181 -0
  64. package/dist/commands/init.js +1390 -0
  65. package/dist/commands/install.js +2609 -0
  66. package/dist/commands/license/activate.js +179 -0
  67. package/dist/commands/license/env.js +94 -0
  68. package/dist/commands/license/generate-id.js +108 -0
  69. package/dist/commands/license/id.js +70 -0
  70. package/dist/commands/license/index.js +20 -0
  71. package/dist/commands/license/plugins/clean.js +115 -0
  72. package/dist/commands/license/plugins/index.js +20 -0
  73. package/dist/commands/license/plugins/list.js +64 -0
  74. package/dist/commands/license/plugins/shared.js +382 -0
  75. package/dist/commands/license/plugins/sync.js +314 -0
  76. package/dist/commands/license/shared.js +423 -0
  77. package/dist/commands/license/status.js +64 -0
  78. package/dist/commands/logs.js +12 -0
  79. package/dist/commands/plugin/disable.js +86 -0
  80. package/dist/commands/plugin/enable.js +86 -0
  81. package/dist/commands/plugin/import.js +108 -0
  82. package/dist/commands/plugin/list.js +82 -0
  83. package/dist/commands/pm/disable.js +12 -0
  84. package/dist/commands/pm/enable.js +12 -0
  85. package/dist/commands/pm/list.js +12 -0
  86. package/dist/commands/proxy/caddy/current.js +17 -0
  87. package/dist/commands/proxy/caddy/generate.js +69 -0
  88. package/dist/commands/proxy/caddy/index.js +28 -0
  89. package/dist/commands/proxy/caddy/info.js +31 -0
  90. package/dist/commands/proxy/caddy/reload.js +30 -0
  91. package/dist/commands/proxy/caddy/restart.js +28 -0
  92. package/dist/commands/proxy/caddy/start.js +30 -0
  93. package/dist/commands/proxy/caddy/status.js +19 -0
  94. package/dist/commands/proxy/caddy/stop.js +30 -0
  95. package/dist/commands/proxy/caddy/use.js +26 -0
  96. package/dist/commands/proxy/index.js +28 -0
  97. package/dist/commands/proxy/nginx/current.js +18 -0
  98. package/dist/commands/proxy/nginx/generate.js +68 -0
  99. package/dist/commands/proxy/nginx/index.js +28 -0
  100. package/dist/commands/proxy/nginx/info.js +34 -0
  101. package/dist/commands/proxy/nginx/reload.js +30 -0
  102. package/dist/commands/proxy/nginx/restart.js +28 -0
  103. package/dist/commands/proxy/nginx/start.js +30 -0
  104. package/dist/commands/proxy/nginx/status.js +19 -0
  105. package/dist/commands/proxy/nginx/stop.js +30 -0
  106. package/dist/commands/proxy/nginx/use.js +31 -0
  107. package/dist/commands/restart.js +12 -0
  108. package/dist/commands/revision/create.js +118 -0
  109. package/dist/commands/scaffold/migration.js +38 -0
  110. package/dist/commands/scaffold/plugin.js +37 -0
  111. package/dist/commands/self/check.js +71 -0
  112. package/dist/commands/self/index.js +20 -0
  113. package/dist/commands/self/update.js +152 -0
  114. package/dist/commands/session/id.js +24 -0
  115. package/dist/commands/session/remove.js +57 -0
  116. package/dist/commands/session/setup.js +62 -0
  117. package/dist/commands/skills/check.js +69 -0
  118. package/dist/commands/skills/index.js +20 -0
  119. package/dist/commands/skills/install.js +80 -0
  120. package/dist/commands/skills/remove.js +80 -0
  121. package/dist/commands/skills/update.js +87 -0
  122. package/dist/commands/source/build.js +58 -0
  123. package/dist/commands/source/dev.js +182 -0
  124. package/dist/commands/source/download.js +884 -0
  125. package/dist/commands/source/publish.js +109 -0
  126. package/dist/commands/source/registry/logs.js +70 -0
  127. package/dist/commands/source/registry/start.js +57 -0
  128. package/dist/commands/source/registry/status.js +33 -0
  129. package/dist/commands/source/registry/stop.js +48 -0
  130. package/dist/commands/source/test.js +476 -0
  131. package/dist/commands/start.js +12 -0
  132. package/dist/commands/stop.js +12 -0
  133. package/dist/commands/test.js +12 -0
  134. package/dist/commands/upgrade.js +12 -0
  135. package/dist/commands/v1.js +210 -0
  136. package/dist/generated/command-registry.js +134 -0
  137. package/dist/help/runtime-help.js +23 -0
  138. package/dist/lib/api-client.js +335 -0
  139. package/dist/lib/api-command-compat.js +641 -0
  140. package/dist/lib/app-health.js +139 -0
  141. package/dist/lib/app-managed-resources.js +337 -0
  142. package/dist/lib/app-public-path.js +80 -0
  143. package/dist/lib/app-runtime.js +189 -0
  144. package/dist/lib/auth-store.js +528 -0
  145. package/dist/lib/backup.js +171 -0
  146. package/dist/lib/bootstrap.js +409 -0
  147. package/dist/lib/build-config.js +18 -0
  148. package/dist/lib/builtin-db.js +86 -0
  149. package/dist/lib/cli-config.js +569 -0
  150. package/dist/lib/cli-entry-error.js +52 -0
  151. package/dist/lib/cli-home.js +47 -0
  152. package/dist/lib/cli-locale.js +141 -0
  153. package/dist/lib/command-discovery.js +39 -0
  154. package/dist/lib/command-log.js +284 -0
  155. package/dist/lib/db-connection-check.js +219 -0
  156. package/dist/lib/docker-env-file.js +60 -0
  157. package/dist/lib/docker-image.js +37 -0
  158. package/dist/lib/docker-log-stream.js +45 -0
  159. package/dist/lib/env-auth.js +963 -0
  160. package/dist/lib/env-command-config.js +45 -0
  161. package/dist/lib/env-config.js +108 -0
  162. package/dist/lib/env-guard.js +61 -0
  163. package/dist/lib/env-paths.js +101 -0
  164. package/dist/lib/env-proxy.js +1325 -0
  165. package/dist/lib/generated-command.js +203 -0
  166. package/dist/lib/http-request.js +49 -0
  167. package/dist/lib/inquirer-theme.js +17 -0
  168. package/dist/lib/inquirer.js +243 -0
  169. package/dist/lib/managed-env-file.js +101 -0
  170. package/dist/lib/managed-init-env.js +32 -0
  171. package/dist/lib/naming.js +70 -0
  172. package/dist/lib/object-utils.js +76 -0
  173. package/dist/lib/openapi.js +62 -0
  174. package/dist/lib/plugin-import.js +279 -0
  175. package/dist/lib/plugin-storage.js +64 -0
  176. package/dist/lib/post-processors.js +23 -0
  177. package/dist/lib/prompt-catalog-core.js +186 -0
  178. package/dist/lib/prompt-catalog-terminal.js +374 -0
  179. package/{src/index.js → dist/lib/prompt-catalog.js} +2 -6
  180. package/dist/lib/prompt-validators.js +278 -0
  181. package/dist/lib/prompt-web-ui.js +2234 -0
  182. package/dist/lib/proxy-caddy.js +274 -0
  183. package/dist/lib/proxy-nginx.js +330 -0
  184. package/dist/lib/resource-command.js +357 -0
  185. package/dist/lib/resource-request.js +104 -0
  186. package/dist/lib/run-npm.js +429 -0
  187. package/dist/lib/runtime-env-vars.js +32 -0
  188. package/dist/lib/runtime-generator.js +498 -0
  189. package/dist/lib/runtime-store.js +56 -0
  190. package/dist/lib/self-manager.js +301 -0
  191. package/dist/lib/session-id.js +17 -0
  192. package/dist/lib/session-integration.js +703 -0
  193. package/dist/lib/session-store.js +118 -0
  194. package/dist/lib/skills-manager.js +438 -0
  195. package/dist/lib/source-publish.js +326 -0
  196. package/dist/lib/source-registry.js +188 -0
  197. package/dist/lib/startup-update.js +309 -0
  198. package/dist/lib/ui.js +159 -0
  199. package/dist/locale/en-US.json +526 -0
  200. package/dist/locale/zh-CN.json +526 -0
  201. package/dist/post-processors/data-modeling.js +84 -0
  202. package/dist/post-processors/data-source-manager.js +138 -0
  203. package/dist/post-processors/index.js +19 -0
  204. package/nocobase-ctl.config.json +388 -0
  205. package/package.json +128 -24
  206. package/scripts/build.mjs +34 -0
  207. package/scripts/clean.mjs +9 -0
  208. package/tsconfig.json +19 -0
  209. package/bin/index.js +0 -39
  210. package/nocobase.conf.tpl +0 -95
  211. package/src/commands/benchmark.js +0 -73
  212. package/src/commands/build.js +0 -49
  213. package/src/commands/clean.js +0 -30
  214. package/src/commands/client.js +0 -166
  215. package/src/commands/create-nginx-conf.js +0 -37
  216. package/src/commands/create-plugin.js +0 -33
  217. package/src/commands/dev.js +0 -200
  218. package/src/commands/doc.js +0 -76
  219. package/src/commands/e2e.js +0 -265
  220. package/src/commands/global.js +0 -43
  221. package/src/commands/index.js +0 -45
  222. package/src/commands/instance-id.js +0 -47
  223. package/src/commands/locale/cronstrue.js +0 -122
  224. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  225. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  226. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  227. package/src/commands/locale.js +0 -81
  228. package/src/commands/p-test.js +0 -88
  229. package/src/commands/perf.js +0 -63
  230. package/src/commands/pkg.js +0 -321
  231. package/src/commands/pm2.js +0 -37
  232. package/src/commands/postinstall.js +0 -88
  233. package/src/commands/start.js +0 -148
  234. package/src/commands/tar.js +0 -36
  235. package/src/commands/test-coverage.js +0 -55
  236. package/src/commands/test.js +0 -107
  237. package/src/commands/umi.js +0 -33
  238. package/src/commands/update-deps.js +0 -72
  239. package/src/commands/upgrade.js +0 -47
  240. package/src/commands/view-license-key.js +0 -44
  241. package/src/license.js +0 -76
  242. package/src/logger.js +0 -75
  243. package/src/plugin-generator.js +0 -80
  244. package/src/util.js +0 -517
  245. package/templates/bundle-status.html +0 -338
  246. package/templates/create-app-package.json +0 -39
  247. package/templates/plugin/.npmignore.tpl +0 -2
  248. package/templates/plugin/README.md.tpl +0 -1
  249. package/templates/plugin/client.d.ts +0 -2
  250. package/templates/plugin/client.js +0 -1
  251. package/templates/plugin/package.json.tpl +0 -11
  252. package/templates/plugin/server.d.ts +0 -2
  253. package/templates/plugin/server.js +0 -1
  254. package/templates/plugin/src/client/client.d.ts +0 -249
  255. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  256. package/templates/plugin/src/client/locale.ts +0 -21
  257. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  258. package/templates/plugin/src/index.ts +0 -2
  259. package/templates/plugin/src/locale/en-US.json +0 -1
  260. package/templates/plugin/src/locale/zh-CN.json +0 -1
  261. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  262. package/templates/plugin/src/server/index.ts.tpl +0 -1
  263. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -0,0 +1,68 @@
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 { getNginxProxyDriver, normalizeProxyListenPort, resolveNginxProxyRuntimeContext, writeNginxProxyBundle, } from '../../../lib/proxy-nginx.js';
12
+ import { announceTargetEnv, failTask, startTask, succeedTask } from '../../../lib/ui.js';
13
+ export default class ProxyNginxGenerate extends Command {
14
+ static summary = 'Generate nginx proxy files for one managed env';
15
+ static examples = [
16
+ '<%= config.bin %> proxy nginx generate --env app1 --host app1.example.com',
17
+ '<%= config.bin %> proxy nginx generate --env app1 --host app1.example.com --port 8080',
18
+ ];
19
+ static flags = {
20
+ env: Flags.string({
21
+ char: 'e',
22
+ description: 'CLI env name to generate proxy files for',
23
+ required: true,
24
+ }),
25
+ host: Flags.string({
26
+ description: 'Host exposed by the nginx entry config, such as example.com or localhost',
27
+ }),
28
+ port: Flags.string({
29
+ description: 'Port exposed by the nginx entry config, not the upstream NocoBase app port',
30
+ }),
31
+ };
32
+ async run() {
33
+ const { flags } = await this.parse(ProxyNginxGenerate);
34
+ const requestedEnv = flags.env?.trim() || undefined;
35
+ const requestedPort = flags.port?.trim() || undefined;
36
+ const normalizedPort = normalizeProxyListenPort(requestedPort);
37
+ if (requestedPort && !normalizedPort) {
38
+ this.error(`Invalid proxy entry port "${requestedPort}". Use an integer between 1 and 65535.`);
39
+ }
40
+ const runtime = await resolveManagedAppRuntime(requestedEnv);
41
+ if (!runtime) {
42
+ this.error(formatMissingManagedAppEnvMessage(requestedEnv));
43
+ }
44
+ if (runtime.kind === 'http') {
45
+ this.error(`Can't generate an nginx proxy config for "${runtime.envName}" from this machine because the env only has an API connection.`);
46
+ }
47
+ if (runtime.kind === 'ssh') {
48
+ this.error(`Can't generate an nginx proxy config for "${runtime.envName}" yet because SSH envs are not implemented.`);
49
+ }
50
+ const driver = await getNginxProxyDriver();
51
+ const runtimeContext = await resolveNginxProxyRuntimeContext();
52
+ announceTargetEnv(runtime.envName);
53
+ startTask(`Generating nginx proxy config for env "${runtime.envName}" with the ${driver} driver...`);
54
+ try {
55
+ const { bundle, status } = await writeNginxProxyBundle(runtime, {
56
+ host: flags.host?.trim() || undefined,
57
+ port: normalizedPort,
58
+ }, runtimeContext);
59
+ succeedTask(status === 'created'
60
+ ? `Saved nginx proxy files for env "${runtime.envName}" under ${bundle.entryDir}, and created editable app entry config at ${bundle.appConfigPath}.`
61
+ : `Saved nginx proxy files for env "${runtime.envName}" under ${bundle.entryDir}, and refreshed editable app entry config at ${bundle.appConfigPath}.`);
62
+ }
63
+ catch (error) {
64
+ failTask(`Failed to generate nginx proxy config for env "${runtime.envName}".`);
65
+ this.error(error instanceof Error ? error.message : String(error));
66
+ }
67
+ }
68
+ }
@@ -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 { Command, loadHelpClass } from '@oclif/core';
10
+ export default class ProxyNginx extends Command {
11
+ static summary = 'Manage nginx proxy generation and runtime selection';
12
+ static examples = [
13
+ '<%= config.bin %> proxy nginx current',
14
+ '<%= config.bin %> proxy nginx use local',
15
+ '<%= config.bin %> proxy nginx generate --env app1 --host app1.example.com',
16
+ '<%= config.bin %> proxy nginx start',
17
+ '<%= config.bin %> proxy nginx status',
18
+ '<%= config.bin %> proxy nginx info',
19
+ ];
20
+ async run() {
21
+ await this.parse(ProxyNginx);
22
+ const Help = await loadHelpClass(this.config);
23
+ await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
24
+ this.id ?? 'proxy nginx',
25
+ ...this.argv,
26
+ ]);
27
+ }
28
+ }
@@ -0,0 +1,34 @@
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 { getCliConfigValue } from '../../../lib/cli-config.js';
11
+ import { mapProxyPathFromCliRoot, resolveEnvProxyMainOutputPath, resolveEnvProxyNginxSnippetsOutputDir, } from '../../../lib/env-proxy.js';
12
+ import { formatNginxProxyInfoLines, resolveNginxProxyContainerName, resolveNginxProxyImage, resolveNginxProxyRuntimeContext, } from '../../../lib/proxy-nginx.js';
13
+ export default class ProxyNginxInfo extends Command {
14
+ static summary = 'Show current nginx proxy driver and generated path info';
15
+ async run() {
16
+ await this.parse(ProxyNginxInfo);
17
+ const runtimeContext = await resolveNginxProxyRuntimeContext();
18
+ const lines = formatNginxProxyInfoLines({
19
+ driver: runtimeContext.driver,
20
+ configFile: await mapProxyPathFromCliRoot(resolveEnvProxyMainOutputPath(), {
21
+ runtimeCliRoot: runtimeContext.runtimeCliRoot,
22
+ }),
23
+ snippetsDir: await mapProxyPathFromCliRoot(resolveEnvProxyNginxSnippetsOutputDir(), {
24
+ runtimeCliRoot: runtimeContext.runtimeCliRoot,
25
+ }),
26
+ upstreamHost: runtimeContext.upstreamHost,
27
+ nginxBinary: await getCliConfigValue('bin.nginx'),
28
+ runtimeRoot: runtimeContext.runtimeCliRoot,
29
+ containerName: await resolveNginxProxyContainerName(),
30
+ image: resolveNginxProxyImage(),
31
+ });
32
+ this.log(lines.join('\n'));
33
+ }
34
+ }
@@ -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 { Command } from '@oclif/core';
10
+ import { getNginxProxyDriver, reloadNginxProxy, resolveNginxProxyRuntimeContext } from '../../../lib/proxy-nginx.js';
11
+ import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
12
+ export default class ProxyNginxReload extends Command {
13
+ static summary = 'Reload the managed nginx proxy';
14
+ async run() {
15
+ await this.parse(ProxyNginxReload);
16
+ const driver = await getNginxProxyDriver();
17
+ const runtimeContext = await resolveNginxProxyRuntimeContext();
18
+ startTask(`Reloading nginx proxy with the ${driver} driver...`);
19
+ try {
20
+ const result = await reloadNginxProxy(runtimeContext);
21
+ succeedTask(result === 'started'
22
+ ? `Nginx proxy started with the ${driver} driver using the latest config.`
23
+ : `Nginx proxy reloaded with the ${driver} driver.`);
24
+ }
25
+ catch (error) {
26
+ failTask(`Failed to reload nginx proxy with the ${driver} driver.`);
27
+ this.error(error instanceof Error ? error.message : String(error));
28
+ }
29
+ }
30
+ }
@@ -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 { Command } from '@oclif/core';
10
+ import { getNginxProxyDriver, resolveNginxProxyRuntimeContext, restartNginxProxy } from '../../../lib/proxy-nginx.js';
11
+ import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
12
+ export default class ProxyNginxRestart extends Command {
13
+ static summary = 'Restart the managed nginx proxy';
14
+ async run() {
15
+ await this.parse(ProxyNginxRestart);
16
+ const driver = await getNginxProxyDriver();
17
+ const runtimeContext = await resolveNginxProxyRuntimeContext();
18
+ startTask(`Restarting nginx proxy with the ${driver} driver...`);
19
+ try {
20
+ await restartNginxProxy(runtimeContext);
21
+ succeedTask(`Nginx proxy restarted with the ${driver} driver.`);
22
+ }
23
+ catch (error) {
24
+ failTask(`Failed to restart nginx proxy with the ${driver} driver.`);
25
+ this.error(error instanceof Error ? error.message : String(error));
26
+ }
27
+ }
28
+ }
@@ -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 { Command } from '@oclif/core';
10
+ import { getNginxProxyDriver, resolveNginxProxyRuntimeContext, startNginxProxy } from '../../../lib/proxy-nginx.js';
11
+ import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
12
+ export default class ProxyNginxStart extends Command {
13
+ static summary = 'Start the managed nginx proxy';
14
+ async run() {
15
+ await this.parse(ProxyNginxStart);
16
+ const driver = await getNginxProxyDriver();
17
+ const runtimeContext = await resolveNginxProxyRuntimeContext();
18
+ startTask(`Starting nginx proxy with the ${driver} driver...`);
19
+ try {
20
+ const result = await startNginxProxy(runtimeContext);
21
+ succeedTask(result === 'already-running'
22
+ ? `Nginx proxy is already running with the ${driver} driver.`
23
+ : `Nginx proxy started with the ${driver} driver.`);
24
+ }
25
+ catch (error) {
26
+ failTask(`Failed to start nginx proxy with the ${driver} driver.`);
27
+ this.error(error instanceof Error ? error.message : String(error));
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,19 @@
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 { formatNginxProxyStatusLines, getNginxProxyStatus, resolveNginxProxyRuntimeContext, } from '../../../lib/proxy-nginx.js';
11
+ export default class ProxyNginxStatus extends Command {
12
+ static summary = 'Show the current nginx proxy runtime status';
13
+ async run() {
14
+ await this.parse(ProxyNginxStatus);
15
+ const runtimeContext = await resolveNginxProxyRuntimeContext();
16
+ const status = await getNginxProxyStatus(runtimeContext);
17
+ this.log(formatNginxProxyStatusLines(status).join('\n'));
18
+ }
19
+ }
@@ -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 { Command } from '@oclif/core';
10
+ import { getNginxProxyDriver, resolveNginxProxyRuntimeContext, stopNginxProxy } from '../../../lib/proxy-nginx.js';
11
+ import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
12
+ export default class ProxyNginxStop extends Command {
13
+ static summary = 'Stop the managed nginx proxy';
14
+ async run() {
15
+ await this.parse(ProxyNginxStop);
16
+ const driver = await getNginxProxyDriver();
17
+ const runtimeContext = await resolveNginxProxyRuntimeContext();
18
+ startTask(`Stopping nginx proxy with the ${driver} driver...`);
19
+ try {
20
+ const result = await stopNginxProxy(runtimeContext);
21
+ succeedTask(result === 'already-stopped'
22
+ ? `Nginx proxy is already stopped with the ${driver} driver.`
23
+ : `Nginx proxy stopped with the ${driver} driver.`);
24
+ }
25
+ catch (error) {
26
+ failTask(`Failed to stop nginx proxy with the ${driver} driver.`);
27
+ this.error(error instanceof Error ? error.message : String(error));
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,31 @@
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 { NGINX_PROXY_DRIVER_OPTIONS, normalizeNginxProxyDriver } from '../../../lib/cli-config.js';
11
+ import { setNginxProxyDriver } from '../../../lib/proxy-nginx.js';
12
+ export default class ProxyNginxUse extends Command {
13
+ static summary = 'Choose whether nginx runs locally or in Docker';
14
+ static examples = ['<%= config.bin %> proxy nginx use local', '<%= config.bin %> proxy nginx use docker'];
15
+ static args = {
16
+ driver: Args.string({
17
+ description: 'Nginx runtime driver',
18
+ required: true,
19
+ options: [...NGINX_PROXY_DRIVER_OPTIONS],
20
+ }),
21
+ };
22
+ async run() {
23
+ const { args } = await this.parse(ProxyNginxUse);
24
+ const driver = normalizeNginxProxyDriver(args.driver);
25
+ if (!driver) {
26
+ this.error(`Unsupported nginx driver "${args.driver}". Use one of: ${NGINX_PROXY_DRIVER_OPTIONS.join(', ')}`);
27
+ }
28
+ const saved = await setNginxProxyDriver(driver);
29
+ this.log(saved);
30
+ }
31
+ }
@@ -0,0 +1,12 @@
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 AppRestart from './app/restart.js';
10
+ export default class Restart extends AppRestart {
11
+ static hidden = true;
12
+ }
@@ -0,0 +1,118 @@
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 { executeRawApiRequest } from '../../lib/api-client.js';
11
+ import { ensureCrossEnvConfirmed } from '../../lib/env-guard.js';
12
+ const VERSION_CONTROL_PLUGIN_PACKAGE = '@nocobase/plugin-version-control';
13
+ function isRecord(value) {
14
+ return typeof value === 'object' && value !== null;
15
+ }
16
+ function extractPluginList(data) {
17
+ const list = Array.isArray(data) ? data : isRecord(data) && Array.isArray(data.data) ? data.data : [];
18
+ return list.filter(isRecord).map((item) => ({
19
+ packageName: typeof item.packageName === 'string' ? item.packageName : undefined,
20
+ enabled: typeof item.enabled === 'boolean' ? item.enabled : undefined,
21
+ }));
22
+ }
23
+ export default class RevisionCreate extends Command {
24
+ static summary = 'Save the current NocoBase build as a restorable revision';
25
+ static examples = [
26
+ '<%= config.bin %> <%= command.id %> "description here"',
27
+ '<%= config.bin %> <%= command.id %> --env app1 "description here"',
28
+ ];
29
+ static args = {
30
+ description: Args.string({
31
+ required: true,
32
+ description: 'Revision description, up to 2000 characters.',
33
+ }),
34
+ };
35
+ static flags = {
36
+ 'api-base-url': Flags.string({
37
+ description: 'NocoBase API base URL, for example http://localhost:13000/api',
38
+ }),
39
+ env: Flags.string({
40
+ char: 'e',
41
+ description: 'Environment name',
42
+ }),
43
+ role: Flags.string({
44
+ description: 'Role override, sent as X-Role',
45
+ }),
46
+ token: Flags.string({
47
+ char: 't',
48
+ description: 'API key override',
49
+ }),
50
+ yes: Flags.boolean({
51
+ char: 'y',
52
+ description: 'Confirm using --env when it targets a different env than the current env',
53
+ default: false,
54
+ }),
55
+ 'json-output': Flags.boolean({
56
+ char: 'j',
57
+ description: 'Print raw JSON response',
58
+ default: false,
59
+ allowNo: true,
60
+ }),
61
+ };
62
+ async run() {
63
+ const { args, flags } = await this.parse(RevisionCreate);
64
+ const description = args.description;
65
+ if (description.length > 2000) {
66
+ this.error('Description length should not be over 2000');
67
+ }
68
+ const confirmed = await ensureCrossEnvConfirmed({
69
+ command: this,
70
+ requestedEnv: flags.env,
71
+ yes: flags.yes,
72
+ });
73
+ if (!confirmed) {
74
+ return;
75
+ }
76
+ const pluginListResponse = await executeRawApiRequest({
77
+ envName: flags.env,
78
+ baseUrl: flags['api-base-url'],
79
+ role: flags.role,
80
+ token: flags.token,
81
+ method: 'GET',
82
+ path: '/pm:list',
83
+ query: {
84
+ mode: 'summary',
85
+ },
86
+ });
87
+ if (!pluginListResponse.ok) {
88
+ this.error(`Failed to check plugin status with status ${pluginListResponse.status}\n${JSON.stringify(pluginListResponse.data, null, 2)}`);
89
+ }
90
+ const versionControlPlugin = extractPluginList(pluginListResponse.data).find((plugin) => plugin.packageName === VERSION_CONTROL_PLUGIN_PACKAGE);
91
+ if (!versionControlPlugin?.enabled) {
92
+ this.error(`The ${VERSION_CONTROL_PLUGIN_PACKAGE} plugin is not enabled. Enable it first with \`nb plugin enable ${VERSION_CONTROL_PLUGIN_PACKAGE}\`.`);
93
+ }
94
+ const response = await executeRawApiRequest({
95
+ envName: flags.env,
96
+ baseUrl: flags['api-base-url'],
97
+ role: flags.role,
98
+ token: flags.token,
99
+ method: 'POST',
100
+ path: '/app:publishEvent',
101
+ body: {
102
+ plugin: 'plugin-version-control',
103
+ command: 'revision:create',
104
+ payload: {
105
+ description,
106
+ },
107
+ },
108
+ });
109
+ if (!response.ok) {
110
+ this.error(`Request failed with status ${response.status}\n${JSON.stringify(response.data, null, 2)}`);
111
+ }
112
+ if (flags['json-output']) {
113
+ this.log(JSON.stringify(response.data, null, 2));
114
+ return;
115
+ }
116
+ this.log('Revision created successfully');
117
+ }
118
+ }
@@ -0,0 +1,38 @@
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
+ export default class ScaffoldMigration extends Command {
12
+ static args = {
13
+ name: Args.string({ description: 'migration name', required: true }),
14
+ };
15
+ static description = 'Generate a plugin migration file.';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %> migration-name --pkg @nocobase/plugin-acl',
18
+ '<%= config.bin %> <%= command.id %> migration-name --pkg @nocobase/plugin-acl --on afterLoad',
19
+ ];
20
+ static flags = {
21
+ pkg: Flags.string({ description: 'plugin package name', required: true }),
22
+ on: Flags.string({ description: 'on', required: false, options: ['beforeLoad', 'afterSync', 'afterLoad'] }),
23
+ };
24
+ async run() {
25
+ const { args, flags } = await this.parse(ScaffoldMigration);
26
+ const npmArgs = ['create-migration', args.name, '--pkg', flags.pkg];
27
+ if (flags.on) {
28
+ npmArgs.push('--on', flags.on);
29
+ }
30
+ try {
31
+ await runNocoBaseCommand(npmArgs, { env: { LOGGER_SILENT: 'true' } });
32
+ }
33
+ catch (error) {
34
+ const message = error instanceof Error ? error.message : String(error);
35
+ this.error(message);
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,37 @@
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
+ export default class ScaffoldPlugin extends Command {
12
+ static args = {
13
+ pkg: Args.string({ description: 'plugin package name', required: true }),
14
+ };
15
+ static description = 'Generate a NocoBase plugin scaffold.';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %> @nocobase-example/plugin-hello',
18
+ '<%= config.bin %> <%= command.id %> @nocobase-example/plugin-hello --force-recreate',
19
+ ];
20
+ static flags = {
21
+ 'force-recreate': Flags.boolean({ description: 'Force recreate the plugin', char: 'f', required: false }),
22
+ };
23
+ async run() {
24
+ const { args, flags } = await this.parse(ScaffoldPlugin);
25
+ const npmArgs = ['pm', 'create', args.pkg];
26
+ if (flags['force-recreate']) {
27
+ npmArgs.push('--force-recreate');
28
+ }
29
+ try {
30
+ await runNocoBaseCommand(npmArgs, { env: { LOGGER_SILENT: 'true' } });
31
+ }
32
+ catch (error) {
33
+ const message = error instanceof Error ? error.message : String(error);
34
+ this.error(message);
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Command, Flags } from '@oclif/core';
10
+ import { getRecommendedSelfUpdateCommand, inspectSelfStatus, } from '../../lib/self-manager.js';
11
+ import { printInfo, renderTable } from '../../lib/ui.js';
12
+ export default class SelfCheck extends Command {
13
+ static summary = 'Check the installed NocoBase CLI version and self-update support';
14
+ static description = 'Inspect the current NocoBase CLI install, resolve the latest version for the selected channel, and report whether automatic self-update is supported.';
15
+ static examples = [
16
+ '<%= config.bin %> <%= command.id %>',
17
+ '<%= config.bin %> <%= command.id %> --channel beta',
18
+ '<%= config.bin %> <%= command.id %> --json',
19
+ ];
20
+ static flags = {
21
+ channel: Flags.string({
22
+ description: 'Release channel to compare against. Defaults to the current CLI channel.',
23
+ options: ['auto', 'latest', 'beta', 'alpha'],
24
+ default: 'auto',
25
+ }),
26
+ json: Flags.boolean({
27
+ description: 'Output the result as JSON',
28
+ default: false,
29
+ }),
30
+ };
31
+ async run() {
32
+ const { flags } = await this.parse(SelfCheck);
33
+ const status = await inspectSelfStatus({
34
+ channel: flags.channel,
35
+ });
36
+ if (flags.json) {
37
+ this.log(JSON.stringify({
38
+ ok: true,
39
+ kind: 'self',
40
+ packageName: status.packageName,
41
+ currentVersion: status.currentVersion,
42
+ latestVersion: status.latestVersion,
43
+ channel: status.channel,
44
+ updateAvailable: status.updateAvailable,
45
+ installMethod: status.installMethod,
46
+ updatable: status.updatable,
47
+ updateBlockedReason: status.updateBlockedReason,
48
+ recommendedCommand: getRecommendedSelfUpdateCommand(status),
49
+ registryError: status.registryError,
50
+ }, null, 2));
51
+ return;
52
+ }
53
+ this.log(renderTable(['Field', 'Value'], [
54
+ ['Current version', status.currentVersion || 'unknown'],
55
+ ['Latest version', status.latestVersion || 'unknown'],
56
+ ['Channel', status.channel],
57
+ ['Install method', status.installMethod],
58
+ ['Auto-update', status.updatable ? 'supported' : 'not supported'],
59
+ ['Update available', status.updateAvailable ? 'yes' : 'no'],
60
+ ]));
61
+ if (status.updateAvailable && status.updatable) {
62
+ printInfo('Run `nb self update`.');
63
+ }
64
+ else if (status.updateAvailable && status.updateBlockedReason) {
65
+ printInfo(status.updateBlockedReason);
66
+ }
67
+ if (status.registryError) {
68
+ printInfo(`Version check warning: ${status.registryError}`);
69
+ }
70
+ }
71
+ }
@@ -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 Self extends Command {
11
+ static summary = 'Inspect or update the NocoBase CLI itself';
12
+ async run() {
13
+ await this.parse(Self);
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 ?? 'self',
17
+ ...this.argv,
18
+ ]);
19
+ }
20
+ }