@nocobase/cli 2.1.0-alpha.21 → 2.1.0-alpha.23
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/dist/commands/download.js +170 -37
- package/dist/commands/env/add.js +39 -12
- package/dist/commands/init.js +90 -47
- package/dist/commands/install.js +191 -57
- package/dist/commands/prompts-stages.js +6 -0
- package/dist/commands/prompts-test.js +6 -0
- package/dist/lib/api-client.js +49 -5
- package/dist/lib/cli-locale.js +115 -0
- package/dist/lib/env-auth.js +2 -2
- package/dist/lib/prompt-catalog.js +87 -58
- package/dist/lib/prompt-validators.js +9 -8
- package/dist/lib/prompt-web-ui.js +143 -74
- package/dist/lib/run-npm.js +10 -10
- package/dist/lib/runtime-generator.js +12 -1
- package/dist/locale/en-US.json +333 -0
- package/dist/locale/zh-CN.json +333 -0
- package/package.json +5 -3
|
@@ -12,11 +12,15 @@ import * as p from '@clack/prompts';
|
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { stdin as stdinStream, stdout as stdoutStream } from 'node:process';
|
|
14
14
|
import { runPromptCatalog, } from "../lib/prompt-catalog.js";
|
|
15
|
+
import { applyCliLocale, CLI_LOCALE_FLAG_DESCRIPTION, CLI_LOCALE_FLAG_OPTIONS, localeText, resolveCliLocale, translateCli, } from "../lib/cli-locale.js";
|
|
15
16
|
import { run } from "../lib/run-npm.js";
|
|
16
17
|
import { printVerbose, setVerboseMode, startTask, stopTask, updateTask } from '../lib/ui.js';
|
|
17
18
|
const DEFAULT_DOCKER_REGISTRY = 'nocobase/nocobase';
|
|
18
19
|
const DEFAULT_DOCKER_REGISTRY_ZH_CN = 'registry.cn-shanghai.aliyuncs.com/nocobase/nocobase';
|
|
19
20
|
const DEFAULT_DOCKER_PLATFORM = 'auto';
|
|
21
|
+
const DEFAULT_DOWNLOAD_VERSION = 'beta';
|
|
22
|
+
const downloadText = (key, values) => localeText(`commands.download.${key}`, values);
|
|
23
|
+
const downloadTranslatedText = (key, values, fallback) => translateCli(`commands.download.${key}`, values, { fallback });
|
|
20
24
|
function defaultOutputDirForVersion(versionTag) {
|
|
21
25
|
const safe = versionTag.replace(/[/\\]/g, '-');
|
|
22
26
|
return `./nocobase-${safe}`;
|
|
@@ -31,10 +35,13 @@ async function pathExists(target) {
|
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
export function defaultDockerRegistryForLang(lang) {
|
|
34
|
-
return String(lang ?? '').trim() === 'zh-CN'
|
|
38
|
+
return resolveCliLocale(String(lang ?? '').trim() || undefined) === 'zh-CN'
|
|
35
39
|
? DEFAULT_DOCKER_REGISTRY_ZH_CN
|
|
36
40
|
: DEFAULT_DOCKER_REGISTRY;
|
|
37
41
|
}
|
|
42
|
+
function defaultDockerRegistryForPromptValues(_values) {
|
|
43
|
+
return defaultDockerRegistryForLang(process.env.NB_LOCALE);
|
|
44
|
+
}
|
|
38
45
|
function argvHasToken(argv, tokens) {
|
|
39
46
|
return tokens.some((t) => argv.includes(t));
|
|
40
47
|
}
|
|
@@ -79,8 +86,64 @@ function dockerPlatformArg(value) {
|
|
|
79
86
|
}
|
|
80
87
|
return platform;
|
|
81
88
|
}
|
|
89
|
+
function formatDownloadStageFailure(stage) {
|
|
90
|
+
return [
|
|
91
|
+
downloadTranslatedText(`failures.${stage}.title`),
|
|
92
|
+
downloadTranslatedText(`failures.${stage}.body`),
|
|
93
|
+
downloadTranslatedText(`failures.${stage}.hint`),
|
|
94
|
+
].join('\n');
|
|
95
|
+
}
|
|
96
|
+
function formatDownloadFailure(message, verbose) {
|
|
97
|
+
if (verbose) {
|
|
98
|
+
return message;
|
|
99
|
+
}
|
|
100
|
+
const lower = message.toLowerCase();
|
|
101
|
+
if (lower.includes('yarn install')) {
|
|
102
|
+
return formatDownloadStageFailure('dependencyInstall');
|
|
103
|
+
}
|
|
104
|
+
if (lower.includes('git clone')) {
|
|
105
|
+
return formatDownloadStageFailure('gitClone');
|
|
106
|
+
}
|
|
107
|
+
if (lower.includes('docker pull')) {
|
|
108
|
+
return formatDownloadStageFailure('dockerPull');
|
|
109
|
+
}
|
|
110
|
+
if (lower.includes('docker save')) {
|
|
111
|
+
return formatDownloadStageFailure('dockerSave');
|
|
112
|
+
}
|
|
113
|
+
if (lower.includes('create-nocobase-app') || lower.includes('npx create-nocobase-app')) {
|
|
114
|
+
return formatDownloadStageFailure('scaffold');
|
|
115
|
+
}
|
|
116
|
+
if (lower.includes('nocobase command')) {
|
|
117
|
+
return formatDownloadStageFailure('build');
|
|
118
|
+
}
|
|
119
|
+
if (lower.includes('exited with code') || lower.includes('exited due to signal')) {
|
|
120
|
+
return formatDownloadStageFailure('generic');
|
|
121
|
+
}
|
|
122
|
+
return message;
|
|
123
|
+
}
|
|
82
124
|
const EXTERNAL_COMMAND_LOADING_DELAY_MS = 8_000;
|
|
83
125
|
const EXTERNAL_COMMAND_LOADING_UPDATE_MS = 15_000;
|
|
126
|
+
function normalizeVersionPreset(value) {
|
|
127
|
+
const text = String(value ?? '').trim();
|
|
128
|
+
if (text === 'latest' || text === 'beta' || text === 'alpha') {
|
|
129
|
+
return text;
|
|
130
|
+
}
|
|
131
|
+
return 'other';
|
|
132
|
+
}
|
|
133
|
+
function versionPresetForValue(value) {
|
|
134
|
+
return normalizeVersionPreset(value);
|
|
135
|
+
}
|
|
136
|
+
function otherVersionValue(value) {
|
|
137
|
+
const text = String(value ?? '').trim();
|
|
138
|
+
return normalizeVersionPreset(text) === 'other' ? text : '';
|
|
139
|
+
}
|
|
140
|
+
function resolveVersionFromResults(results, fallback) {
|
|
141
|
+
const preset = normalizeVersionPreset(results.version ?? fallback);
|
|
142
|
+
if (preset === 'other') {
|
|
143
|
+
return String(results.otherVersion ?? fallback ?? '').trim();
|
|
144
|
+
}
|
|
145
|
+
return preset;
|
|
146
|
+
}
|
|
84
147
|
export default class Download extends Command {
|
|
85
148
|
_flags;
|
|
86
149
|
preparationTaskActive = false;
|
|
@@ -109,6 +172,10 @@ export default class Download extends Command {
|
|
|
109
172
|
description: 'Show detailed command output',
|
|
110
173
|
default: false,
|
|
111
174
|
}),
|
|
175
|
+
locale: Flags.string({
|
|
176
|
+
description: CLI_LOCALE_FLAG_DESCRIPTION,
|
|
177
|
+
options: CLI_LOCALE_FLAG_OPTIONS,
|
|
178
|
+
}),
|
|
112
179
|
'no-intro': Flags.boolean({
|
|
113
180
|
hidden: true,
|
|
114
181
|
description: 'Skip command intro when invoked by another CLI command',
|
|
@@ -143,7 +210,7 @@ export default class Download extends Command {
|
|
|
143
210
|
description: 'Git repository URL to clone when --source git is used.',
|
|
144
211
|
}),
|
|
145
212
|
'docker-registry': Flags.string({
|
|
146
|
-
description: 'Docker
|
|
213
|
+
description: 'Docker registry to pull when --source docker is used; combine it with --version as the image tag.',
|
|
147
214
|
}),
|
|
148
215
|
'docker-platform': Flags.string({
|
|
149
216
|
description: 'Docker image platform to pull; use auto to let Docker choose.',
|
|
@@ -170,38 +237,84 @@ export default class Download extends Command {
|
|
|
170
237
|
static prompts = {
|
|
171
238
|
source: {
|
|
172
239
|
type: 'select',
|
|
173
|
-
|
|
240
|
+
variant: 'radio',
|
|
241
|
+
message: downloadText('prompts.source.message'),
|
|
174
242
|
options: [
|
|
175
|
-
{
|
|
176
|
-
|
|
177
|
-
|
|
243
|
+
{
|
|
244
|
+
value: 'docker',
|
|
245
|
+
label: downloadText('prompts.source.dockerLabel'),
|
|
246
|
+
hint: downloadText('prompts.source.dockerHint'),
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
value: 'npm',
|
|
250
|
+
label: downloadText('prompts.source.npmLabel'),
|
|
251
|
+
hint: downloadText('prompts.source.npmHint'),
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
value: 'git',
|
|
255
|
+
label: downloadText('prompts.source.gitLabel'),
|
|
256
|
+
hint: downloadText('prompts.source.gitHint'),
|
|
257
|
+
},
|
|
178
258
|
],
|
|
179
259
|
yesInitialValue: 'docker',
|
|
180
260
|
initialValue: 'docker',
|
|
181
261
|
required: true,
|
|
182
262
|
},
|
|
183
263
|
version: {
|
|
264
|
+
type: 'select',
|
|
265
|
+
variant: 'radio',
|
|
266
|
+
message: downloadText('prompts.version.message'),
|
|
267
|
+
options: [
|
|
268
|
+
{
|
|
269
|
+
value: 'latest',
|
|
270
|
+
label: downloadText('prompts.version.latestLabel'),
|
|
271
|
+
hint: downloadText('prompts.version.latestHint'),
|
|
272
|
+
disabled: true,
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
value: 'beta',
|
|
276
|
+
label: downloadText('prompts.version.betaLabel'),
|
|
277
|
+
hint: downloadText('prompts.version.betaHint'),
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
value: 'alpha',
|
|
281
|
+
label: downloadText('prompts.version.alphaLabel'),
|
|
282
|
+
hint: downloadText('prompts.version.alphaHint'),
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
value: 'other',
|
|
286
|
+
label: downloadText('prompts.version.otherLabel'),
|
|
287
|
+
hint: downloadText('prompts.version.otherHint'),
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
initialValue: DEFAULT_DOWNLOAD_VERSION,
|
|
291
|
+
yesInitialValue: DEFAULT_DOWNLOAD_VERSION,
|
|
292
|
+
required: true,
|
|
293
|
+
},
|
|
294
|
+
otherVersion: {
|
|
184
295
|
type: 'text',
|
|
185
|
-
message: '
|
|
186
|
-
placeholder: '
|
|
187
|
-
initialValue: 'alpha',
|
|
188
|
-
yesInitialValue: 'alpha',
|
|
296
|
+
message: downloadText('prompts.otherVersion.message'),
|
|
297
|
+
placeholder: downloadText('prompts.otherVersion.placeholder'),
|
|
189
298
|
required: true,
|
|
299
|
+
hidden: (values) => normalizeVersionPreset(values.version) !== 'other',
|
|
190
300
|
},
|
|
191
301
|
dockerRegistry: {
|
|
192
302
|
type: 'text',
|
|
193
|
-
message: '
|
|
194
|
-
placeholder:
|
|
195
|
-
initialValue:
|
|
196
|
-
yesInitialValue: DEFAULT_DOCKER_REGISTRY,
|
|
303
|
+
message: downloadText('prompts.dockerRegistry.message'),
|
|
304
|
+
placeholder: downloadText('prompts.dockerRegistry.placeholder'),
|
|
305
|
+
initialValue: defaultDockerRegistryForPromptValues,
|
|
197
306
|
required: true,
|
|
198
307
|
hidden: (values) => values.source !== 'docker',
|
|
199
308
|
},
|
|
200
309
|
dockerPlatform: {
|
|
201
310
|
type: 'select',
|
|
202
|
-
message: '
|
|
311
|
+
message: downloadText('prompts.dockerPlatform.message'),
|
|
203
312
|
options: [
|
|
204
|
-
{
|
|
313
|
+
{
|
|
314
|
+
value: 'auto',
|
|
315
|
+
label: downloadText('prompts.dockerPlatform.autoLabel'),
|
|
316
|
+
hint: downloadText('prompts.dockerPlatform.autoHint'),
|
|
317
|
+
},
|
|
205
318
|
{ value: 'linux/amd64', label: 'linux/amd64' },
|
|
206
319
|
{ value: 'linux/arm64', label: 'linux/arm64' },
|
|
207
320
|
],
|
|
@@ -212,14 +325,14 @@ export default class Download extends Command {
|
|
|
212
325
|
},
|
|
213
326
|
dockerSave: {
|
|
214
327
|
type: 'boolean',
|
|
215
|
-
message: '
|
|
328
|
+
message: downloadText('prompts.dockerSave.message'),
|
|
216
329
|
initialValue: false,
|
|
217
330
|
hidden: (values) => values.source !== 'docker',
|
|
218
331
|
},
|
|
219
332
|
gitUrl: {
|
|
220
333
|
type: 'text',
|
|
221
|
-
message: '
|
|
222
|
-
placeholder: '
|
|
334
|
+
message: downloadText('prompts.gitUrl.message'),
|
|
335
|
+
placeholder: downloadText('prompts.gitUrl.placeholder'),
|
|
223
336
|
initialValue: 'https://github.com/nocobase/nocobase.git',
|
|
224
337
|
yesInitialValue: 'https://github.com/nocobase/nocobase.git',
|
|
225
338
|
required: true,
|
|
@@ -227,9 +340,12 @@ export default class Download extends Command {
|
|
|
227
340
|
},
|
|
228
341
|
outputDir: {
|
|
229
342
|
type: 'text',
|
|
230
|
-
message: '
|
|
231
|
-
placeholder: '
|
|
232
|
-
initialValue: (values) =>
|
|
343
|
+
message: downloadText('prompts.outputDir.message'),
|
|
344
|
+
placeholder: downloadText('prompts.outputDir.placeholder'),
|
|
345
|
+
initialValue: (values) => {
|
|
346
|
+
const version = resolveVersionFromResults(values, DEFAULT_DOWNLOAD_VERSION) || DEFAULT_DOWNLOAD_VERSION;
|
|
347
|
+
return defaultOutputDirForVersion(version);
|
|
348
|
+
},
|
|
233
349
|
required: true,
|
|
234
350
|
hidden: (values) => {
|
|
235
351
|
const s = values.source;
|
|
@@ -244,33 +360,33 @@ export default class Download extends Command {
|
|
|
244
360
|
},
|
|
245
361
|
npmRegistry: {
|
|
246
362
|
type: 'text',
|
|
247
|
-
message: '
|
|
248
|
-
placeholder: '
|
|
363
|
+
message: downloadText('prompts.npmRegistry.message'),
|
|
364
|
+
placeholder: downloadText('prompts.npmRegistry.placeholder'),
|
|
249
365
|
initialValue: '',
|
|
250
366
|
hidden: (values) => values.source !== 'npm' && values.source !== 'git',
|
|
251
367
|
},
|
|
252
368
|
replace: {
|
|
253
369
|
type: 'boolean',
|
|
254
|
-
message: '
|
|
370
|
+
message: downloadText('prompts.replace.message'),
|
|
255
371
|
initialValue: false,
|
|
256
372
|
hidden: (values) => Download.hideOutputDirAndReplaceSteps(values),
|
|
257
373
|
},
|
|
258
374
|
devDependencies: {
|
|
259
375
|
type: 'boolean',
|
|
260
|
-
message: '
|
|
376
|
+
message: downloadText('prompts.devDependencies.message'),
|
|
261
377
|
initialValue: false,
|
|
262
378
|
hidden: (values) => values.source !== 'npm',
|
|
263
379
|
},
|
|
264
380
|
build: {
|
|
265
381
|
type: 'boolean',
|
|
266
|
-
message: '
|
|
382
|
+
message: downloadText('prompts.build.message'),
|
|
267
383
|
initialValue: true,
|
|
268
384
|
yesInitialValue: true,
|
|
269
385
|
hidden: () => true,
|
|
270
386
|
},
|
|
271
387
|
buildDts: {
|
|
272
388
|
type: 'boolean',
|
|
273
|
-
message: '
|
|
389
|
+
message: downloadText('prompts.buildDts.message'),
|
|
274
390
|
initialValue: false,
|
|
275
391
|
hidden: (values) => values.source !== 'git',
|
|
276
392
|
},
|
|
@@ -305,7 +421,7 @@ export default class Download extends Command {
|
|
|
305
421
|
return outputAbs;
|
|
306
422
|
}
|
|
307
423
|
dockerTarPath(flags, outputAbs) {
|
|
308
|
-
const image = flags['docker-registry'] ??
|
|
424
|
+
const image = String(flags['docker-registry'] ?? '').trim() || defaultDockerRegistryForLang(process.env.NB_LOCALE);
|
|
309
425
|
const tag = flags.version ?? 'latest';
|
|
310
426
|
const safeBase = `${image.replace(/[/:]/g, '-')}-${tag.replace(/[/\\]/g, '-')}`;
|
|
311
427
|
return path.join(outputAbs, `${safeBase}.tar`);
|
|
@@ -316,12 +432,15 @@ export default class Download extends Command {
|
|
|
316
432
|
*/
|
|
317
433
|
buildInitialValuesFromParsed(flags, preset) {
|
|
318
434
|
const initialValues = {};
|
|
435
|
+
const localeDefaultDockerRegistry = defaultDockerRegistryForLang(flags.locale ?? process.env.NB_LOCALE);
|
|
319
436
|
const source = flags.source?.trim();
|
|
320
437
|
if (source) {
|
|
321
438
|
initialValues.source = source;
|
|
322
439
|
}
|
|
323
440
|
if (flags.version !== undefined) {
|
|
324
|
-
|
|
441
|
+
const version = flags.version.trim() || 'latest';
|
|
442
|
+
initialValues.version = versionPresetForValue(version);
|
|
443
|
+
initialValues.otherVersion = otherVersionValue(version);
|
|
325
444
|
}
|
|
326
445
|
initialValues.replace = flags.replace;
|
|
327
446
|
initialValues.devDependencies = flags['dev-dependencies'];
|
|
@@ -336,6 +455,9 @@ export default class Download extends Command {
|
|
|
336
455
|
if (flags['docker-registry'] !== undefined) {
|
|
337
456
|
initialValues.dockerRegistry = String(flags['docker-registry'] ?? '').trim();
|
|
338
457
|
}
|
|
458
|
+
else {
|
|
459
|
+
initialValues.dockerRegistry = localeDefaultDockerRegistry;
|
|
460
|
+
}
|
|
339
461
|
initialValues.dockerPlatform = normalizeDockerPlatform(flags['docker-platform']);
|
|
340
462
|
initialValues.dockerSave = flags['docker-save'];
|
|
341
463
|
if (flags['npm-registry'] !== undefined) {
|
|
@@ -360,7 +482,11 @@ export default class Download extends Command {
|
|
|
360
482
|
preset.source = String(flags.source).trim();
|
|
361
483
|
}
|
|
362
484
|
if (flags.version !== undefined) {
|
|
363
|
-
|
|
485
|
+
const version = String(flags.version).trim() || 'latest';
|
|
486
|
+
preset.version = versionPresetForValue(version);
|
|
487
|
+
if (normalizeVersionPreset(version) === 'other') {
|
|
488
|
+
preset.otherVersion = version;
|
|
489
|
+
}
|
|
364
490
|
}
|
|
365
491
|
if (flags['docker-registry'] !== undefined) {
|
|
366
492
|
const v = String(flags['docker-registry'] ?? '').trim();
|
|
@@ -414,7 +540,7 @@ export default class Download extends Command {
|
|
|
414
540
|
}
|
|
415
541
|
mapCatalogResultsToResolved(results, flags) {
|
|
416
542
|
const source = String(results.source);
|
|
417
|
-
const version =
|
|
543
|
+
const version = resolveVersionFromResults(results, flags.version) || 'latest';
|
|
418
544
|
const devDependencies = source === 'npm' ? Boolean(results.devDependencies) : undefined;
|
|
419
545
|
const effectiveBuild = this.resolveEffectiveBuild(source, results, flags);
|
|
420
546
|
const buildDtsWant = results.buildDts !== undefined ? Boolean(results.buildDts) : flags['build-dts'];
|
|
@@ -425,9 +551,11 @@ export default class Download extends Command {
|
|
|
425
551
|
const gitUrl = results.gitUrl !== undefined
|
|
426
552
|
? String(results.gitUrl).trim() || undefined
|
|
427
553
|
: flags['git-url']?.trim() || undefined;
|
|
428
|
-
const dockerRegistry =
|
|
429
|
-
?
|
|
430
|
-
|
|
554
|
+
const dockerRegistry = source === 'docker'
|
|
555
|
+
? (results.dockerRegistry !== undefined
|
|
556
|
+
? String(results.dockerRegistry).trim() || undefined
|
|
557
|
+
: flags['docker-registry']?.trim() || defaultDockerRegistryForLang(flags.locale ?? process.env.NB_LOCALE))
|
|
558
|
+
: undefined;
|
|
431
559
|
const dockerPlatform = source === 'docker'
|
|
432
560
|
? normalizeDockerPlatform(results.dockerPlatform !== undefined
|
|
433
561
|
? results.dockerPlatform
|
|
@@ -480,9 +608,13 @@ export default class Download extends Command {
|
|
|
480
608
|
},
|
|
481
609
|
});
|
|
482
610
|
const source = String(results.source ?? '').trim();
|
|
611
|
+
const version = resolveVersionFromResults(results, flags.version);
|
|
483
612
|
if (!source || !['docker', 'npm', 'git'].includes(source)) {
|
|
484
613
|
this.error('Download source is required. Choose npm, git, or docker.');
|
|
485
614
|
}
|
|
615
|
+
if (!version) {
|
|
616
|
+
this.error('Version is required. Choose alpha, beta, latest, or enter another version.');
|
|
617
|
+
}
|
|
486
618
|
if (flags['docker-save'] && source !== 'docker') {
|
|
487
619
|
this.error('--docker-save is only available when --source docker is selected.');
|
|
488
620
|
}
|
|
@@ -576,7 +708,7 @@ export default class Download extends Command {
|
|
|
576
708
|
return argv;
|
|
577
709
|
}
|
|
578
710
|
async downloadFromDocker(flags) {
|
|
579
|
-
const image = flags['docker-registry'] ??
|
|
711
|
+
const image = String(flags['docker-registry'] ?? '').trim() || defaultDockerRegistryForLang(process.env.NB_LOCALE);
|
|
580
712
|
const tag = flags.version ?? 'latest';
|
|
581
713
|
const imageRef = `${image}:${tag}`;
|
|
582
714
|
const platform = dockerPlatformArg(flags['docker-platform']);
|
|
@@ -689,6 +821,7 @@ export default class Download extends Command {
|
|
|
689
821
|
async download() {
|
|
690
822
|
const { flags } = await this.parse(Download);
|
|
691
823
|
this._flags = flags;
|
|
824
|
+
applyCliLocale(this._flags.locale);
|
|
692
825
|
setVerboseMode(Boolean(flags.verbose));
|
|
693
826
|
if (!flags['no-intro']) {
|
|
694
827
|
p.intro('Get NocoBase');
|
|
@@ -726,7 +859,7 @@ export default class Download extends Command {
|
|
|
726
859
|
}
|
|
727
860
|
catch (error) {
|
|
728
861
|
const message = error instanceof Error ? error.message : String(error);
|
|
729
|
-
this.error(message);
|
|
862
|
+
this.error(formatDownloadFailure(message, this.isVerbose()));
|
|
730
863
|
}
|
|
731
864
|
}
|
|
732
865
|
}
|
package/dist/commands/env/add.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { Args, Command, Flags } from '@oclif/core';
|
|
10
10
|
import { upsertEnv } from '../../lib/auth-store.js';
|
|
11
11
|
import { runPromptCatalog, } from '../../lib/prompt-catalog.js';
|
|
12
|
+
import { applyCliLocale, CLI_LOCALE_FLAG_DESCRIPTION, CLI_LOCALE_FLAG_OPTIONS, localeText, } from '../../lib/cli-locale.js';
|
|
12
13
|
import { validateApiBaseUrl } from '../../lib/prompt-validators.js';
|
|
13
14
|
import { printVerbose, setVerboseMode } from '../../lib/ui.js';
|
|
14
15
|
import * as p from '@clack/prompts';
|
|
@@ -25,6 +26,7 @@ const ENV_RUNTIME_FLAG_MAP = {
|
|
|
25
26
|
'app-key': 'appKey',
|
|
26
27
|
timezone: 'timezone',
|
|
27
28
|
'db-dialect': 'dbDialect',
|
|
29
|
+
'builtin-db-image': 'builtinDbImage',
|
|
28
30
|
'db-host': 'dbHost',
|
|
29
31
|
'db-port': 'dbPort',
|
|
30
32
|
'db-database': 'dbDatabase',
|
|
@@ -37,6 +39,7 @@ const ENV_BOOLEAN_RUNTIME_FLAG_MAP = {
|
|
|
37
39
|
build: 'build',
|
|
38
40
|
'build-dts': 'buildDts',
|
|
39
41
|
};
|
|
42
|
+
const envAddText = (key, values) => localeText(`commands.envAdd.${key}`, values);
|
|
40
43
|
export default class EnvAdd extends Command {
|
|
41
44
|
static summary = 'Save a named NocoBase API endpoint (token or OAuth), then switch the CLI to use it';
|
|
42
45
|
static examples = [
|
|
@@ -61,6 +64,10 @@ export default class EnvAdd extends Command {
|
|
|
61
64
|
description: 'Print detailed progress while writing config',
|
|
62
65
|
default: false,
|
|
63
66
|
}),
|
|
67
|
+
locale: Flags.string({
|
|
68
|
+
description: CLI_LOCALE_FLAG_DESCRIPTION,
|
|
69
|
+
options: CLI_LOCALE_FLAG_OPTIONS,
|
|
70
|
+
}),
|
|
64
71
|
'no-intro': Flags.boolean({
|
|
65
72
|
hidden: true,
|
|
66
73
|
description: 'Skip command intro when invoked by another CLI command',
|
|
@@ -160,6 +167,10 @@ export default class EnvAdd extends Command {
|
|
|
160
167
|
hidden: true,
|
|
161
168
|
description: 'Database dialect saved with this env',
|
|
162
169
|
}),
|
|
170
|
+
'builtin-db-image': Flags.string({
|
|
171
|
+
hidden: true,
|
|
172
|
+
description: 'Built-in database image saved with this env',
|
|
173
|
+
}),
|
|
163
174
|
'db-host': Flags.string({
|
|
164
175
|
hidden: true,
|
|
165
176
|
description: 'Database host saved with this env',
|
|
@@ -184,41 +195,53 @@ export default class EnvAdd extends Command {
|
|
|
184
195
|
static prompts = {
|
|
185
196
|
name: {
|
|
186
197
|
type: 'text',
|
|
187
|
-
message: '
|
|
188
|
-
placeholder: '
|
|
198
|
+
message: envAddText('prompts.name.message'),
|
|
199
|
+
placeholder: envAddText('prompts.name.placeholder'),
|
|
189
200
|
required: true,
|
|
190
201
|
},
|
|
191
202
|
scope: {
|
|
192
203
|
type: 'select',
|
|
193
|
-
message: '
|
|
204
|
+
message: envAddText('prompts.scope.message'),
|
|
194
205
|
options: [
|
|
195
|
-
{
|
|
196
|
-
|
|
206
|
+
{
|
|
207
|
+
value: 'project',
|
|
208
|
+
label: envAddText('prompts.scope.projectLabel'),
|
|
209
|
+
hint: envAddText('prompts.scope.projectHint'),
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
value: 'global',
|
|
213
|
+
label: envAddText('prompts.scope.globalLabel'),
|
|
214
|
+
hint: envAddText('prompts.scope.globalHint'),
|
|
215
|
+
},
|
|
197
216
|
],
|
|
198
217
|
initialValue: 'project',
|
|
199
218
|
required: true,
|
|
200
219
|
},
|
|
201
220
|
apiBaseUrl: {
|
|
202
221
|
type: 'text',
|
|
203
|
-
message: '
|
|
204
|
-
placeholder: '
|
|
222
|
+
message: envAddText('prompts.apiBaseUrl.message'),
|
|
223
|
+
placeholder: envAddText('prompts.apiBaseUrl.placeholder'),
|
|
205
224
|
required: true,
|
|
206
225
|
validate: validateApiBaseUrl,
|
|
207
226
|
},
|
|
208
227
|
authType: {
|
|
209
228
|
type: 'select',
|
|
210
|
-
message: '
|
|
229
|
+
message: envAddText('prompts.authType.message'),
|
|
211
230
|
options: [
|
|
212
|
-
{
|
|
213
|
-
|
|
231
|
+
{
|
|
232
|
+
value: 'oauth',
|
|
233
|
+
label: envAddText('prompts.authType.oauthLabel'),
|
|
234
|
+
hint: envAddText('prompts.authType.oauthHint'),
|
|
235
|
+
},
|
|
236
|
+
{ value: 'token', label: envAddText('prompts.authType.tokenLabel') },
|
|
214
237
|
],
|
|
215
238
|
initialValue: 'oauth',
|
|
216
239
|
required: true,
|
|
217
240
|
},
|
|
218
241
|
accessToken: {
|
|
219
242
|
type: 'text',
|
|
220
|
-
message: '
|
|
221
|
-
placeholder: '
|
|
243
|
+
message: envAddText('prompts.accessToken.message'),
|
|
244
|
+
placeholder: envAddText('prompts.accessToken.placeholder'),
|
|
222
245
|
required: true,
|
|
223
246
|
hidden: (values) => values.authType !== 'token',
|
|
224
247
|
},
|
|
@@ -269,6 +292,9 @@ export default class EnvAdd extends Command {
|
|
|
269
292
|
envConfig[configKey] = value;
|
|
270
293
|
}
|
|
271
294
|
}
|
|
295
|
+
if (flags['builtin-db'] === false) {
|
|
296
|
+
envConfig.builtinDbImage = undefined;
|
|
297
|
+
}
|
|
272
298
|
if (results.authType === 'token' && results.accessToken != null) {
|
|
273
299
|
envConfig.accessToken = String(results.accessToken);
|
|
274
300
|
}
|
|
@@ -277,6 +303,7 @@ export default class EnvAdd extends Command {
|
|
|
277
303
|
async run() {
|
|
278
304
|
const { args, flags } = await this.parse(EnvAdd);
|
|
279
305
|
const parsedFlags = flags;
|
|
306
|
+
applyCliLocale(parsedFlags.locale);
|
|
280
307
|
setVerboseMode(parsedFlags.verbose);
|
|
281
308
|
if (!parsedFlags['no-intro']) {
|
|
282
309
|
p.intro('Connect a NocoBase Environment');
|