@nocobase/cli 2.1.0-alpha.4 → 2.1.0-alpha.40
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.
- package/LICENSE.txt +107 -0
- package/README.md +393 -19
- package/README.zh-CN.md +343 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +135 -0
- package/bin/session-env.js +39 -0
- package/dist/commands/api/resource/create.js +15 -0
- package/dist/commands/api/resource/destroy.js +15 -0
- package/dist/commands/api/resource/get.js +15 -0
- package/dist/commands/api/resource/index.js +20 -0
- package/dist/commands/api/resource/list.js +16 -0
- package/dist/commands/api/resource/query.js +15 -0
- package/dist/commands/api/resource/update.js +15 -0
- package/dist/commands/app/down.js +301 -0
- package/dist/commands/app/logs.js +114 -0
- package/dist/commands/app/restart.js +158 -0
- package/dist/commands/app/start.js +305 -0
- package/dist/commands/app/stop.js +115 -0
- package/dist/commands/app/upgrade.js +636 -0
- package/dist/commands/backup/create.js +147 -0
- package/dist/commands/backup/index.js +20 -0
- package/dist/commands/backup/restore.js +105 -0
- package/{src/cli.js → dist/commands/build.js} +4 -11
- package/dist/commands/config/delete.js +30 -0
- package/dist/commands/config/get.js +29 -0
- package/dist/commands/config/index.js +20 -0
- package/dist/commands/config/list.js +29 -0
- package/dist/commands/config/set.js +35 -0
- package/dist/commands/db/check.js +240 -0
- package/dist/commands/db/logs.js +85 -0
- package/dist/commands/db/ps.js +60 -0
- package/dist/commands/db/shared.js +96 -0
- package/dist/commands/db/start.js +71 -0
- package/dist/commands/db/stop.js +71 -0
- package/{templates/plugin/src/client/models/index.ts → dist/commands/dev.js} +4 -4
- package/{src/commands/locale/react-js-cron/index.js → dist/commands/down.js} +3 -8
- package/dist/commands/download.js +13 -0
- package/dist/commands/env/add.js +366 -0
- package/dist/commands/env/auth.js +130 -0
- package/dist/commands/env/current.js +21 -0
- package/dist/commands/env/info.js +157 -0
- package/dist/commands/env/list.js +44 -0
- package/dist/commands/env/remove.js +84 -0
- package/dist/commands/env/shared.js +158 -0
- package/dist/commands/env/status.js +90 -0
- package/dist/commands/env/update.js +74 -0
- package/dist/commands/env/use.js +38 -0
- package/dist/commands/examples/prompts-stages.js +150 -0
- package/dist/commands/examples/prompts-test.js +181 -0
- package/dist/commands/init.js +1092 -0
- package/dist/commands/install.js +2378 -0
- package/dist/commands/license/activate.js +360 -0
- package/dist/commands/license/env.js +94 -0
- package/dist/commands/license/generate-id.js +108 -0
- package/dist/commands/license/id.js +70 -0
- package/dist/commands/license/index.js +20 -0
- package/dist/commands/license/plugins/clean.js +115 -0
- package/dist/commands/license/plugins/index.js +20 -0
- package/dist/commands/license/plugins/list.js +64 -0
- package/dist/commands/license/plugins/shared.js +325 -0
- package/dist/commands/license/plugins/sync.js +285 -0
- package/dist/commands/license/shared.js +423 -0
- package/dist/commands/license/status.js +64 -0
- package/dist/commands/logs.js +12 -0
- package/dist/commands/plugin/disable.js +86 -0
- package/dist/commands/plugin/enable.js +86 -0
- package/dist/commands/plugin/list.js +82 -0
- package/dist/commands/pm/disable.js +12 -0
- package/dist/commands/pm/enable.js +12 -0
- package/dist/commands/pm/list.js +12 -0
- package/dist/commands/restart.js +12 -0
- package/dist/commands/scaffold/migration.js +38 -0
- package/dist/commands/scaffold/plugin.js +37 -0
- package/dist/commands/self/check.js +71 -0
- package/dist/commands/self/index.js +20 -0
- package/dist/commands/self/update.js +95 -0
- package/dist/commands/session/id.js +24 -0
- package/dist/commands/session/remove.js +57 -0
- package/dist/commands/session/setup.js +62 -0
- package/dist/commands/skills/check.js +69 -0
- package/dist/commands/skills/index.js +20 -0
- package/dist/commands/skills/install.js +80 -0
- package/dist/commands/skills/remove.js +80 -0
- package/dist/commands/skills/update.js +87 -0
- package/dist/commands/source/build.js +58 -0
- package/dist/commands/source/dev.js +182 -0
- package/dist/commands/source/download.js +880 -0
- package/dist/commands/source/publish.js +109 -0
- package/dist/commands/source/registry/logs.js +70 -0
- package/dist/commands/source/registry/start.js +57 -0
- package/dist/commands/source/registry/status.js +33 -0
- package/dist/commands/source/registry/stop.js +48 -0
- package/dist/commands/source/test.js +477 -0
- package/dist/commands/start.js +12 -0
- package/dist/commands/stop.js +12 -0
- package/dist/commands/test.js +12 -0
- package/dist/commands/upgrade.js +12 -0
- package/dist/commands/v1.js +210 -0
- package/dist/generated/command-registry.js +133 -0
- package/dist/help/runtime-help.js +23 -0
- package/dist/lib/api-client.js +329 -0
- package/dist/lib/app-health.js +126 -0
- package/dist/lib/app-managed-resources.js +316 -0
- package/dist/lib/app-runtime.js +180 -0
- package/dist/lib/auth-store.js +368 -0
- package/dist/lib/backup.js +171 -0
- package/dist/lib/bootstrap.js +403 -0
- package/dist/lib/build-config.js +18 -0
- package/dist/lib/builtin-db.js +86 -0
- package/dist/lib/cli-config.js +176 -0
- package/dist/lib/cli-home.js +47 -0
- package/dist/lib/cli-locale.js +129 -0
- package/dist/lib/command-discovery.js +39 -0
- package/dist/lib/db-connection-check.js +158 -0
- package/dist/lib/docker-env-file.js +52 -0
- package/dist/lib/docker-image.js +37 -0
- package/dist/lib/env-auth.js +873 -0
- package/dist/lib/env-config.js +94 -0
- package/dist/lib/env-guard.js +62 -0
- package/dist/lib/generated-command.js +186 -0
- package/dist/lib/http-request.js +49 -0
- package/dist/lib/inquirer-theme.js +17 -0
- package/dist/lib/inquirer.js +244 -0
- package/dist/lib/naming.js +70 -0
- package/dist/lib/object-utils.js +76 -0
- package/dist/lib/openapi.js +62 -0
- package/dist/lib/plugin-storage.js +64 -0
- package/dist/lib/post-processors.js +23 -0
- package/dist/lib/prompt-catalog-core.js +185 -0
- package/dist/lib/prompt-catalog-terminal.js +375 -0
- package/{src/index.js → dist/lib/prompt-catalog.js} +2 -6
- package/dist/lib/prompt-validators.js +240 -0
- package/dist/lib/prompt-web-ui.js +2103 -0
- package/dist/lib/resource-command.js +357 -0
- package/dist/lib/resource-request.js +104 -0
- package/dist/lib/run-npm.js +275 -0
- package/dist/lib/runtime-env-vars.js +32 -0
- package/dist/lib/runtime-generator.js +498 -0
- package/dist/lib/runtime-store.js +56 -0
- package/dist/lib/self-manager.js +301 -0
- package/dist/lib/session-id.js +17 -0
- package/dist/lib/session-integration.js +703 -0
- package/dist/lib/session-store.js +118 -0
- package/dist/lib/skills-manager.js +360 -0
- package/dist/lib/source-publish.js +306 -0
- package/dist/lib/source-registry.js +188 -0
- package/dist/lib/startup-update.js +285 -0
- package/dist/lib/ui.js +155 -0
- package/dist/locale/en-US.json +344 -0
- package/dist/locale/zh-CN.json +344 -0
- package/dist/post-processors/data-modeling.js +84 -0
- package/dist/post-processors/data-source-manager.js +138 -0
- package/dist/post-processors/index.js +19 -0
- package/nocobase-ctl.config.json +388 -0
- package/package.json +100 -26
- package/LICENSE +0 -661
- package/bin/index.js +0 -39
- package/nocobase.conf.tpl +0 -95
- package/src/commands/benchmark.js +0 -73
- package/src/commands/build.js +0 -49
- package/src/commands/clean.js +0 -30
- package/src/commands/client.js +0 -166
- package/src/commands/create-nginx-conf.js +0 -37
- package/src/commands/create-plugin.js +0 -33
- package/src/commands/dev.js +0 -200
- package/src/commands/doc.js +0 -76
- package/src/commands/e2e.js +0 -265
- package/src/commands/global.js +0 -43
- package/src/commands/index.js +0 -45
- package/src/commands/instance-id.js +0 -47
- package/src/commands/locale/cronstrue.js +0 -122
- package/src/commands/locale/react-js-cron/en-US.json +0 -75
- package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
- package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
- package/src/commands/locale.js +0 -81
- package/src/commands/p-test.js +0 -88
- package/src/commands/perf.js +0 -63
- package/src/commands/pkg.js +0 -321
- package/src/commands/pm2.js +0 -37
- package/src/commands/postinstall.js +0 -88
- package/src/commands/start.js +0 -148
- package/src/commands/tar.js +0 -36
- package/src/commands/test-coverage.js +0 -55
- package/src/commands/test.js +0 -107
- package/src/commands/umi.js +0 -33
- package/src/commands/update-deps.js +0 -72
- package/src/commands/upgrade.js +0 -47
- package/src/commands/view-license-key.js +0 -44
- package/src/license.js +0 -76
- package/src/logger.js +0 -75
- package/src/plugin-generator.js +0 -80
- package/src/util.js +0 -517
- package/templates/bundle-status.html +0 -338
- package/templates/create-app-package.json +0 -39
- package/templates/plugin/.npmignore.tpl +0 -2
- package/templates/plugin/README.md.tpl +0 -1
- package/templates/plugin/client.d.ts +0 -2
- package/templates/plugin/client.js +0 -1
- package/templates/plugin/package.json.tpl +0 -11
- package/templates/plugin/server.d.ts +0 -2
- package/templates/plugin/server.js +0 -1
- package/templates/plugin/src/client/client.d.ts +0 -249
- package/templates/plugin/src/client/index.tsx.tpl +0 -1
- package/templates/plugin/src/client/locale.ts +0 -21
- package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
- package/templates/plugin/src/index.ts +0 -2
- package/templates/plugin/src/locale/en-US.json +0 -1
- package/templates/plugin/src/locale/zh-CN.json +0 -1
- package/templates/plugin/src/server/collections/.gitkeep +0 -0
- package/templates/plugin/src/server/index.ts.tpl +0 -1
- package/templates/plugin/src/server/plugin.ts.tpl +0 -19
|
@@ -0,0 +1,301 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|