@nocobase/cli 2.1.0-beta.15 → 2.1.0-beta.17
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 +307 -63
- package/README.zh-CN.md +332 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +114 -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/build.js +57 -0
- package/dist/commands/db/logs.js +85 -0
- package/dist/commands/db/ps.js +60 -0
- package/dist/commands/db/shared.js +81 -0
- package/dist/commands/db/start.js +70 -0
- package/dist/commands/db/stop.js +70 -0
- package/dist/commands/dev.js +149 -0
- package/dist/commands/down.js +193 -0
- package/dist/commands/download.js +779 -0
- package/dist/commands/env/add.js +327 -0
- package/dist/commands/env/auth.js +62 -0
- package/dist/commands/env/list.js +41 -0
- package/dist/commands/env/remove.js +65 -0
- package/dist/commands/env/update.js +73 -0
- package/dist/commands/env/use.js +36 -0
- package/dist/commands/init.js +813 -0
- package/dist/commands/install.js +1850 -0
- package/dist/commands/logs.js +90 -0
- package/dist/commands/pm/disable.js +63 -0
- package/dist/commands/pm/enable.js +63 -0
- package/dist/commands/pm/list.js +54 -0
- package/dist/commands/prompts-stages.js +150 -0
- package/dist/commands/prompts-test.js +181 -0
- package/dist/commands/ps.js +116 -0
- package/dist/commands/scaffold/migration.js +38 -0
- package/dist/commands/scaffold/plugin.js +37 -0
- package/dist/commands/start.js +211 -0
- package/dist/commands/stop.js +90 -0
- package/dist/commands/upgrade.js +583 -0
- package/dist/generated/command-registry.js +133 -0
- package/dist/help/runtime-help.js +20 -0
- package/dist/lib/api-client.js +243 -0
- package/dist/lib/app-runtime.js +142 -0
- package/dist/lib/auth-store.js +241 -0
- package/dist/lib/bootstrap.js +387 -0
- package/dist/lib/build-config.js +10 -0
- package/dist/lib/cli-home.js +30 -0
- package/dist/lib/cli-locale.js +115 -0
- package/dist/lib/command-discovery.js +39 -0
- package/dist/lib/env-auth.js +872 -0
- package/dist/lib/generated-command.js +142 -0
- package/dist/lib/naming.js +70 -0
- package/dist/lib/openapi.js +62 -0
- package/dist/lib/post-processors.js +23 -0
- package/dist/lib/prompt-catalog.js +574 -0
- package/dist/lib/prompt-validators.js +185 -0
- package/dist/lib/prompt-web-ui.js +2061 -0
- package/dist/lib/resource-command.js +335 -0
- package/dist/lib/resource-request.js +104 -0
- package/dist/lib/run-npm.js +123 -0
- package/dist/lib/runtime-generator.js +419 -0
- package/dist/lib/runtime-store.js +56 -0
- package/dist/lib/ui.js +175 -0
- package/dist/locale/en-US.json +319 -0
- package/dist/locale/zh-CN.json +319 -0
- package/dist/post-processors/data-modeling.js +66 -0
- package/dist/post-processors/data-source-manager.js +114 -0
- package/dist/post-processors/index.js +19 -0
- package/nocobase-ctl.config.json +287 -0
- package/package.json +53 -25
- package/LICENSE +0 -201
- package/bin/index.js +0 -39
- package/nocobase.conf.tpl +0 -95
- package/src/cli.js +0 -19
- 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/index.js +0 -17
- 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/index.js +0 -14
- 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/models/index.ts +0 -12
- 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,115 @@
|
|
|
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
|
+
export const SUPPORTED_CLI_LOCALES = ['en-US', 'zh-CN'];
|
|
11
|
+
export const CLI_LOCALE_FLAG_OPTIONS = [...SUPPORTED_CLI_LOCALES];
|
|
12
|
+
export const CLI_LOCALE_FLAG_DESCRIPTION = 'Language for CLI prompts and the local setup UI.';
|
|
13
|
+
const DEFAULT_CLI_LOCALE = 'en-US';
|
|
14
|
+
const localeCache = {};
|
|
15
|
+
function normalizeCliLocale(value) {
|
|
16
|
+
const raw = String(value ?? '').trim();
|
|
17
|
+
if (!raw) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const normalized = raw.replace(/\..*$/, '').replace(/_/g, '-').toLowerCase();
|
|
21
|
+
if (normalized === 'zh' || normalized.startsWith('zh-')) {
|
|
22
|
+
return 'zh-CN';
|
|
23
|
+
}
|
|
24
|
+
if (normalized === 'en' || normalized.startsWith('en-')) {
|
|
25
|
+
return 'en-US';
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
function loadLocaleMessages(locale) {
|
|
30
|
+
if (localeCache[locale]) {
|
|
31
|
+
return localeCache[locale];
|
|
32
|
+
}
|
|
33
|
+
const fileUrl = new URL(`../locale/${locale}.json`, import.meta.url);
|
|
34
|
+
const parsed = JSON.parse(readFileSync(fileUrl, 'utf8'));
|
|
35
|
+
localeCache[locale] = parsed;
|
|
36
|
+
return parsed;
|
|
37
|
+
}
|
|
38
|
+
function getPathValue(input, path) {
|
|
39
|
+
let current = input;
|
|
40
|
+
for (const part of path.split('.')) {
|
|
41
|
+
if (!current || typeof current !== 'object' || !Object.prototype.hasOwnProperty.call(current, part)) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
current = current[part];
|
|
45
|
+
}
|
|
46
|
+
return current;
|
|
47
|
+
}
|
|
48
|
+
function interpolateTemplate(template, values) {
|
|
49
|
+
return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
|
|
50
|
+
const value = getPathValue(values, key);
|
|
51
|
+
return value === undefined || value === null ? '' : String(value);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function detectCliLocale() {
|
|
55
|
+
const candidates = [
|
|
56
|
+
process.env.NB_LOCALE,
|
|
57
|
+
process.env.LC_ALL,
|
|
58
|
+
process.env.LC_MESSAGES,
|
|
59
|
+
process.env.LANG,
|
|
60
|
+
Intl.DateTimeFormat().resolvedOptions().locale,
|
|
61
|
+
];
|
|
62
|
+
for (const candidate of candidates) {
|
|
63
|
+
const locale = normalizeCliLocale(candidate);
|
|
64
|
+
if (locale) {
|
|
65
|
+
return locale;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return DEFAULT_CLI_LOCALE;
|
|
69
|
+
}
|
|
70
|
+
export function resolveCliLocale(preferred) {
|
|
71
|
+
return normalizeCliLocale(preferred) ?? detectCliLocale();
|
|
72
|
+
}
|
|
73
|
+
export function applyCliLocale(preferred) {
|
|
74
|
+
const locale = resolveCliLocale(preferred);
|
|
75
|
+
process.env.NB_LOCALE = locale;
|
|
76
|
+
return locale;
|
|
77
|
+
}
|
|
78
|
+
export function createCliTranslate(preferred) {
|
|
79
|
+
const locale = resolveCliLocale(preferred);
|
|
80
|
+
return (key, values, fallback) => {
|
|
81
|
+
const messages = loadLocaleMessages(locale);
|
|
82
|
+
const template = getPathValue(messages, key);
|
|
83
|
+
if (typeof template !== 'string') {
|
|
84
|
+
return interpolateTemplate(fallback ?? key, values);
|
|
85
|
+
}
|
|
86
|
+
return interpolateTemplate(template, values);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function translateCli(key, values, options) {
|
|
90
|
+
return createCliTranslate(options?.locale)(key, values, options?.fallback);
|
|
91
|
+
}
|
|
92
|
+
export function localeText(key, values, fallback) {
|
|
93
|
+
return {
|
|
94
|
+
key,
|
|
95
|
+
...(values ? { values } : {}),
|
|
96
|
+
...(fallback ? { fallback } : {}),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function isLocalizedTextDef(value) {
|
|
100
|
+
return Boolean(value
|
|
101
|
+
&& typeof value === 'object'
|
|
102
|
+
&& typeof value.key === 'string');
|
|
103
|
+
}
|
|
104
|
+
export function resolveLocalizedText(text, options) {
|
|
105
|
+
if (text === undefined) {
|
|
106
|
+
return options?.fallback ?? '';
|
|
107
|
+
}
|
|
108
|
+
if (typeof text === 'string') {
|
|
109
|
+
return text;
|
|
110
|
+
}
|
|
111
|
+
return translateCli(text.key, text.values, {
|
|
112
|
+
locale: options?.locale,
|
|
113
|
+
fallback: text.fallback ?? options?.fallback,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|