@nocobase/cli 2.1.0-beta.44 → 2.1.0-beta.44.test.2
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 +201 -0
- package/README.md +63 -380
- package/assets/env-proxy/nginx/app.conf.tpl +23 -0
- package/assets/env-proxy/nginx/nocobase.conf.tpl +5 -0
- package/assets/env-proxy/nginx/snippets/dist-location.conf +5 -0
- package/assets/env-proxy/nginx/snippets/gzip.conf +17 -0
- package/assets/env-proxy/nginx/snippets/log-format-http.conf +13 -0
- package/assets/env-proxy/nginx/snippets/maps-http.conf +14 -0
- package/assets/env-proxy/nginx/snippets/mime-types.conf +98 -0
- package/assets/env-proxy/nginx/snippets/proxy-location.conf +17 -0
- package/assets/env-proxy/nginx/snippets/spa-location.conf +6 -0
- package/assets/env-proxy/nginx/snippets/uploads-location.conf +21 -0
- package/dist/commands/app/autostart/disable.js +55 -0
- package/dist/commands/app/autostart/enable.js +55 -0
- package/dist/commands/app/autostart/list.js +37 -0
- package/dist/commands/app/autostart/run.js +84 -0
- package/dist/commands/app/autostart/shared.js +49 -0
- package/dist/commands/app/destroy.js +8 -6
- package/dist/commands/app/down.js +2 -2
- package/dist/commands/app/logs.js +2 -1
- package/dist/commands/app/restart.js +79 -23
- package/dist/commands/app/shared.js +1 -1
- package/dist/commands/app/start.js +134 -38
- package/dist/commands/app/stop.js +31 -2
- package/dist/commands/app/upgrade.js +3 -1
- package/dist/commands/config/delete.js +4 -1
- package/dist/commands/config/get.js +4 -1
- package/dist/commands/config/set.js +5 -2
- package/dist/commands/env/add.js +19 -39
- package/dist/commands/env/info.js +3 -2
- package/dist/commands/env/proxy/caddy.js +28 -0
- package/dist/commands/env/proxy/index.js +353 -0
- package/dist/commands/env/proxy/nginx.js +28 -0
- package/dist/commands/env/remove.js +112 -22
- package/dist/commands/env/shared.js +17 -9
- package/dist/commands/env/update.js +385 -21
- package/dist/commands/init.js +233 -91
- package/dist/commands/install.js +174 -68
- package/dist/commands/license/activate.js +63 -244
- package/dist/commands/license/plugins/shared.js +64 -13
- package/dist/commands/plugin/import.js +108 -0
- package/dist/commands/revision/create.js +89 -0
- package/dist/locale/en-US.json +105 -19
- package/dist/locale/zh-CN.json +102 -16
- package/package.json +5 -8
- package/scripts/build.mjs +34 -0
- package/scripts/clean.mjs +9 -0
- package/tsconfig.json +19 -0
- package/LICENSE.txt +0 -107
- package/README.zh-CN.md +0 -355
- package/dist/lib/api-client.js +0 -335
- package/dist/lib/api-command-compat.js +0 -641
- package/dist/lib/app-health.js +0 -139
- package/dist/lib/app-managed-resources.js +0 -316
- package/dist/lib/app-runtime.js +0 -180
- package/dist/lib/auth-store.js +0 -405
- package/dist/lib/backup.js +0 -171
- package/dist/lib/bootstrap.js +0 -409
- package/dist/lib/build-config.js +0 -18
- package/dist/lib/builtin-db.js +0 -86
- package/dist/lib/cli-config.js +0 -309
- package/dist/lib/cli-entry-error.js +0 -44
- package/dist/lib/cli-home.js +0 -47
- package/dist/lib/cli-locale.js +0 -141
- package/dist/lib/command-discovery.js +0 -39
- package/dist/lib/db-connection-check.js +0 -219
- package/dist/lib/docker-env-file.js +0 -52
- package/dist/lib/docker-image.js +0 -37
- package/dist/lib/docker-log-stream.js +0 -45
- package/dist/lib/env-auth.js +0 -960
- package/dist/lib/env-config.js +0 -95
- package/dist/lib/env-guard.js +0 -62
- package/dist/lib/generated-command.js +0 -203
- package/dist/lib/http-request.js +0 -49
- package/dist/lib/inquirer-theme.js +0 -17
- package/dist/lib/inquirer.js +0 -244
- package/dist/lib/naming.js +0 -70
- package/dist/lib/object-utils.js +0 -76
- package/dist/lib/openapi.js +0 -62
- package/dist/lib/plugin-storage.js +0 -64
- package/dist/lib/post-processors.js +0 -23
- package/dist/lib/prompt-catalog-core.js +0 -185
- package/dist/lib/prompt-catalog-terminal.js +0 -375
- package/dist/lib/prompt-catalog.js +0 -10
- package/dist/lib/prompt-validators.js +0 -258
- package/dist/lib/prompt-web-ui.js +0 -2227
- package/dist/lib/resource-command.js +0 -357
- package/dist/lib/resource-request.js +0 -104
- package/dist/lib/run-npm.js +0 -385
- package/dist/lib/runtime-env-vars.js +0 -32
- package/dist/lib/runtime-generator.js +0 -498
- package/dist/lib/runtime-store.js +0 -56
- package/dist/lib/self-manager.js +0 -301
- package/dist/lib/session-id.js +0 -17
- package/dist/lib/session-integration.js +0 -703
- package/dist/lib/session-store.js +0 -118
- package/dist/lib/skills-manager.js +0 -436
- package/dist/lib/source-publish.js +0 -309
- package/dist/lib/source-registry.js +0 -188
- package/dist/lib/startup-update.js +0 -309
- package/dist/lib/ui.js +0 -158
package/dist/lib/cli-config.js
DELETED
|
@@ -1,309 +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 { loadExactAuthConfig, saveAuthConfig } from './auth-store.js';
|
|
10
|
-
import { resolveDefaultConfigScope } from './cli-home.js';
|
|
11
|
-
import { CLI_LOCALE_FLAG_OPTIONS, normalizeCliLocale, resolveCliLocale } from './cli-locale.js';
|
|
12
|
-
export const DEFAULT_LICENSE_PKG_URL = 'https://pkg.nocobase.com/';
|
|
13
|
-
export const DEFAULT_DOCKER_NETWORK = 'nocobase';
|
|
14
|
-
export const DEFAULT_DOCKER_CONTAINER_PREFIX = 'nb';
|
|
15
|
-
export const DEFAULT_DOCKER_BIN = 'docker';
|
|
16
|
-
export const DEFAULT_GIT_BIN = 'git';
|
|
17
|
-
export const DEFAULT_YARN_BIN = 'yarn';
|
|
18
|
-
export const CLI_UPDATE_POLICY_OPTIONS = ['prompt', 'auto', 'off'];
|
|
19
|
-
export const DEFAULT_UPDATE_POLICY = 'prompt';
|
|
20
|
-
export const SUPPORTED_CLI_CONFIG_KEYS = [
|
|
21
|
-
'locale',
|
|
22
|
-
'update.policy',
|
|
23
|
-
'license.pkg-url',
|
|
24
|
-
'docker.network',
|
|
25
|
-
'docker.container-prefix',
|
|
26
|
-
'bin.docker',
|
|
27
|
-
'bin.git',
|
|
28
|
-
'bin.yarn',
|
|
29
|
-
];
|
|
30
|
-
function trimValue(value) {
|
|
31
|
-
const text = String(value ?? '').trim();
|
|
32
|
-
return text || undefined;
|
|
33
|
-
}
|
|
34
|
-
function resolveScope(options = {}) {
|
|
35
|
-
return {
|
|
36
|
-
scope: options.scope ?? resolveDefaultConfigScope(),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export function isSupportedCliConfigKey(value) {
|
|
40
|
-
return SUPPORTED_CLI_CONFIG_KEYS.includes(value);
|
|
41
|
-
}
|
|
42
|
-
export function assertSupportedCliConfigKey(value) {
|
|
43
|
-
if (!isSupportedCliConfigKey(value)) {
|
|
44
|
-
throw new Error(`Unsupported config key "${value}". Supported keys: ${SUPPORTED_CLI_CONFIG_KEYS.join(', ')}`);
|
|
45
|
-
}
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
48
|
-
export function normalizeCliUpdatePolicy(value) {
|
|
49
|
-
const normalized = trimValue(value);
|
|
50
|
-
if (!normalized) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
return CLI_UPDATE_POLICY_OPTIONS.includes(normalized) ? normalized : undefined;
|
|
54
|
-
}
|
|
55
|
-
function cloneSettings(config) {
|
|
56
|
-
return {
|
|
57
|
-
...(config.settings?.locale ? { locale: trimValue(config.settings.locale) } : {}),
|
|
58
|
-
update: config.settings?.update ? { ...config.settings.update } : undefined,
|
|
59
|
-
license: config.settings?.license ? { ...config.settings.license } : undefined,
|
|
60
|
-
docker: config.settings?.docker ? { ...config.settings.docker } : undefined,
|
|
61
|
-
bin: config.settings?.bin ? { ...config.settings.bin } : undefined,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function pruneSettings(config) {
|
|
65
|
-
if (config.settings && !trimValue(config.settings.locale)) {
|
|
66
|
-
delete config.settings.locale;
|
|
67
|
-
}
|
|
68
|
-
const update = config.settings?.update;
|
|
69
|
-
if (update && !normalizeCliUpdatePolicy(update.policy)) {
|
|
70
|
-
delete config.settings?.update;
|
|
71
|
-
}
|
|
72
|
-
const license = config.settings?.license;
|
|
73
|
-
if (license && !trimValue(license.pkgUrl)) {
|
|
74
|
-
delete config.settings?.license;
|
|
75
|
-
}
|
|
76
|
-
const docker = config.settings?.docker;
|
|
77
|
-
if (docker && !trimValue(docker.network) && !trimValue(docker.containerPrefix)) {
|
|
78
|
-
delete config.settings?.docker;
|
|
79
|
-
}
|
|
80
|
-
const bin = config.settings?.bin;
|
|
81
|
-
if (bin && !trimValue(bin.docker) && !trimValue(bin.git) && !trimValue(bin.yarn)) {
|
|
82
|
-
delete config.settings?.bin;
|
|
83
|
-
}
|
|
84
|
-
if (config.settings &&
|
|
85
|
-
!config.settings.locale &&
|
|
86
|
-
!config.settings.update &&
|
|
87
|
-
!config.settings.license &&
|
|
88
|
-
!config.settings.docker &&
|
|
89
|
-
!config.settings.bin) {
|
|
90
|
-
delete config.settings;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
export function getExplicitCliConfigValue(config, key) {
|
|
94
|
-
switch (key) {
|
|
95
|
-
case 'locale':
|
|
96
|
-
return trimValue(config.settings?.locale);
|
|
97
|
-
case 'update.policy':
|
|
98
|
-
return normalizeCliUpdatePolicy(config.settings?.update?.policy);
|
|
99
|
-
case 'license.pkg-url':
|
|
100
|
-
return trimValue(config.settings?.license?.pkgUrl);
|
|
101
|
-
case 'docker.network':
|
|
102
|
-
return trimValue(config.settings?.docker?.network);
|
|
103
|
-
case 'docker.container-prefix':
|
|
104
|
-
return trimValue(config.settings?.docker?.containerPrefix);
|
|
105
|
-
case 'bin.docker':
|
|
106
|
-
return trimValue(config.settings?.bin?.docker);
|
|
107
|
-
case 'bin.git':
|
|
108
|
-
return trimValue(config.settings?.bin?.git);
|
|
109
|
-
case 'bin.yarn':
|
|
110
|
-
return trimValue(config.settings?.bin?.yarn);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
export function getEffectiveCliConfigValue(config, key) {
|
|
114
|
-
const explicit = getExplicitCliConfigValue(config, key);
|
|
115
|
-
if (explicit && key !== 'locale') {
|
|
116
|
-
return explicit;
|
|
117
|
-
}
|
|
118
|
-
switch (key) {
|
|
119
|
-
case 'locale':
|
|
120
|
-
return resolveCliLocale(undefined, { configuredLocale: trimValue(config.settings?.locale) });
|
|
121
|
-
case 'update.policy':
|
|
122
|
-
return explicit ?? DEFAULT_UPDATE_POLICY;
|
|
123
|
-
case 'license.pkg-url':
|
|
124
|
-
return DEFAULT_LICENSE_PKG_URL;
|
|
125
|
-
case 'docker.network':
|
|
126
|
-
return trimValue(config.name) || DEFAULT_DOCKER_NETWORK;
|
|
127
|
-
case 'docker.container-prefix':
|
|
128
|
-
return trimValue(config.name) || DEFAULT_DOCKER_CONTAINER_PREFIX;
|
|
129
|
-
case 'bin.docker':
|
|
130
|
-
return DEFAULT_DOCKER_BIN;
|
|
131
|
-
case 'bin.git':
|
|
132
|
-
return DEFAULT_GIT_BIN;
|
|
133
|
-
case 'bin.yarn':
|
|
134
|
-
return DEFAULT_YARN_BIN;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export function normalizeCliConfigValue(key, value) {
|
|
138
|
-
const normalized = value.trim();
|
|
139
|
-
if (!normalized) {
|
|
140
|
-
throw new Error(`Config key "${key}" requires a non-empty value.`);
|
|
141
|
-
}
|
|
142
|
-
if (key === 'license.pkg-url') {
|
|
143
|
-
return normalized.replace(/\/+$/, '') + '/';
|
|
144
|
-
}
|
|
145
|
-
if (key === 'locale') {
|
|
146
|
-
const locale = normalizeCliLocale(normalized);
|
|
147
|
-
if (!locale) {
|
|
148
|
-
throw new Error(`Config key "${key}" must be one of: ${CLI_LOCALE_FLAG_OPTIONS.join(', ')}`);
|
|
149
|
-
}
|
|
150
|
-
return locale;
|
|
151
|
-
}
|
|
152
|
-
if (key === 'update.policy') {
|
|
153
|
-
const policy = normalizeCliUpdatePolicy(normalized);
|
|
154
|
-
if (!policy) {
|
|
155
|
-
throw new Error(`Config key "${key}" must be one of: ${CLI_UPDATE_POLICY_OPTIONS.join(', ')}`);
|
|
156
|
-
}
|
|
157
|
-
return policy;
|
|
158
|
-
}
|
|
159
|
-
return normalized;
|
|
160
|
-
}
|
|
161
|
-
export async function loadCliConfig(options = {}) {
|
|
162
|
-
return await loadExactAuthConfig(resolveScope(options));
|
|
163
|
-
}
|
|
164
|
-
export async function getCliConfigValue(key, options = {}) {
|
|
165
|
-
const config = await loadCliConfig(options);
|
|
166
|
-
return getEffectiveCliConfigValue(config, key);
|
|
167
|
-
}
|
|
168
|
-
export async function listExplicitCliConfigValues(options = {}) {
|
|
169
|
-
const config = await loadCliConfig(options);
|
|
170
|
-
const out = {};
|
|
171
|
-
for (const key of SUPPORTED_CLI_CONFIG_KEYS) {
|
|
172
|
-
const value = getExplicitCliConfigValue(config, key);
|
|
173
|
-
if (value) {
|
|
174
|
-
out[key] = value;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return out;
|
|
178
|
-
}
|
|
179
|
-
export async function setCliConfigValue(key, value, options = {}) {
|
|
180
|
-
const scope = resolveScope(options);
|
|
181
|
-
const config = await loadExactAuthConfig(scope);
|
|
182
|
-
const normalized = normalizeCliConfigValue(key, value);
|
|
183
|
-
config.settings = cloneSettings(config);
|
|
184
|
-
switch (key) {
|
|
185
|
-
case 'locale':
|
|
186
|
-
config.settings.locale = normalized;
|
|
187
|
-
break;
|
|
188
|
-
case 'update.policy':
|
|
189
|
-
config.settings.update = {
|
|
190
|
-
...(config.settings.update ?? {}),
|
|
191
|
-
policy: normalized,
|
|
192
|
-
};
|
|
193
|
-
break;
|
|
194
|
-
case 'license.pkg-url':
|
|
195
|
-
config.settings.license = {
|
|
196
|
-
...(config.settings.license ?? {}),
|
|
197
|
-
pkgUrl: normalized,
|
|
198
|
-
};
|
|
199
|
-
break;
|
|
200
|
-
case 'docker.network':
|
|
201
|
-
config.settings.docker = {
|
|
202
|
-
...(config.settings.docker ?? {}),
|
|
203
|
-
network: normalized,
|
|
204
|
-
};
|
|
205
|
-
break;
|
|
206
|
-
case 'docker.container-prefix':
|
|
207
|
-
config.settings.docker = {
|
|
208
|
-
...(config.settings.docker ?? {}),
|
|
209
|
-
containerPrefix: normalized,
|
|
210
|
-
};
|
|
211
|
-
break;
|
|
212
|
-
case 'bin.docker':
|
|
213
|
-
config.settings.bin = {
|
|
214
|
-
...(config.settings.bin ?? {}),
|
|
215
|
-
docker: normalized,
|
|
216
|
-
};
|
|
217
|
-
break;
|
|
218
|
-
case 'bin.git':
|
|
219
|
-
config.settings.bin = {
|
|
220
|
-
...(config.settings.bin ?? {}),
|
|
221
|
-
git: normalized,
|
|
222
|
-
};
|
|
223
|
-
break;
|
|
224
|
-
case 'bin.yarn':
|
|
225
|
-
config.settings.bin = {
|
|
226
|
-
...(config.settings.bin ?? {}),
|
|
227
|
-
yarn: normalized,
|
|
228
|
-
};
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
pruneSettings(config);
|
|
232
|
-
await saveAuthConfig(config, scope);
|
|
233
|
-
return normalized;
|
|
234
|
-
}
|
|
235
|
-
export async function deleteCliConfigValue(key, options = {}) {
|
|
236
|
-
const scope = resolveScope(options);
|
|
237
|
-
const config = await loadExactAuthConfig(scope);
|
|
238
|
-
const hadValue = Boolean(getExplicitCliConfigValue(config, key));
|
|
239
|
-
if (!hadValue) {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
config.settings = cloneSettings(config);
|
|
243
|
-
switch (key) {
|
|
244
|
-
case 'locale':
|
|
245
|
-
delete config.settings.locale;
|
|
246
|
-
break;
|
|
247
|
-
case 'update.policy':
|
|
248
|
-
if (config.settings.update) {
|
|
249
|
-
delete config.settings.update.policy;
|
|
250
|
-
}
|
|
251
|
-
break;
|
|
252
|
-
case 'license.pkg-url':
|
|
253
|
-
if (config.settings.license) {
|
|
254
|
-
delete config.settings.license.pkgUrl;
|
|
255
|
-
}
|
|
256
|
-
break;
|
|
257
|
-
case 'docker.network':
|
|
258
|
-
if (config.settings.docker) {
|
|
259
|
-
delete config.settings.docker.network;
|
|
260
|
-
}
|
|
261
|
-
break;
|
|
262
|
-
case 'docker.container-prefix':
|
|
263
|
-
if (config.settings.docker) {
|
|
264
|
-
delete config.settings.docker.containerPrefix;
|
|
265
|
-
}
|
|
266
|
-
break;
|
|
267
|
-
case 'bin.docker':
|
|
268
|
-
if (config.settings.bin) {
|
|
269
|
-
delete config.settings.bin.docker;
|
|
270
|
-
}
|
|
271
|
-
break;
|
|
272
|
-
case 'bin.git':
|
|
273
|
-
if (config.settings.bin) {
|
|
274
|
-
delete config.settings.bin.git;
|
|
275
|
-
}
|
|
276
|
-
break;
|
|
277
|
-
case 'bin.yarn':
|
|
278
|
-
if (config.settings.bin) {
|
|
279
|
-
delete config.settings.bin.yarn;
|
|
280
|
-
}
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
pruneSettings(config);
|
|
284
|
-
await saveAuthConfig(config, scope);
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
export async function resolveDockerNetworkName(options = {}) {
|
|
288
|
-
return await getCliConfigValue('docker.network', options);
|
|
289
|
-
}
|
|
290
|
-
export async function resolveDockerContainerPrefix(options = {}) {
|
|
291
|
-
return await getCliConfigValue('docker.container-prefix', options);
|
|
292
|
-
}
|
|
293
|
-
export async function resolveLicensePkgUrlFromConfig(options = {}) {
|
|
294
|
-
return await getCliConfigValue('license.pkg-url', options);
|
|
295
|
-
}
|
|
296
|
-
const CONFIGURABLE_COMMAND_KEYS = {
|
|
297
|
-
docker: 'bin.docker',
|
|
298
|
-
git: 'bin.git',
|
|
299
|
-
yarn: 'bin.yarn',
|
|
300
|
-
};
|
|
301
|
-
export function isConfigurableCommandName(value) {
|
|
302
|
-
return Object.prototype.hasOwnProperty.call(CONFIGURABLE_COMMAND_KEYS, value);
|
|
303
|
-
}
|
|
304
|
-
export async function resolveConfiguredCommandName(commandName, options = {}) {
|
|
305
|
-
if (!isConfigurableCommandName(commandName)) {
|
|
306
|
-
return commandName;
|
|
307
|
-
}
|
|
308
|
-
return await getCliConfigValue(CONFIGURABLE_COMMAND_KEYS[commandName], options);
|
|
309
|
-
}
|
|
@@ -1,44 +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 getCommandPathTokens(argv) {
|
|
10
|
-
const tokens = [];
|
|
11
|
-
for (const token of argv) {
|
|
12
|
-
if (!token) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
if (token.startsWith('-')) {
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
tokens.push(token);
|
|
19
|
-
}
|
|
20
|
-
return tokens;
|
|
21
|
-
}
|
|
22
|
-
export function formatCliEntryError(error, argv) {
|
|
23
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
24
|
-
const missingCommandMatch = message.match(/^Command (.+) not found\.$/);
|
|
25
|
-
if (!missingCommandMatch) {
|
|
26
|
-
return message;
|
|
27
|
-
}
|
|
28
|
-
const commandPathTokens = getCommandPathTokens(argv);
|
|
29
|
-
const attemptedCommand = commandPathTokens.join(' ') || missingCommandMatch[1];
|
|
30
|
-
const isApiCommand = commandPathTokens[0] === 'api';
|
|
31
|
-
if (isApiCommand) {
|
|
32
|
-
const helpCommandTokens = commandPathTokens.length > 2 ? commandPathTokens.slice(0, -1) : ['api'];
|
|
33
|
-
const helpCommand = `nb ${helpCommandTokens.join(' ')} --help`;
|
|
34
|
-
return [
|
|
35
|
-
`Unknown command: \`${attemptedCommand}\`.`,
|
|
36
|
-
`If this is a built-in command or a typo, run \`${helpCommand}\` to inspect the commands available under that API group.`,
|
|
37
|
-
].join('\n');
|
|
38
|
-
}
|
|
39
|
-
return [
|
|
40
|
-
`Unknown command: \`${attemptedCommand}\`.`,
|
|
41
|
-
'If this is a built-in command or a typo, run `nb --help` to inspect available commands.',
|
|
42
|
-
`If \`${attemptedCommand}\` should be a runtime command from your NocoBase app, check whether the connected app exposes it, then retry the command.`,
|
|
43
|
-
].join('\n');
|
|
44
|
-
}
|
package/dist/lib/cli-home.js
DELETED
|
@@ -1,47 +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 os from 'node:os';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
export const CLI_HOME_DIRNAME = '.nocobase';
|
|
12
|
-
export const NB_CLI_ROOT_ENV = 'NB_CLI_ROOT';
|
|
13
|
-
export function resolveDefaultConfigScope() {
|
|
14
|
-
return 'global';
|
|
15
|
-
}
|
|
16
|
-
function readConfiguredPath(name) {
|
|
17
|
-
const value = String(process.env[name] ?? '').trim();
|
|
18
|
-
return value || undefined;
|
|
19
|
-
}
|
|
20
|
-
function resolveGlobalCliHomeRoot() {
|
|
21
|
-
return readConfiguredPath(NB_CLI_ROOT_ENV) ?? os.homedir();
|
|
22
|
-
}
|
|
23
|
-
export function resolveCliHomeRoot(scope = resolveDefaultConfigScope()) {
|
|
24
|
-
void scope;
|
|
25
|
-
return resolveGlobalCliHomeRoot();
|
|
26
|
-
}
|
|
27
|
-
export function resolveCliHomeDir(scope = resolveDefaultConfigScope()) {
|
|
28
|
-
return path.join(resolveCliHomeRoot(scope), CLI_HOME_DIRNAME);
|
|
29
|
-
}
|
|
30
|
-
export function resolveEnvRoot(scope = resolveDefaultConfigScope()) {
|
|
31
|
-
void scope;
|
|
32
|
-
return resolveCliHomeRoot();
|
|
33
|
-
}
|
|
34
|
-
export function resolveEnvRelativePath(relativePath, scope = resolveDefaultConfigScope()) {
|
|
35
|
-
return path.resolve(resolveEnvRoot(scope), relativePath);
|
|
36
|
-
}
|
|
37
|
-
export function resolveConfiguredEnvPath(value, scope = resolveDefaultConfigScope()) {
|
|
38
|
-
const text = String(value ?? '').trim();
|
|
39
|
-
if (!text) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
return path.isAbsolute(text) ? text : resolveEnvRelativePath(text, scope);
|
|
43
|
-
}
|
|
44
|
-
export function formatCliHomeScope(scope) {
|
|
45
|
-
void scope;
|
|
46
|
-
return 'global';
|
|
47
|
-
}
|
package/dist/lib/cli-locale.js
DELETED
|
@@ -1,141 +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 { readFileSync } from 'node:fs';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
import { fileURLToPath } from 'node:url';
|
|
12
|
-
import { resolveCliHomeDir } from './cli-home.js';
|
|
13
|
-
export const SUPPORTED_CLI_LOCALES = ['en-US', 'zh-CN'];
|
|
14
|
-
export const CLI_LOCALE_FLAG_OPTIONS = [...SUPPORTED_CLI_LOCALES];
|
|
15
|
-
export const CLI_LOCALE_FLAG_DESCRIPTION = 'Language for CLI prompts and the local setup UI.';
|
|
16
|
-
const DEFAULT_CLI_LOCALE = 'en-US';
|
|
17
|
-
const localeCache = {};
|
|
18
|
-
export function normalizeCliLocale(value) {
|
|
19
|
-
const raw = String(value ?? '').trim();
|
|
20
|
-
if (!raw) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
const normalized = raw.replace(/\..*$/, '').replace(/_/g, '-').toLowerCase();
|
|
24
|
-
if (normalized === 'zh' || normalized.startsWith('zh-')) {
|
|
25
|
-
return 'zh-CN';
|
|
26
|
-
}
|
|
27
|
-
if (normalized === 'en' || normalized.startsWith('en-')) {
|
|
28
|
-
return 'en-US';
|
|
29
|
-
}
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
function readConfiguredCliLocale() {
|
|
33
|
-
try {
|
|
34
|
-
const configPath = path.join(resolveCliHomeDir(), 'config.json');
|
|
35
|
-
const content = readFileSync(configPath, 'utf8');
|
|
36
|
-
const parsed = JSON.parse(content);
|
|
37
|
-
return normalizeCliLocale(parsed.settings?.locale === undefined ? undefined : String(parsed.settings.locale));
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function loadLocaleMessages(locale) {
|
|
44
|
-
if (localeCache[locale]) {
|
|
45
|
-
return localeCache[locale];
|
|
46
|
-
}
|
|
47
|
-
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
48
|
-
const fallbackPath = path.resolve(moduleDir, '..', 'locale', `${locale}.json`);
|
|
49
|
-
const fileUrl = new URL(`../locale/${locale}.json`, import.meta.url);
|
|
50
|
-
let parsed;
|
|
51
|
-
try {
|
|
52
|
-
parsed = JSON.parse(readFileSync(fileUrl, 'utf8'));
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : '';
|
|
56
|
-
if (code !== 'ENOENT') {
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
parsed = JSON.parse(readFileSync(fallbackPath, 'utf8'));
|
|
60
|
-
}
|
|
61
|
-
localeCache[locale] = parsed;
|
|
62
|
-
return parsed;
|
|
63
|
-
}
|
|
64
|
-
function getPathValue(input, path) {
|
|
65
|
-
let current = input;
|
|
66
|
-
for (const part of path.split('.')) {
|
|
67
|
-
if (!current || typeof current !== 'object' || !Object.prototype.hasOwnProperty.call(current, part)) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
current = current[part];
|
|
71
|
-
}
|
|
72
|
-
return current;
|
|
73
|
-
}
|
|
74
|
-
function interpolateTemplate(template, values) {
|
|
75
|
-
return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
|
|
76
|
-
const value = getPathValue(values, key);
|
|
77
|
-
return value === undefined || value === null ? '' : String(value);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
export function detectCliLocale(configuredLocale) {
|
|
81
|
-
const resolvedConfiguredLocale = configuredLocale ?? readConfiguredCliLocale();
|
|
82
|
-
const candidates = [
|
|
83
|
-
process.env.NB_LOCALE,
|
|
84
|
-
resolvedConfiguredLocale,
|
|
85
|
-
process.env.LC_ALL,
|
|
86
|
-
process.env.LC_MESSAGES,
|
|
87
|
-
process.env.LANG,
|
|
88
|
-
Intl.DateTimeFormat().resolvedOptions().locale,
|
|
89
|
-
];
|
|
90
|
-
for (const candidate of candidates) {
|
|
91
|
-
const locale = normalizeCliLocale(candidate);
|
|
92
|
-
if (locale) {
|
|
93
|
-
return locale;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return DEFAULT_CLI_LOCALE;
|
|
97
|
-
}
|
|
98
|
-
export function resolveCliLocale(preferred, options) {
|
|
99
|
-
return normalizeCliLocale(preferred) ?? detectCliLocale(options?.configuredLocale);
|
|
100
|
-
}
|
|
101
|
-
export function applyCliLocale(preferred) {
|
|
102
|
-
const locale = resolveCliLocale(preferred);
|
|
103
|
-
process.env.NB_LOCALE = locale;
|
|
104
|
-
return locale;
|
|
105
|
-
}
|
|
106
|
-
export function createCliTranslate(preferred) {
|
|
107
|
-
const locale = resolveCliLocale(preferred);
|
|
108
|
-
return (key, values, fallback) => {
|
|
109
|
-
const messages = loadLocaleMessages(locale);
|
|
110
|
-
const template = getPathValue(messages, key);
|
|
111
|
-
if (typeof template !== 'string') {
|
|
112
|
-
return interpolateTemplate(fallback ?? key, values);
|
|
113
|
-
}
|
|
114
|
-
return interpolateTemplate(template, values);
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
export function translateCli(key, values, options) {
|
|
118
|
-
return createCliTranslate(options?.locale)(key, values, options?.fallback);
|
|
119
|
-
}
|
|
120
|
-
export function localeText(key, values, fallback) {
|
|
121
|
-
return {
|
|
122
|
-
key,
|
|
123
|
-
...(values ? { values } : {}),
|
|
124
|
-
...(fallback ? { fallback } : {}),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
export function isLocalizedTextDef(value) {
|
|
128
|
-
return Boolean(value && typeof value === 'object' && typeof value.key === 'string');
|
|
129
|
-
}
|
|
130
|
-
export function resolveLocalizedText(text, options) {
|
|
131
|
-
if (text === undefined) {
|
|
132
|
-
return options?.fallback ?? '';
|
|
133
|
-
}
|
|
134
|
-
if (typeof text === 'string') {
|
|
135
|
-
return text;
|
|
136
|
-
}
|
|
137
|
-
return translateCli(text.key, text.values, {
|
|
138
|
-
locale: options?.locale,
|
|
139
|
-
fallback: text.fallback ?? options?.fallback,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
@@ -1,39 +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 { readdir } from 'node:fs/promises';
|
|
10
|
-
import { join } from 'node:path';
|
|
11
|
-
/**
|
|
12
|
-
* Recursively collect command module paths under `commandsRoot` (e.g. `dist/commands` → `.js`, `src/commands` → `.ts`).
|
|
13
|
-
*/
|
|
14
|
-
export async function collectCommandModulePaths(commandsRoot, extension) {
|
|
15
|
-
const entries = await readdir(commandsRoot, { withFileTypes: true });
|
|
16
|
-
const files = [];
|
|
17
|
-
for (const ent of entries) {
|
|
18
|
-
const full = join(commandsRoot, ent.name);
|
|
19
|
-
if (ent.isDirectory()) {
|
|
20
|
-
files.push(...(await collectCommandModulePaths(full, extension)));
|
|
21
|
-
}
|
|
22
|
-
else if (ent.isFile() && ent.name.endsWith(extension)) {
|
|
23
|
-
files.push(full);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return files.sort();
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Map a path relative to `commands/` with `.js` / `.ts` to an oclif explicit-registry key.
|
|
30
|
-
* `api/resource/foo.js` → `api:resource:foo`; trailing `index` maps to the parent command.
|
|
31
|
-
*/
|
|
32
|
-
export function commandRelativePathToRegistryKey(relativePath) {
|
|
33
|
-
const normalized = relativePath.replace(/\\/g, '/').replace(/\.(js|ts)$/i, '');
|
|
34
|
-
const segments = normalized.split('/').filter(Boolean);
|
|
35
|
-
if (segments.at(-1) === 'index') {
|
|
36
|
-
segments.pop();
|
|
37
|
-
}
|
|
38
|
-
return segments.join(':');
|
|
39
|
-
}
|