@nocobase/cli 2.1.0-alpha.3 → 2.1.0-alpha.30

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 (182) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +379 -19
  3. package/README.zh-CN.md +329 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +131 -0
  6. package/dist/commands/api/resource/create.js +15 -0
  7. package/dist/commands/api/resource/destroy.js +15 -0
  8. package/dist/commands/api/resource/get.js +15 -0
  9. package/dist/commands/api/resource/index.js +20 -0
  10. package/dist/commands/api/resource/list.js +16 -0
  11. package/dist/commands/api/resource/query.js +15 -0
  12. package/dist/commands/api/resource/update.js +15 -0
  13. package/dist/commands/app/down.js +266 -0
  14. package/dist/commands/app/logs.js +98 -0
  15. package/dist/commands/app/restart.js +75 -0
  16. package/dist/commands/app/start.js +253 -0
  17. package/dist/commands/app/stop.js +99 -0
  18. package/dist/commands/app/upgrade.js +582 -0
  19. package/{src/cli.js → dist/commands/build.js} +4 -11
  20. package/dist/commands/config/delete.js +30 -0
  21. package/dist/commands/config/get.js +29 -0
  22. package/dist/commands/config/index.js +20 -0
  23. package/dist/commands/config/list.js +29 -0
  24. package/dist/commands/config/set.js +35 -0
  25. package/dist/commands/db/check.js +238 -0
  26. package/dist/commands/db/logs.js +85 -0
  27. package/dist/commands/db/ps.js +60 -0
  28. package/dist/commands/db/shared.js +96 -0
  29. package/dist/commands/db/start.js +71 -0
  30. package/dist/commands/db/stop.js +71 -0
  31. package/{templates/plugin/src/client/models/index.ts → dist/commands/dev.js} +4 -4
  32. package/{src/index.js → dist/commands/down.js} +4 -6
  33. package/{src/commands/locale/react-js-cron/index.js → dist/commands/download.js} +4 -8
  34. package/dist/commands/env/add.js +312 -0
  35. package/dist/commands/env/auth.js +55 -0
  36. package/dist/commands/env/info.js +156 -0
  37. package/dist/commands/env/list.js +50 -0
  38. package/dist/commands/env/remove.js +59 -0
  39. package/dist/commands/env/shared.js +158 -0
  40. package/dist/commands/env/update.js +67 -0
  41. package/dist/commands/env/use.js +28 -0
  42. package/dist/commands/examples/prompts-stages.js +150 -0
  43. package/dist/commands/examples/prompts-test.js +181 -0
  44. package/dist/commands/init.js +1027 -0
  45. package/dist/commands/install.js +2206 -0
  46. package/dist/commands/license/activate.js +360 -0
  47. package/dist/commands/license/env.js +94 -0
  48. package/dist/commands/license/generate-id.js +108 -0
  49. package/dist/commands/license/id.js +56 -0
  50. package/dist/commands/license/index.js +20 -0
  51. package/dist/commands/license/plugins/clean.js +101 -0
  52. package/dist/commands/license/plugins/index.js +20 -0
  53. package/dist/commands/license/plugins/list.js +50 -0
  54. package/dist/commands/license/plugins/shared.js +325 -0
  55. package/dist/commands/license/plugins/sync.js +269 -0
  56. package/dist/commands/license/shared.js +414 -0
  57. package/dist/commands/license/status.js +50 -0
  58. package/dist/commands/logs.js +12 -0
  59. package/dist/commands/plugin/disable.js +66 -0
  60. package/dist/commands/plugin/enable.js +66 -0
  61. package/dist/commands/plugin/list.js +62 -0
  62. package/dist/commands/pm/disable.js +12 -0
  63. package/dist/commands/pm/enable.js +12 -0
  64. package/dist/commands/pm/list.js +12 -0
  65. package/dist/commands/restart.js +12 -0
  66. package/dist/commands/scaffold/migration.js +38 -0
  67. package/dist/commands/scaffold/plugin.js +37 -0
  68. package/dist/commands/self/check.js +71 -0
  69. package/dist/commands/self/index.js +20 -0
  70. package/dist/commands/self/update.js +86 -0
  71. package/dist/commands/skills/check.js +69 -0
  72. package/dist/commands/skills/index.js +20 -0
  73. package/dist/commands/skills/install.js +71 -0
  74. package/dist/commands/skills/remove.js +71 -0
  75. package/dist/commands/skills/update.js +78 -0
  76. package/dist/commands/source/build.js +58 -0
  77. package/dist/commands/source/dev.js +158 -0
  78. package/dist/commands/source/download.js +866 -0
  79. package/dist/commands/source/test.js +467 -0
  80. package/dist/commands/start.js +12 -0
  81. package/dist/commands/stop.js +12 -0
  82. package/dist/commands/test.js +12 -0
  83. package/dist/commands/upgrade.js +12 -0
  84. package/dist/generated/command-registry.js +133 -0
  85. package/dist/help/runtime-help.js +23 -0
  86. package/dist/lib/api-client.js +329 -0
  87. package/dist/lib/app-health.js +126 -0
  88. package/dist/lib/app-managed-resources.js +268 -0
  89. package/dist/lib/app-runtime.js +171 -0
  90. package/dist/lib/auth-store.js +328 -0
  91. package/dist/lib/bootstrap.js +384 -0
  92. package/dist/lib/build-config.js +18 -0
  93. package/dist/lib/builtin-db.js +86 -0
  94. package/dist/lib/cli-config.js +176 -0
  95. package/dist/lib/cli-home.js +47 -0
  96. package/dist/lib/cli-locale.js +129 -0
  97. package/dist/lib/command-discovery.js +39 -0
  98. package/dist/lib/db-connection-check.js +178 -0
  99. package/dist/lib/env-auth.js +872 -0
  100. package/dist/lib/env-config.js +87 -0
  101. package/dist/lib/generated-command.js +171 -0
  102. package/dist/lib/http-request.js +49 -0
  103. package/dist/lib/naming.js +70 -0
  104. package/dist/lib/openapi.js +62 -0
  105. package/dist/lib/plugin-storage.js +127 -0
  106. package/dist/lib/post-processors.js +23 -0
  107. package/dist/lib/prompt-catalog.js +581 -0
  108. package/dist/lib/prompt-validators.js +185 -0
  109. package/dist/lib/prompt-web-ui.js +2103 -0
  110. package/dist/lib/resource-command.js +343 -0
  111. package/dist/lib/resource-request.js +104 -0
  112. package/dist/lib/run-npm.js +250 -0
  113. package/dist/lib/runtime-env-vars.js +32 -0
  114. package/dist/lib/runtime-generator.js +498 -0
  115. package/dist/lib/runtime-store.js +56 -0
  116. package/dist/lib/self-manager.js +301 -0
  117. package/dist/lib/skills-manager.js +296 -0
  118. package/dist/lib/startup-update.js +281 -0
  119. package/dist/lib/ui.js +178 -0
  120. package/dist/locale/en-US.json +339 -0
  121. package/dist/locale/zh-CN.json +339 -0
  122. package/dist/post-processors/data-modeling.js +66 -0
  123. package/dist/post-processors/data-source-manager.js +114 -0
  124. package/dist/post-processors/index.js +19 -0
  125. package/nocobase-ctl.config.json +369 -0
  126. package/package.json +95 -26
  127. package/LICENSE +0 -661
  128. package/bin/index.js +0 -39
  129. package/nocobase.conf.tpl +0 -95
  130. package/src/commands/benchmark.js +0 -73
  131. package/src/commands/build.js +0 -49
  132. package/src/commands/clean.js +0 -30
  133. package/src/commands/client.js +0 -166
  134. package/src/commands/create-nginx-conf.js +0 -37
  135. package/src/commands/create-plugin.js +0 -33
  136. package/src/commands/dev.js +0 -200
  137. package/src/commands/doc.js +0 -76
  138. package/src/commands/e2e.js +0 -265
  139. package/src/commands/global.js +0 -43
  140. package/src/commands/index.js +0 -45
  141. package/src/commands/instance-id.js +0 -47
  142. package/src/commands/locale/cronstrue.js +0 -122
  143. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  144. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  145. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  146. package/src/commands/locale.js +0 -81
  147. package/src/commands/p-test.js +0 -88
  148. package/src/commands/perf.js +0 -63
  149. package/src/commands/pkg.js +0 -321
  150. package/src/commands/pm2.js +0 -37
  151. package/src/commands/postinstall.js +0 -88
  152. package/src/commands/start.js +0 -148
  153. package/src/commands/tar.js +0 -36
  154. package/src/commands/test-coverage.js +0 -55
  155. package/src/commands/test.js +0 -107
  156. package/src/commands/umi.js +0 -33
  157. package/src/commands/update-deps.js +0 -72
  158. package/src/commands/upgrade.js +0 -47
  159. package/src/commands/view-license-key.js +0 -44
  160. package/src/license.js +0 -76
  161. package/src/logger.js +0 -75
  162. package/src/plugin-generator.js +0 -80
  163. package/src/util.js +0 -517
  164. package/templates/bundle-status.html +0 -338
  165. package/templates/create-app-package.json +0 -39
  166. package/templates/plugin/.npmignore.tpl +0 -2
  167. package/templates/plugin/README.md.tpl +0 -1
  168. package/templates/plugin/client.d.ts +0 -2
  169. package/templates/plugin/client.js +0 -1
  170. package/templates/plugin/package.json.tpl +0 -11
  171. package/templates/plugin/server.d.ts +0 -2
  172. package/templates/plugin/server.js +0 -1
  173. package/templates/plugin/src/client/client.d.ts +0 -249
  174. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  175. package/templates/plugin/src/client/locale.ts +0 -21
  176. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  177. package/templates/plugin/src/index.ts +0 -2
  178. package/templates/plugin/src/locale/en-US.json +0 -1
  179. package/templates/plugin/src/locale/zh-CN.json +0 -1
  180. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  181. package/templates/plugin/src/server/index.ts.tpl +0 -1
  182. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -0,0 +1,328 @@
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 { promises as fs } from 'node:fs';
10
+ import path from 'node:path';
11
+ import { resolveCliHomeDir, resolveConfiguredEnvPath, resolveEnvRelativePath, } from './cli-home.js';
12
+ function normalizeStoredEnvKind(value) {
13
+ const kind = String(value ?? '').trim();
14
+ if (kind === 'remote') {
15
+ return 'http';
16
+ }
17
+ if (kind === 'local' || kind === 'http' || kind === 'docker' || kind === 'ssh') {
18
+ return kind;
19
+ }
20
+ return undefined;
21
+ }
22
+ function normalizeOptionalString(value) {
23
+ const normalized = String(value ?? '').trim();
24
+ return normalized || undefined;
25
+ }
26
+ export function readEnvApiBaseUrl(config) {
27
+ if (!config) {
28
+ return undefined;
29
+ }
30
+ return (normalizeOptionalString(config.apiBaseUrl)
31
+ ?? normalizeOptionalString(config.baseUrl)
32
+ ?? normalizeOptionalString(config.apibaseUrl));
33
+ }
34
+ export function resolveEnvKind(config) {
35
+ if (!config) {
36
+ return undefined;
37
+ }
38
+ const explicitKind = normalizeStoredEnvKind(config.kind);
39
+ if (explicitKind) {
40
+ return explicitKind;
41
+ }
42
+ const source = String(config.source ?? '').trim();
43
+ if (source === 'docker') {
44
+ return 'docker';
45
+ }
46
+ if (source === 'npm' || source === 'git' || source === 'local') {
47
+ return 'local';
48
+ }
49
+ if (String(config.appRootPath ?? '').trim()) {
50
+ return 'local';
51
+ }
52
+ if (readEnvApiBaseUrl(config) || config.auth) {
53
+ return 'http';
54
+ }
55
+ return undefined;
56
+ }
57
+ function normalizeEnvConfigEntry(entry) {
58
+ if (!entry) {
59
+ return entry;
60
+ }
61
+ const { kind: _kind, apiBaseUrl: _apiBaseUrl, baseUrl: _baseUrl, apibaseUrl: _legacyApiBaseUrl, ...rest } = entry;
62
+ const normalizedKind = resolveEnvKind(entry);
63
+ const apiBaseUrl = readEnvApiBaseUrl(entry);
64
+ return {
65
+ ...rest,
66
+ ...(normalizedKind ? { kind: normalizedKind } : {}),
67
+ ...(apiBaseUrl !== undefined ? { apiBaseUrl } : {}),
68
+ };
69
+ }
70
+ function normalizeAuthConfig(config) {
71
+ const settings = config.settings ?? {};
72
+ return {
73
+ name: config.name || config.dockerResourcePrefix,
74
+ settings: {
75
+ ...(settings.license?.pkgUrl ? { license: { pkgUrl: normalizeOptionalString(settings.license.pkgUrl) } } : {}),
76
+ ...(settings.docker?.network || settings.docker?.containerPrefix
77
+ ? {
78
+ docker: {
79
+ ...(settings.docker?.network ? { network: normalizeOptionalString(settings.docker.network) } : {}),
80
+ ...(settings.docker?.containerPrefix
81
+ ? { containerPrefix: normalizeOptionalString(settings.docker.containerPrefix) }
82
+ : {}),
83
+ },
84
+ }
85
+ : {}),
86
+ },
87
+ currentEnv: config.currentEnv || 'default',
88
+ envs: Object.fromEntries(Object.entries(config.envs || {}).map(([envName, entry]) => [envName, normalizeEnvConfigEntry(entry) ?? {}])),
89
+ };
90
+ }
91
+ function getConfigFile(options = {}) {
92
+ return path.join(resolveCliHomeDir(options.scope), 'config.json');
93
+ }
94
+ function createDefaultConfig() {
95
+ return {
96
+ currentEnv: 'default',
97
+ envs: {},
98
+ };
99
+ }
100
+ async function readStoredAuthConfig(filePath) {
101
+ try {
102
+ const content = await fs.readFile(filePath, 'utf8');
103
+ const parsed = JSON.parse(content);
104
+ return normalizeAuthConfig(parsed);
105
+ }
106
+ catch (_error) {
107
+ return undefined;
108
+ }
109
+ }
110
+ export async function loadExactAuthConfig(options = {}) {
111
+ return (await readStoredAuthConfig(getConfigFile(options))) ?? createDefaultConfig();
112
+ }
113
+ export async function loadAuthConfig(options = {}) {
114
+ return await loadExactAuthConfig(options);
115
+ }
116
+ export async function saveAuthConfig(config, options = {}) {
117
+ const filePath = getConfigFile(options);
118
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
119
+ await fs.writeFile(filePath, JSON.stringify(normalizeAuthConfig(config), null, 2));
120
+ }
121
+ export async function listEnvs(options = {}) {
122
+ const config = await loadAuthConfig(options);
123
+ return {
124
+ currentEnv: config.currentEnv || 'default',
125
+ envs: config.envs,
126
+ };
127
+ }
128
+ export async function getCurrentEnvName(options = {}) {
129
+ const config = await loadAuthConfig(options);
130
+ return config.currentEnv || 'default';
131
+ }
132
+ export async function setCurrentEnv(envName, options = {}) {
133
+ const config = await loadExactAuthConfig(options);
134
+ if (!config.envs[envName]) {
135
+ throw new Error(`Env "${envName}" is not configured`);
136
+ }
137
+ config.currentEnv = envName;
138
+ await saveAuthConfig(config, options);
139
+ }
140
+ export class Env {
141
+ config;
142
+ constructor(config = {}) {
143
+ this.config = config;
144
+ }
145
+ get name() {
146
+ return this.config.name;
147
+ }
148
+ get baseUrl() {
149
+ return readEnvApiBaseUrl(this.config);
150
+ }
151
+ get apiBaseUrl() {
152
+ return readEnvApiBaseUrl(this.config);
153
+ }
154
+ get auth() {
155
+ return this.config.auth;
156
+ }
157
+ get runtime() {
158
+ return this.config.runtime;
159
+ }
160
+ get kind() {
161
+ return resolveEnvKind(this.config);
162
+ }
163
+ get appRootPath() {
164
+ if (this.kind === 'ssh') {
165
+ const configuredPath = String(this.config.appRootPath ?? '').trim();
166
+ if (configuredPath) {
167
+ return configuredPath;
168
+ }
169
+ }
170
+ return resolveConfiguredEnvPath(this.config.appRootPath) ?? resolveEnvRelativePath('.');
171
+ }
172
+ get storagePath() {
173
+ if (this.kind === 'ssh') {
174
+ const configuredPath = String(this.config.storagePath ?? '').trim();
175
+ if (configuredPath) {
176
+ return configuredPath;
177
+ }
178
+ }
179
+ return resolveConfiguredEnvPath(this.config.storagePath) ?? resolveEnvRelativePath('.');
180
+ }
181
+ get appPort() {
182
+ return this.config.appPort;
183
+ }
184
+ get envVars() {
185
+ const out = {
186
+ STORAGE_PATH: this.storagePath,
187
+ };
188
+ const put = (key, value) => {
189
+ if (value === undefined || value === null) {
190
+ return;
191
+ }
192
+ out[key] = String(value);
193
+ };
194
+ put('APP_PORT', this.appPort);
195
+ put('APP_KEY', this.config.appKey);
196
+ put('TZ', this.config.timezone);
197
+ put('DB_DIALECT', this.config.dbDialect);
198
+ if (!this.config.builtinDb) {
199
+ put('DB_HOST', this.config.dbHost);
200
+ put('DB_PORT', this.config.dbPort);
201
+ }
202
+ else if (String(this.config.source ?? '').trim() !== 'docker') {
203
+ put('DB_PORT', this.config.dbPort);
204
+ }
205
+ put('DB_DATABASE', this.config.dbDatabase);
206
+ put('DB_USER', this.config.dbUser);
207
+ put('DB_PASSWORD', this.config.dbPassword);
208
+ return out;
209
+ }
210
+ }
211
+ export async function getEnv(envName, options = {}) {
212
+ const { config: snapshot, ...loadOptions } = options;
213
+ const config = snapshot ?? (await loadAuthConfig(loadOptions));
214
+ const resolved = envName?.trim() || config.currentEnv || 'default';
215
+ const envConfig = config.envs[resolved];
216
+ if (!envConfig) {
217
+ return undefined;
218
+ }
219
+ return new Env({ ...(normalizeEnvConfigEntry(envConfig) ?? {}), name: resolved });
220
+ }
221
+ function areAuthConfigsEquivalent(left, right) {
222
+ if (!left && !right) {
223
+ return true;
224
+ }
225
+ if (!left || !right || left.type !== right.type) {
226
+ return false;
227
+ }
228
+ if (left.type === 'token' && right.type === 'token') {
229
+ return left.accessToken === right.accessToken;
230
+ }
231
+ if (left.type === 'oauth' && right.type === 'oauth') {
232
+ return (left.accessToken === right.accessToken &&
233
+ left.refreshToken === right.refreshToken &&
234
+ left.expiresAt === right.expiresAt &&
235
+ left.scope === right.scope &&
236
+ left.issuer === right.issuer &&
237
+ left.clientId === right.clientId &&
238
+ left.resource === right.resource);
239
+ }
240
+ return false;
241
+ }
242
+ async function writeEnv(envName, updater, options = {}) {
243
+ const config = await loadExactAuthConfig(options);
244
+ const previous = config.envs[envName];
245
+ config.envs[envName] = updater(previous);
246
+ config.currentEnv = envName;
247
+ await saveAuthConfig(config, options);
248
+ }
249
+ export async function upsertEnv(envName, config, options = {}) {
250
+ await writeEnv(envName, (previous) => {
251
+ const { apiBaseUrl: _apiBaseUrl, baseUrl: _baseUrl, apibaseUrl: _legacyApiBaseUrl, accessToken, ...rest } = config;
252
+ const nextApiBaseUrl = readEnvApiBaseUrl(config);
253
+ const previousApiBaseUrl = readEnvApiBaseUrl(previous);
254
+ const baseUrlChanged = previousApiBaseUrl !== nextApiBaseUrl;
255
+ const nextAuth = accessToken
256
+ ? {
257
+ type: 'token',
258
+ accessToken,
259
+ }
260
+ : baseUrlChanged || previous?.auth?.type === 'token'
261
+ ? undefined
262
+ : previous?.auth;
263
+ const authChanged = !areAuthConfigsEquivalent(previous?.auth, nextAuth);
264
+ return {
265
+ ...previous,
266
+ apiBaseUrl: nextApiBaseUrl,
267
+ auth: nextAuth,
268
+ ...rest,
269
+ runtime: baseUrlChanged || authChanged ? undefined : previous?.runtime,
270
+ };
271
+ }, options);
272
+ }
273
+ export async function updateEnvConnection(envName, updates, options = {}) {
274
+ await writeEnv(envName, (previous) => {
275
+ const nextApiBaseUrl = readEnvApiBaseUrl(updates) ?? readEnvApiBaseUrl(previous);
276
+ const previousApiBaseUrl = readEnvApiBaseUrl(previous);
277
+ const baseUrlChanged = previousApiBaseUrl !== nextApiBaseUrl;
278
+ const nextAuth = updates.accessToken
279
+ ? {
280
+ type: 'token',
281
+ accessToken: updates.accessToken,
282
+ }
283
+ : baseUrlChanged || previous?.auth?.type === 'token'
284
+ ? undefined
285
+ : previous?.auth;
286
+ const authChanged = !areAuthConfigsEquivalent(previous?.auth, nextAuth);
287
+ return {
288
+ ...previous,
289
+ ...(nextApiBaseUrl !== undefined ? { apiBaseUrl: nextApiBaseUrl } : {}),
290
+ auth: nextAuth,
291
+ runtime: baseUrlChanged || authChanged ? undefined : previous?.runtime,
292
+ };
293
+ }, options);
294
+ }
295
+ export async function setEnvOauthSession(envName, auth, options = {}) {
296
+ await writeEnv(envName, (previous) => ({
297
+ ...previous,
298
+ auth,
299
+ runtime: options.preserveRuntime ? previous?.runtime : undefined,
300
+ }), options);
301
+ }
302
+ export async function setEnvRuntime(envName, runtime, options = {}) {
303
+ const config = await loadExactAuthConfig(options);
304
+ const current = config.envs[envName] ?? {};
305
+ config.envs[envName] = {
306
+ ...current,
307
+ runtime,
308
+ };
309
+ config.currentEnv = envName;
310
+ await saveAuthConfig(config, options);
311
+ }
312
+ export async function removeEnv(envName, options = {}) {
313
+ const config = await loadExactAuthConfig(options);
314
+ if (!config.envs[envName]) {
315
+ throw new Error(`Env "${envName}" is not configured`);
316
+ }
317
+ delete config.envs[envName];
318
+ if (config.currentEnv === envName) {
319
+ const nextEnv = Object.keys(config.envs).sort()[0];
320
+ config.currentEnv = nextEnv ?? 'default';
321
+ }
322
+ await saveAuthConfig(config, options);
323
+ return {
324
+ removed: envName,
325
+ currentEnv: config.currentEnv || 'default',
326
+ hasEnvs: Object.keys(config.envs).length > 0,
327
+ };
328
+ }