@nocobase/cli 2.1.0-beta.44.test.3 → 2.1.0-beta.44.test.4

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 (77) hide show
  1. package/bin/run.js +40 -3
  2. package/dist/commands/app/destroy.js +13 -6
  3. package/dist/commands/app/restart.js +11 -2
  4. package/dist/commands/app/shared.js +3 -2
  5. package/dist/commands/app/start.js +10 -2
  6. package/dist/commands/app/upgrade.js +6 -4
  7. package/dist/commands/config/delete.js +2 -0
  8. package/dist/commands/config/get.js +2 -0
  9. package/dist/commands/config/set.js +2 -0
  10. package/dist/commands/env/add.js +5 -5
  11. package/dist/commands/init.js +117 -7
  12. package/dist/commands/install.js +50 -13
  13. package/dist/commands/source/download.js +1 -1
  14. package/dist/commands/source/test.js +13 -14
  15. package/dist/locale/en-US.json +13 -5
  16. package/dist/locale/zh-CN.json +13 -5
  17. package/package.json +1 -7
  18. package/scripts/build.mjs +34 -0
  19. package/scripts/clean.mjs +9 -0
  20. package/tsconfig.json +19 -0
  21. package/dist/lib/api-client.js +0 -335
  22. package/dist/lib/api-command-compat.js +0 -641
  23. package/dist/lib/app-health.js +0 -139
  24. package/dist/lib/app-managed-resources.js +0 -321
  25. package/dist/lib/app-public-path.js +0 -80
  26. package/dist/lib/app-runtime.js +0 -189
  27. package/dist/lib/auth-store.js +0 -498
  28. package/dist/lib/backup.js +0 -171
  29. package/dist/lib/bootstrap.js +0 -409
  30. package/dist/lib/build-config.js +0 -18
  31. package/dist/lib/builtin-db.js +0 -86
  32. package/dist/lib/cli-config.js +0 -398
  33. package/dist/lib/cli-entry-error.js +0 -44
  34. package/dist/lib/cli-home.js +0 -47
  35. package/dist/lib/cli-locale.js +0 -141
  36. package/dist/lib/command-discovery.js +0 -39
  37. package/dist/lib/db-connection-check.js +0 -219
  38. package/dist/lib/docker-env-file.js +0 -60
  39. package/dist/lib/docker-image.js +0 -37
  40. package/dist/lib/docker-log-stream.js +0 -45
  41. package/dist/lib/env-auth.js +0 -960
  42. package/dist/lib/env-command-config.js +0 -45
  43. package/dist/lib/env-config.js +0 -100
  44. package/dist/lib/env-guard.js +0 -61
  45. package/dist/lib/env-paths.js +0 -101
  46. package/dist/lib/env-proxy.js +0 -1295
  47. package/dist/lib/generated-command.js +0 -203
  48. package/dist/lib/http-request.js +0 -49
  49. package/dist/lib/inquirer-theme.js +0 -17
  50. package/dist/lib/inquirer.js +0 -243
  51. package/dist/lib/managed-env-file.js +0 -98
  52. package/dist/lib/naming.js +0 -70
  53. package/dist/lib/object-utils.js +0 -76
  54. package/dist/lib/openapi.js +0 -62
  55. package/dist/lib/plugin-import.js +0 -279
  56. package/dist/lib/plugin-storage.js +0 -64
  57. package/dist/lib/post-processors.js +0 -23
  58. package/dist/lib/prompt-catalog-core.js +0 -185
  59. package/dist/lib/prompt-catalog-terminal.js +0 -375
  60. package/dist/lib/prompt-catalog.js +0 -10
  61. package/dist/lib/prompt-validators.js +0 -258
  62. package/dist/lib/prompt-web-ui.js +0 -2227
  63. package/dist/lib/resource-command.js +0 -357
  64. package/dist/lib/resource-request.js +0 -104
  65. package/dist/lib/run-npm.js +0 -393
  66. package/dist/lib/runtime-env-vars.js +0 -32
  67. package/dist/lib/runtime-generator.js +0 -498
  68. package/dist/lib/runtime-store.js +0 -56
  69. package/dist/lib/self-manager.js +0 -301
  70. package/dist/lib/session-id.js +0 -17
  71. package/dist/lib/session-integration.js +0 -703
  72. package/dist/lib/session-store.js +0 -118
  73. package/dist/lib/skills-manager.js +0 -438
  74. package/dist/lib/source-publish.js +0 -326
  75. package/dist/lib/source-registry.js +0 -188
  76. package/dist/lib/startup-update.js +0 -309
  77. package/dist/lib/ui.js +0 -159
@@ -1,301 +0,0 @@
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 fs from 'node:fs';
10
- import fsp from 'node:fs/promises';
11
- import path from 'node:path';
12
- import { fileURLToPath } from 'node:url';
13
- import { resolveCliHomeDir } from './cli-home.js';
14
- import { commandOutput, run } from './run-npm.js';
15
- const DEFAULT_PACKAGE_NAME = '@nocobase/cli';
16
- const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
17
- const INSTALL_METHOD_CACHE_FILE = 'self-install-methods.json';
18
- function normalizePath(value) {
19
- return path.resolve(value);
20
- }
21
- function isSubPath(parent, child) {
22
- const relative = path.relative(normalizePath(parent), normalizePath(child));
23
- return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
24
- }
25
- function parseVersion(version) {
26
- const normalized = String(version ?? '').trim();
27
- const match = normalized.match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?$/);
28
- if (!match) {
29
- return undefined;
30
- }
31
- return {
32
- major: Number(match[1]),
33
- minor: Number(match[2]),
34
- patch: Number(match[3]),
35
- prerelease: match[4] ? match[4].split('.').filter(Boolean) : [],
36
- };
37
- }
38
- function compareIdentifier(left, right) {
39
- const leftNumeric = /^\d+$/.test(left);
40
- const rightNumeric = /^\d+$/.test(right);
41
- if (leftNumeric && rightNumeric) {
42
- return Number(left) - Number(right);
43
- }
44
- if (leftNumeric) {
45
- return -1;
46
- }
47
- if (rightNumeric) {
48
- return 1;
49
- }
50
- return left.localeCompare(right);
51
- }
52
- export function compareVersions(leftVersion, rightVersion) {
53
- const left = parseVersion(leftVersion);
54
- const right = parseVersion(rightVersion);
55
- if (!left || !right) {
56
- return String(leftVersion ?? '').localeCompare(String(rightVersion ?? ''));
57
- }
58
- if (left.major !== right.major) {
59
- return left.major - right.major;
60
- }
61
- if (left.minor !== right.minor) {
62
- return left.minor - right.minor;
63
- }
64
- if (left.patch !== right.patch) {
65
- return left.patch - right.patch;
66
- }
67
- if (left.prerelease.length === 0 && right.prerelease.length === 0) {
68
- return 0;
69
- }
70
- if (left.prerelease.length === 0) {
71
- return 1;
72
- }
73
- if (right.prerelease.length === 0) {
74
- return -1;
75
- }
76
- const maxLength = Math.max(left.prerelease.length, right.prerelease.length);
77
- for (let index = 0; index < maxLength; index += 1) {
78
- const leftIdentifier = left.prerelease[index];
79
- const rightIdentifier = right.prerelease[index];
80
- if (leftIdentifier === undefined) {
81
- return -1;
82
- }
83
- if (rightIdentifier === undefined) {
84
- return 1;
85
- }
86
- const compared = compareIdentifier(leftIdentifier, rightIdentifier);
87
- if (compared !== 0) {
88
- return compared;
89
- }
90
- }
91
- return 0;
92
- }
93
- function detectChannel(currentVersion) {
94
- if (/-alpha(?:[.-]|$)/i.test(currentVersion)) {
95
- return 'alpha';
96
- }
97
- if (/-beta(?:[.-]|$)/i.test(currentVersion)) {
98
- return 'beta';
99
- }
100
- return 'latest';
101
- }
102
- function readCurrentVersion(packageRoot) {
103
- const packageJsonPath = path.join(packageRoot, 'package.json');
104
- const content = fs.readFileSync(packageJsonPath, 'utf8');
105
- const pkg = JSON.parse(content);
106
- return String(pkg.version ?? '').trim();
107
- }
108
- function detectInstallMethod(packageRoot, globalPrefix) {
109
- if (fs.existsSync(path.join(packageRoot, 'src'))
110
- && fs.existsSync(path.join(packageRoot, 'tsconfig.json'))) {
111
- return 'source';
112
- }
113
- if (globalPrefix && isSubPath(globalPrefix, packageRoot)) {
114
- return 'npm-global';
115
- }
116
- if (packageRoot.includes(`${path.sep}node_modules${path.sep}`)) {
117
- return 'package-local';
118
- }
119
- return 'unknown';
120
- }
121
- function getInstallMethodCacheFile() {
122
- return path.join(resolveCliHomeDir('global'), INSTALL_METHOD_CACHE_FILE);
123
- }
124
- function getInstallMethodCacheKey(packageRoot) {
125
- return normalizePath(path.join(packageRoot, 'bin', 'run.js'));
126
- }
127
- async function readInstallMethodCache() {
128
- try {
129
- const raw = await fsp.readFile(getInstallMethodCacheFile(), 'utf8');
130
- return JSON.parse(raw);
131
- }
132
- catch {
133
- return {};
134
- }
135
- }
136
- async function writeInstallMethodCache(state) {
137
- const filePath = getInstallMethodCacheFile();
138
- await fsp.mkdir(path.dirname(filePath), { recursive: true });
139
- await fsp.writeFile(filePath, JSON.stringify(state, null, 2));
140
- }
141
- async function readCachedInstallMethod(packageRoot) {
142
- const state = await readInstallMethodCache();
143
- return state.entries?.[getInstallMethodCacheKey(packageRoot)];
144
- }
145
- async function writeCachedInstallMethod(packageRoot, entry) {
146
- const state = await readInstallMethodCache();
147
- const entries = {
148
- ...(state.entries ?? {}),
149
- [getInstallMethodCacheKey(packageRoot)]: entry,
150
- };
151
- await writeInstallMethodCache({ entries });
152
- }
153
- async function readGlobalPrefix(commandOutputFn) {
154
- try {
155
- return (await commandOutputFn('npm', ['prefix', '-g'], {
156
- errorName: 'npm prefix',
157
- })).trim();
158
- }
159
- catch {
160
- return undefined;
161
- }
162
- }
163
- async function readDistTags(packageName, commandOutputFn) {
164
- const output = await commandOutputFn('npm', ['view', packageName, 'dist-tags', '--json'], {
165
- errorName: 'npm view',
166
- });
167
- const parsed = JSON.parse(output);
168
- return parsed ?? {};
169
- }
170
- function getUnsupportedSelfUpdateReason(installMethod) {
171
- if (installMethod === 'source') {
172
- return [
173
- 'This CLI is running from source in a repository checkout.',
174
- 'Automatic self-update is only supported for standard global npm installs.',
175
- 'Upgrade this checkout through your repo workflow instead.',
176
- ].join(' ');
177
- }
178
- if (installMethod === 'package-local') {
179
- return [
180
- 'This CLI is installed from a local project dependency tree.',
181
- 'Automatic self-update is only supported for standard global npm installs.',
182
- 'Upgrade the parent project dependency that provides this CLI instead.',
183
- ].join(' ');
184
- }
185
- if (installMethod === 'unknown') {
186
- return [
187
- 'This CLI install could not be recognized as a standard global npm install.',
188
- 'Automatic self-update is only supported for standard global npm installs.',
189
- ].join(' ');
190
- }
191
- return undefined;
192
- }
193
- export function getRecommendedSelfUpdateCommand(status) {
194
- if (!status.updatable || !status.updateAvailable) {
195
- return undefined;
196
- }
197
- return 'nb self update --yes';
198
- }
199
- export function formatSelfUpdateUnavailableMessage(status) {
200
- if (status.registryError) {
201
- return [
202
- `Couldn't resolve the latest published version for ${status.packageName}.`,
203
- 'Check your npm registry access and try again.',
204
- `Details: ${status.registryError}`,
205
- ].join('\n');
206
- }
207
- return [
208
- `Couldn't resolve the latest published version for ${status.packageName}.`,
209
- 'Check your npm registry access and try again.',
210
- ].join('\n');
211
- }
212
- export function getSelfUpdatePackageSpec(status) {
213
- return `${status.packageName}@${status.channel}`;
214
- }
215
- export async function inspectSelfInstall(options = {}) {
216
- const packageRoot = options.packageRoot ? normalizePath(options.packageRoot) : PACKAGE_ROOT;
217
- const commandOutputFn = options.commandOutputFn ?? commandOutput;
218
- const cachedInstallMethod = await readCachedInstallMethod(packageRoot);
219
- const globalPrefix = cachedInstallMethod?.globalPrefix ?? await readGlobalPrefix(commandOutputFn);
220
- const installMethod = cachedInstallMethod?.installMethod ?? detectInstallMethod(packageRoot, globalPrefix);
221
- if (!cachedInstallMethod) {
222
- await writeCachedInstallMethod(packageRoot, {
223
- installMethod,
224
- globalPrefix,
225
- });
226
- }
227
- return {
228
- packageRoot,
229
- installMethod,
230
- globalPrefix,
231
- };
232
- }
233
- export async function inspectSelfStatus(options = {}) {
234
- const packageRoot = options.packageRoot ? normalizePath(options.packageRoot) : PACKAGE_ROOT;
235
- const packageName = options.packageName ?? DEFAULT_PACKAGE_NAME;
236
- const currentVersion = options.currentVersion ?? readCurrentVersion(packageRoot);
237
- const channel = options.channel && options.channel !== 'auto' ? options.channel : detectChannel(currentVersion);
238
- const commandOutputFn = options.commandOutputFn ?? commandOutput;
239
- const { installMethod, globalPrefix } = await inspectSelfInstall({
240
- packageRoot,
241
- commandOutputFn,
242
- });
243
- let latestVersion;
244
- let registryError;
245
- try {
246
- const distTags = await readDistTags(packageName, commandOutputFn);
247
- latestVersion = distTags[channel] || distTags.latest;
248
- }
249
- catch (error) {
250
- registryError = error instanceof Error ? error.message : String(error);
251
- }
252
- const updateAvailable = latestVersion ? compareVersions(latestVersion, currentVersion) > 0 : false;
253
- return {
254
- packageName,
255
- packageRoot,
256
- currentVersion,
257
- channel,
258
- latestVersion,
259
- updateAvailable,
260
- installMethod,
261
- updatable: installMethod === 'npm-global',
262
- updateBlockedReason: getUnsupportedSelfUpdateReason(installMethod),
263
- globalPrefix,
264
- registryError,
265
- };
266
- }
267
- export function formatUnsupportedSelfUpdateMessage(status) {
268
- return status.updateBlockedReason
269
- ?? [
270
- 'Automatic self-update is only supported for standard global npm installs.',
271
- ].join('\n');
272
- }
273
- export async function updateSelf(options = {}) {
274
- const status = await inspectSelfStatus(options);
275
- if (!status.updatable) {
276
- throw new Error(formatUnsupportedSelfUpdateMessage(status));
277
- }
278
- const targetVersion = options.targetVersion ?? status.latestVersion;
279
- if (!targetVersion) {
280
- throw new Error(formatSelfUpdateUnavailableMessage(status));
281
- }
282
- if (!targetVersion || compareVersions(targetVersion, status.currentVersion) <= 0) {
283
- return {
284
- action: 'noop',
285
- status,
286
- targetVersion,
287
- packageSpec: getSelfUpdatePackageSpec(status),
288
- };
289
- }
290
- const packageSpec = getSelfUpdatePackageSpec(status);
291
- await (options.runFn ?? run)('npm', ['install', '-g', packageSpec], {
292
- stdio: options.verbose ? 'inherit' : 'ignore',
293
- errorName: 'npm install',
294
- });
295
- return {
296
- action: 'updated',
297
- status,
298
- targetVersion,
299
- packageSpec,
300
- };
301
- }
@@ -1,17 +0,0 @@
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
- export function resolveSessionIdentity() {
10
- const sessionId = String(process.env.NB_SESSION_ID ?? '').trim();
11
- if (sessionId) {
12
- return {
13
- id: sessionId,
14
- };
15
- }
16
- return undefined;
17
- }