@nocobase/cli 2.1.0-beta.15 → 2.1.0-beta.16

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 (132) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +307 -63
  3. package/README.zh-CN.md +332 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +114 -0
  6. package/dist/commands/api/resource/create.js +15 -0
  7. package/dist/commands/api/resource/destroy.js +15 -0
  8. package/dist/commands/api/resource/get.js +15 -0
  9. package/dist/commands/api/resource/index.js +20 -0
  10. package/dist/commands/api/resource/list.js +16 -0
  11. package/dist/commands/api/resource/query.js +15 -0
  12. package/dist/commands/api/resource/update.js +15 -0
  13. package/dist/commands/build.js +57 -0
  14. package/dist/commands/db/logs.js +85 -0
  15. package/dist/commands/db/ps.js +60 -0
  16. package/dist/commands/db/shared.js +81 -0
  17. package/dist/commands/db/start.js +70 -0
  18. package/dist/commands/db/stop.js +70 -0
  19. package/dist/commands/dev.js +149 -0
  20. package/dist/commands/down.js +193 -0
  21. package/dist/commands/download.js +743 -0
  22. package/dist/commands/env/add.js +327 -0
  23. package/dist/commands/env/auth.js +62 -0
  24. package/dist/commands/env/list.js +41 -0
  25. package/dist/commands/env/remove.js +65 -0
  26. package/dist/commands/env/update.js +73 -0
  27. package/dist/commands/env/use.js +36 -0
  28. package/dist/commands/init.js +806 -0
  29. package/dist/commands/install.js +1840 -0
  30. package/dist/commands/logs.js +90 -0
  31. package/dist/commands/pm/disable.js +63 -0
  32. package/dist/commands/pm/enable.js +63 -0
  33. package/dist/commands/pm/list.js +54 -0
  34. package/dist/commands/prompts-stages.js +150 -0
  35. package/dist/commands/prompts-test.js +181 -0
  36. package/dist/commands/ps.js +116 -0
  37. package/dist/commands/scaffold/migration.js +38 -0
  38. package/dist/commands/scaffold/plugin.js +37 -0
  39. package/dist/commands/start.js +211 -0
  40. package/dist/commands/stop.js +90 -0
  41. package/dist/commands/upgrade.js +583 -0
  42. package/dist/generated/command-registry.js +133 -0
  43. package/dist/help/runtime-help.js +20 -0
  44. package/dist/lib/api-client.js +243 -0
  45. package/dist/lib/app-runtime.js +142 -0
  46. package/dist/lib/auth-store.js +241 -0
  47. package/dist/lib/bootstrap.js +387 -0
  48. package/dist/lib/build-config.js +10 -0
  49. package/dist/lib/cli-home.js +30 -0
  50. package/dist/lib/cli-locale.js +115 -0
  51. package/dist/lib/command-discovery.js +39 -0
  52. package/dist/lib/env-auth.js +872 -0
  53. package/dist/lib/generated-command.js +142 -0
  54. package/dist/lib/naming.js +70 -0
  55. package/dist/lib/openapi.js +62 -0
  56. package/dist/lib/post-processors.js +23 -0
  57. package/dist/lib/prompt-catalog.js +574 -0
  58. package/dist/lib/prompt-validators.js +185 -0
  59. package/dist/lib/prompt-web-ui.js +2061 -0
  60. package/dist/lib/resource-command.js +335 -0
  61. package/dist/lib/resource-request.js +104 -0
  62. package/dist/lib/run-npm.js +123 -0
  63. package/dist/lib/runtime-generator.js +419 -0
  64. package/dist/lib/runtime-store.js +56 -0
  65. package/dist/lib/ui.js +175 -0
  66. package/dist/locale/en-US.json +282 -0
  67. package/dist/locale/zh-CN.json +282 -0
  68. package/dist/post-processors/data-modeling.js +66 -0
  69. package/dist/post-processors/data-source-manager.js +114 -0
  70. package/dist/post-processors/index.js +19 -0
  71. package/nocobase-ctl.config.json +287 -0
  72. package/package.json +52 -25
  73. package/LICENSE +0 -201
  74. package/bin/index.js +0 -39
  75. package/nocobase.conf.tpl +0 -95
  76. package/src/cli.js +0 -19
  77. package/src/commands/benchmark.js +0 -73
  78. package/src/commands/build.js +0 -49
  79. package/src/commands/clean.js +0 -30
  80. package/src/commands/client.js +0 -166
  81. package/src/commands/create-nginx-conf.js +0 -37
  82. package/src/commands/create-plugin.js +0 -33
  83. package/src/commands/dev.js +0 -200
  84. package/src/commands/doc.js +0 -76
  85. package/src/commands/e2e.js +0 -265
  86. package/src/commands/global.js +0 -43
  87. package/src/commands/index.js +0 -45
  88. package/src/commands/instance-id.js +0 -47
  89. package/src/commands/locale/cronstrue.js +0 -122
  90. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  91. package/src/commands/locale/react-js-cron/index.js +0 -17
  92. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  93. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  94. package/src/commands/locale.js +0 -81
  95. package/src/commands/p-test.js +0 -88
  96. package/src/commands/perf.js +0 -63
  97. package/src/commands/pkg.js +0 -321
  98. package/src/commands/pm2.js +0 -37
  99. package/src/commands/postinstall.js +0 -88
  100. package/src/commands/start.js +0 -148
  101. package/src/commands/tar.js +0 -36
  102. package/src/commands/test-coverage.js +0 -55
  103. package/src/commands/test.js +0 -107
  104. package/src/commands/umi.js +0 -33
  105. package/src/commands/update-deps.js +0 -72
  106. package/src/commands/upgrade.js +0 -47
  107. package/src/commands/view-license-key.js +0 -44
  108. package/src/index.js +0 -14
  109. package/src/license.js +0 -76
  110. package/src/logger.js +0 -75
  111. package/src/plugin-generator.js +0 -80
  112. package/src/util.js +0 -517
  113. package/templates/bundle-status.html +0 -338
  114. package/templates/create-app-package.json +0 -39
  115. package/templates/plugin/.npmignore.tpl +0 -2
  116. package/templates/plugin/README.md.tpl +0 -1
  117. package/templates/plugin/client.d.ts +0 -2
  118. package/templates/plugin/client.js +0 -1
  119. package/templates/plugin/package.json.tpl +0 -11
  120. package/templates/plugin/server.d.ts +0 -2
  121. package/templates/plugin/server.js +0 -1
  122. package/templates/plugin/src/client/client.d.ts +0 -249
  123. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  124. package/templates/plugin/src/client/locale.ts +0 -21
  125. package/templates/plugin/src/client/models/index.ts +0 -12
  126. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  127. package/templates/plugin/src/index.ts +0 -2
  128. package/templates/plugin/src/locale/en-US.json +0 -1
  129. package/templates/plugin/src/locale/zh-CN.json +0 -1
  130. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  131. package/templates/plugin/src/server/index.ts.tpl +0 -1
  132. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -0,0 +1,193 @@
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 fsp from 'node:fs/promises';
11
+ import os from 'node:os';
12
+ import path from 'node:path';
13
+ import { buildDockerDbContainerName, formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runLocalNocoBaseCommand, } from '../lib/app-runtime.js';
14
+ import { removeEnv } from '../lib/auth-store.js';
15
+ import { commandSucceeds, run } from '../lib/run-npm.js';
16
+ import { confirmAction, failTask, isInteractiveTerminal, printInfo, startTask, succeedTask, } from '../lib/ui.js';
17
+ function resolveConfiguredPath(value) {
18
+ const text = String(value ?? '').trim();
19
+ if (!text) {
20
+ return undefined;
21
+ }
22
+ return path.isAbsolute(text) ? text : path.resolve(process.cwd(), text);
23
+ }
24
+ function assertSafeRemovalPath(target, label) {
25
+ const resolved = path.resolve(target);
26
+ const cwd = path.resolve(process.cwd());
27
+ const home = path.resolve(os.homedir());
28
+ const root = path.parse(resolved).root;
29
+ if (resolved === root || resolved === cwd || resolved === home) {
30
+ throw new Error(`Refusing to remove ${label} at "${resolved}" because it is too broad.`);
31
+ }
32
+ }
33
+ async function removePathIfExists(target, label) {
34
+ const resolved = path.resolve(target);
35
+ assertSafeRemovalPath(resolved, label);
36
+ await fsp.rm(resolved, { recursive: true, force: true });
37
+ }
38
+ async function dockerContainerExists(containerName) {
39
+ return await commandSucceeds('docker', ['container', 'inspect', containerName]);
40
+ }
41
+ async function removeDockerContainerIfExists(containerName) {
42
+ if (!(await dockerContainerExists(containerName))) {
43
+ return 'missing';
44
+ }
45
+ await run('docker', ['rm', '-f', containerName], {
46
+ errorName: 'docker rm',
47
+ stdio: 'ignore',
48
+ });
49
+ return 'removed';
50
+ }
51
+ function builtinDbContainerName(runtime) {
52
+ if (!runtime.env.config.builtinDb) {
53
+ return undefined;
54
+ }
55
+ const dbDialect = String(runtime.env.config.dbDialect ?? 'postgres').trim() || 'postgres';
56
+ const workspaceName = runtime.workspaceName;
57
+ return buildDockerDbContainerName(runtime.envName, dbDialect, workspaceName);
58
+ }
59
+ async function confirmRemoveData(envName, yes) {
60
+ if (yes) {
61
+ return true;
62
+ }
63
+ if (!isInteractiveTerminal()) {
64
+ throw new Error(`Refusing to remove user data for "${envName}" without confirmation. Re-run with --yes only if you are sure.`);
65
+ }
66
+ return await confirmAction(`Delete storage and managed database data for "${envName}"? This cannot be undone.`, { defaultValue: false });
67
+ }
68
+ function formatDownFailure(envName, message) {
69
+ return [
70
+ `Couldn't bring down NocoBase for "${envName}".`,
71
+ 'Some local runtime resources may still exist. Check Docker or the local app process, then try again.',
72
+ `Details: ${message}`,
73
+ ].join('\n');
74
+ }
75
+ export default class Down extends Command {
76
+ static description = 'Stop NocoBase and remove local runtime containers for the selected env. Data, source files, and env config are kept unless explicitly requested.';
77
+ static examples = [
78
+ '<%= config.bin %> <%= command.id %> --env app1',
79
+ '<%= config.bin %> <%= command.id %> --env app1 --remove-data',
80
+ '<%= config.bin %> <%= command.id %> --env app1 --remove-source --remove-env',
81
+ ];
82
+ static flags = {
83
+ env: Flags.string({
84
+ char: 'e',
85
+ description: 'CLI env name to bring down. Defaults to the current env when omitted',
86
+ }),
87
+ 'remove-data': Flags.boolean({
88
+ description: 'Delete storage and managed database data after confirmation',
89
+ default: false,
90
+ }),
91
+ 'remove-source': Flags.boolean({
92
+ description: 'Delete the npm/git source directory for local installs',
93
+ default: false,
94
+ }),
95
+ 'remove-env': Flags.boolean({
96
+ description: 'Remove the CLI env config after local resources are removed',
97
+ default: false,
98
+ }),
99
+ yes: Flags.boolean({
100
+ char: 'y',
101
+ description: 'Confirm destructive actions without prompting',
102
+ default: false,
103
+ }),
104
+ verbose: Flags.boolean({
105
+ description: 'Show raw output from shutdown commands',
106
+ default: false,
107
+ }),
108
+ };
109
+ async run() {
110
+ const { flags } = await this.parse(Down);
111
+ const requestedEnv = flags.env?.trim() || undefined;
112
+ const runtime = await resolveManagedAppRuntime(requestedEnv);
113
+ if (!runtime) {
114
+ this.error(formatMissingManagedAppEnvMessage(requestedEnv));
115
+ }
116
+ if (runtime.kind === 'remote') {
117
+ this.error([
118
+ `Can't bring down "${runtime.envName}" from this machine.`,
119
+ 'This env only has an API connection, so there is no saved local app, Docker app, or managed database to remove here.',
120
+ 'Use `nb env remove` if you only want to remove the CLI connection config.',
121
+ ].join('\n'));
122
+ }
123
+ if (flags['remove-data']) {
124
+ let confirmed = false;
125
+ try {
126
+ confirmed = await confirmRemoveData(runtime.envName, flags.yes);
127
+ }
128
+ catch (error) {
129
+ this.error(error instanceof Error ? error.message : String(error));
130
+ }
131
+ if (!confirmed) {
132
+ this.log('Canceled.');
133
+ return;
134
+ }
135
+ }
136
+ try {
137
+ if (runtime.kind === 'docker') {
138
+ startTask(`Removing Docker app container for "${runtime.envName}"...`);
139
+ const state = await removeDockerContainerIfExists(runtime.containerName);
140
+ succeedTask(state === 'removed'
141
+ ? `Docker app container removed for "${runtime.envName}".`
142
+ : `No Docker app container found for "${runtime.envName}".`);
143
+ }
144
+ else {
145
+ startTask(`Stopping local NocoBase app for "${runtime.envName}"...`);
146
+ await runLocalNocoBaseCommand(runtime, ['pm2', 'kill'], {
147
+ stdio: flags.verbose ? 'inherit' : 'ignore',
148
+ });
149
+ succeedTask(`Local NocoBase app stopped for "${runtime.envName}".`);
150
+ }
151
+ const dbContainerName = builtinDbContainerName(runtime);
152
+ if (dbContainerName) {
153
+ startTask(`Removing built-in database container for "${runtime.envName}"...`);
154
+ const state = await removeDockerContainerIfExists(dbContainerName);
155
+ succeedTask(state === 'removed'
156
+ ? `Built-in database container removed for "${runtime.envName}".`
157
+ : `No built-in database container found for "${runtime.envName}".`);
158
+ }
159
+ if (flags['remove-data']) {
160
+ const storagePath = resolveConfiguredPath(runtime.env.config.storagePath);
161
+ if (storagePath) {
162
+ startTask(`Deleting storage and managed database data for "${runtime.envName}"...`);
163
+ await removePathIfExists(storagePath, 'storage data');
164
+ succeedTask(`Storage and managed database data deleted for "${runtime.envName}".`);
165
+ }
166
+ else {
167
+ printInfo(`No storage path is configured for "${runtime.envName}".`);
168
+ }
169
+ }
170
+ if (flags['remove-source']) {
171
+ if (runtime.kind === 'local') {
172
+ startTask(`Deleting source files for "${runtime.envName}"...`);
173
+ await removePathIfExists(runtime.projectRoot, 'source files');
174
+ succeedTask(`Source files deleted for "${runtime.envName}".`);
175
+ }
176
+ else {
177
+ printInfo(`No npm/git source directory is configured for "${runtime.envName}".`);
178
+ }
179
+ }
180
+ if (flags['remove-env']) {
181
+ startTask(`Removing CLI env config for "${runtime.envName}"...`);
182
+ await removeEnv(runtime.envName);
183
+ succeedTask(`CLI env config removed for "${runtime.envName}".`);
184
+ }
185
+ printInfo(`NocoBase is down for "${runtime.envName}".`);
186
+ }
187
+ catch (error) {
188
+ const message = error instanceof Error ? error.message : String(error);
189
+ failTask(`Failed to bring down NocoBase for "${runtime.envName}".`);
190
+ this.error(formatDownFailure(runtime.envName, message));
191
+ }
192
+ }
193
+ }