@nocobase/cli 2.1.0-rc.1 → 2.1.0-rc.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/dist/lib/api-client.js +335 -0
- package/dist/lib/api-command-compat.js +641 -0
- package/dist/lib/app-health.js +139 -0
- package/dist/lib/app-managed-resources.js +337 -0
- package/dist/lib/app-public-path.js +80 -0
- package/dist/lib/app-runtime.js +189 -0
- package/dist/lib/auth-store.js +528 -0
- package/dist/lib/backup.js +171 -0
- package/dist/lib/bootstrap.js +409 -0
- package/dist/lib/build-config.js +18 -0
- package/dist/lib/builtin-db.js +86 -0
- package/dist/lib/cli-config.js +569 -0
- package/dist/lib/cli-entry-error.js +52 -0
- package/dist/lib/cli-home.js +47 -0
- package/dist/lib/cli-locale.js +141 -0
- package/dist/lib/command-discovery.js +39 -0
- package/dist/lib/command-log.js +284 -0
- package/dist/lib/db-connection-check.js +219 -0
- package/dist/lib/docker-env-file.js +60 -0
- package/dist/lib/docker-image.js +37 -0
- package/dist/lib/docker-log-stream.js +45 -0
- package/dist/lib/env-auth.js +963 -0
- package/dist/lib/env-command-config.js +45 -0
- package/dist/lib/env-config.js +108 -0
- package/dist/lib/env-guard.js +61 -0
- package/dist/lib/env-paths.js +101 -0
- package/dist/lib/env-proxy.js +1325 -0
- package/dist/lib/generated-command.js +203 -0
- package/dist/lib/http-request.js +49 -0
- package/dist/lib/inquirer-theme.js +17 -0
- package/dist/lib/inquirer.js +243 -0
- package/dist/lib/managed-env-file.js +101 -0
- package/dist/lib/managed-init-env.js +32 -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-import.js +279 -0
- package/dist/lib/plugin-storage.js +64 -0
- package/dist/lib/post-processors.js +23 -0
- package/dist/lib/prompt-catalog-core.js +186 -0
- package/dist/lib/prompt-catalog-terminal.js +374 -0
- package/dist/lib/prompt-catalog.js +10 -0
- package/dist/lib/prompt-validators.js +278 -0
- package/dist/lib/prompt-web-ui.js +2234 -0
- package/dist/lib/proxy-caddy.js +274 -0
- package/dist/lib/proxy-nginx.js +330 -0
- package/dist/lib/resource-command.js +357 -0
- package/dist/lib/resource-request.js +104 -0
- package/dist/lib/run-npm.js +429 -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 +438 -0
- package/dist/lib/source-publish.js +326 -0
- package/dist/lib/source-registry.js +188 -0
- package/dist/lib/startup-update.js +309 -0
- package/dist/lib/ui.js +159 -0
- package/package.json +6 -1
- package/assets/env-proxy/nginx/app.conf.tpl +0 -23
- package/assets/env-proxy/nginx/nocobase.conf.tpl +0 -5
- package/assets/env-proxy/nginx/snippets/dist-location.conf +0 -5
- package/assets/env-proxy/nginx/snippets/gzip.conf +0 -17
- package/assets/env-proxy/nginx/snippets/log-format-http.conf +0 -13
- package/assets/env-proxy/nginx/snippets/maps-http.conf +0 -14
- package/assets/env-proxy/nginx/snippets/mime-types.conf +0 -98
- package/assets/env-proxy/nginx/snippets/proxy-location.conf +0 -17
- package/assets/env-proxy/nginx/snippets/spa-location.conf +0 -6
- package/assets/env-proxy/nginx/snippets/uploads-location.conf +0 -21
- package/scripts/build.mjs +0 -34
- package/scripts/clean.mjs +0 -9
- package/tsconfig.json +0 -19
|
@@ -0,0 +1,45 @@
|
|
|
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 const ENV_STRING_CONFIG_FLAG_MAP = {
|
|
10
|
+
source: 'source',
|
|
11
|
+
'download-version': 'downloadVersion',
|
|
12
|
+
'docker-registry': 'dockerRegistry',
|
|
13
|
+
'docker-platform': 'dockerPlatform',
|
|
14
|
+
'git-url': 'gitUrl',
|
|
15
|
+
'npm-registry': 'npmRegistry',
|
|
16
|
+
'app-path': 'appPath',
|
|
17
|
+
'app-root-path': 'appRootPath',
|
|
18
|
+
'storage-path': 'storagePath',
|
|
19
|
+
'app-public-path': 'appPublicPath',
|
|
20
|
+
'cdn-base-url': 'cdnBaseUrl',
|
|
21
|
+
'env-file': 'envFile',
|
|
22
|
+
'app-port': 'appPort',
|
|
23
|
+
'app-key': 'appKey',
|
|
24
|
+
timezone: 'timezone',
|
|
25
|
+
'db-dialect': 'dbDialect',
|
|
26
|
+
'builtin-db-image': 'builtinDbImage',
|
|
27
|
+
'db-host': 'dbHost',
|
|
28
|
+
'db-port': 'dbPort',
|
|
29
|
+
'db-database': 'dbDatabase',
|
|
30
|
+
'db-user': 'dbUser',
|
|
31
|
+
'db-password': 'dbPassword',
|
|
32
|
+
'db-schema': 'dbSchema',
|
|
33
|
+
'db-table-prefix': 'dbTablePrefix',
|
|
34
|
+
'root-username': 'rootUsername',
|
|
35
|
+
'root-email': 'rootEmail',
|
|
36
|
+
'root-password': 'rootPassword',
|
|
37
|
+
'root-nickname': 'rootNickname',
|
|
38
|
+
};
|
|
39
|
+
export const ENV_BOOLEAN_CONFIG_FLAG_MAP = {
|
|
40
|
+
'builtin-db': 'builtinDb',
|
|
41
|
+
'dev-dependencies': 'devDependencies',
|
|
42
|
+
build: 'build',
|
|
43
|
+
'build-dts': 'buildDts',
|
|
44
|
+
'db-underscored': 'dbUnderscored',
|
|
45
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
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 { resolveAppPublicPath } from './app-public-path.js';
|
|
10
|
+
const STRING_ENV_CONFIG_KEYS = [
|
|
11
|
+
'source',
|
|
12
|
+
'downloadVersion',
|
|
13
|
+
'dockerRegistry',
|
|
14
|
+
'dockerPlatform',
|
|
15
|
+
'gitUrl',
|
|
16
|
+
'npmRegistry',
|
|
17
|
+
'appPath',
|
|
18
|
+
'appRootPath',
|
|
19
|
+
'storagePath',
|
|
20
|
+
'appPublicPath',
|
|
21
|
+
'cdnBaseUrl',
|
|
22
|
+
'envFile',
|
|
23
|
+
'appPort',
|
|
24
|
+
'appKey',
|
|
25
|
+
'timezone',
|
|
26
|
+
'authUsername',
|
|
27
|
+
'dbDialect',
|
|
28
|
+
'builtinDbImage',
|
|
29
|
+
'dbHost',
|
|
30
|
+
'dbPort',
|
|
31
|
+
'dbDatabase',
|
|
32
|
+
'dbUser',
|
|
33
|
+
'dbPassword',
|
|
34
|
+
'dbSchema',
|
|
35
|
+
'dbTablePrefix',
|
|
36
|
+
'lang',
|
|
37
|
+
'rootUsername',
|
|
38
|
+
'rootEmail',
|
|
39
|
+
'rootPassword',
|
|
40
|
+
'rootNickname',
|
|
41
|
+
];
|
|
42
|
+
const BOOLEAN_ENV_CONFIG_KEYS = [
|
|
43
|
+
'builtinDb',
|
|
44
|
+
'devDependencies',
|
|
45
|
+
'build',
|
|
46
|
+
'buildDts',
|
|
47
|
+
'dbUnderscored',
|
|
48
|
+
];
|
|
49
|
+
function trimConfigValue(value) {
|
|
50
|
+
const text = String(value ?? '').trim();
|
|
51
|
+
return text || undefined;
|
|
52
|
+
}
|
|
53
|
+
function resolveSetupState(value) {
|
|
54
|
+
return value === 'prepared' || value === 'installed' ? value : undefined;
|
|
55
|
+
}
|
|
56
|
+
function resolveEnvKind(input) {
|
|
57
|
+
const source = trimConfigValue(input.source);
|
|
58
|
+
const appPath = trimConfigValue(input.appPath);
|
|
59
|
+
const appRootPath = trimConfigValue(input.appRootPath);
|
|
60
|
+
if (source === 'docker') {
|
|
61
|
+
return 'docker';
|
|
62
|
+
}
|
|
63
|
+
if (source === 'npm' || source === 'git' || source === 'local' || appPath || appRootPath) {
|
|
64
|
+
return 'local';
|
|
65
|
+
}
|
|
66
|
+
return 'http';
|
|
67
|
+
}
|
|
68
|
+
export function buildStoredEnvConfig(input) {
|
|
69
|
+
const envConfig = {
|
|
70
|
+
kind: resolveEnvKind(input),
|
|
71
|
+
apiBaseUrl: trimConfigValue(input.apiBaseUrl) ?? '',
|
|
72
|
+
};
|
|
73
|
+
for (const key of STRING_ENV_CONFIG_KEYS) {
|
|
74
|
+
const value = trimConfigValue(input[key]);
|
|
75
|
+
if (value) {
|
|
76
|
+
envConfig[key] = key === 'appPublicPath' ? resolveAppPublicPath(value) : value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const setupState = resolveSetupState(input.setupState);
|
|
80
|
+
if (setupState) {
|
|
81
|
+
envConfig.setupState = setupState;
|
|
82
|
+
}
|
|
83
|
+
for (const key of BOOLEAN_ENV_CONFIG_KEYS) {
|
|
84
|
+
const value = input[key];
|
|
85
|
+
if (typeof value === 'boolean') {
|
|
86
|
+
envConfig[key] = value;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (input.builtinDb === false) {
|
|
90
|
+
envConfig.builtinDbImage = undefined;
|
|
91
|
+
}
|
|
92
|
+
if (input.builtinDb === true) {
|
|
93
|
+
delete envConfig.dbHost;
|
|
94
|
+
const source = trimConfigValue(input.source);
|
|
95
|
+
if (source === 'docker') {
|
|
96
|
+
delete envConfig.dbPort;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const authType = trimConfigValue(input.authType);
|
|
100
|
+
if (authType === 'basic' || authType === 'token' || authType === 'oauth') {
|
|
101
|
+
envConfig.authType = authType;
|
|
102
|
+
}
|
|
103
|
+
const accessToken = trimConfigValue(input.accessToken);
|
|
104
|
+
if ((authType === 'basic' || authType === 'token') && accessToken) {
|
|
105
|
+
envConfig.accessToken = accessToken;
|
|
106
|
+
}
|
|
107
|
+
return envConfig;
|
|
108
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { stdin as input, stdout as output } from 'node:process';
|
|
10
|
+
import { getCurrentEnvName } from './auth-store.js';
|
|
11
|
+
import { translateCli } from './cli-locale.js';
|
|
12
|
+
import { confirm } from "./inquirer.js";
|
|
13
|
+
function normalizeEnvName(value) {
|
|
14
|
+
const text = String(value ?? '').trim();
|
|
15
|
+
return text || undefined;
|
|
16
|
+
}
|
|
17
|
+
export function hasExplicitEnvSelection(argv) {
|
|
18
|
+
return argv.some((token, index) => (token === '--env'
|
|
19
|
+
|| token === '-e'
|
|
20
|
+
|| token.startsWith('--env=')
|
|
21
|
+
|| (token.startsWith('-e') && token.length > 2 && index >= 0)));
|
|
22
|
+
}
|
|
23
|
+
function isInteractiveTerminal() {
|
|
24
|
+
return Boolean(input.isTTY && output.isTTY);
|
|
25
|
+
}
|
|
26
|
+
function formatCrossEnvPromptMessage(currentEnv, requestedEnv) {
|
|
27
|
+
return translateCli('commands.shared.crossEnv.prompt', {
|
|
28
|
+
currentEnv,
|
|
29
|
+
requestedEnv,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function formatCrossEnvRefusalMessage(currentEnv, requestedEnv) {
|
|
33
|
+
return translateCli('commands.shared.crossEnv.refusal', {
|
|
34
|
+
currentEnv,
|
|
35
|
+
requestedEnv,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export async function ensureCrossEnvConfirmed(options) {
|
|
39
|
+
const requestedEnv = normalizeEnvName(options.requestedEnv);
|
|
40
|
+
if (!requestedEnv) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const currentEnv = normalizeEnvName(await getCurrentEnvName());
|
|
44
|
+
const interactiveTerminal = isInteractiveTerminal();
|
|
45
|
+
const bypassInteractivePrompt = Boolean(options.yes);
|
|
46
|
+
if (!currentEnv || currentEnv === requestedEnv || bypassInteractivePrompt) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (!interactiveTerminal) {
|
|
50
|
+
options.command.error(formatCrossEnvRefusalMessage(currentEnv, requestedEnv));
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return Boolean(await confirm({
|
|
54
|
+
message: formatCrossEnvPromptMessage(currentEnv, requestedEnv),
|
|
55
|
+
default: false,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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 path from 'node:path';
|
|
10
|
+
import { resolveConfiguredEnvPath } from './cli-home.js';
|
|
11
|
+
function trimPathValue(value) {
|
|
12
|
+
const text = String(value ?? '').trim();
|
|
13
|
+
return text || undefined;
|
|
14
|
+
}
|
|
15
|
+
function normalizePathForComparison(value) {
|
|
16
|
+
return value.replace(/[\\/]+/g, '/').replace(/\/+$/, '');
|
|
17
|
+
}
|
|
18
|
+
export function areConfiguredPathsEquivalent(left, right) {
|
|
19
|
+
const leftValue = trimPathValue(left);
|
|
20
|
+
const rightValue = trimPathValue(right);
|
|
21
|
+
if (!leftValue || !rightValue) {
|
|
22
|
+
return leftValue === rightValue;
|
|
23
|
+
}
|
|
24
|
+
return normalizePathForComparison(leftValue) === normalizePathForComparison(rightValue);
|
|
25
|
+
}
|
|
26
|
+
function trimTrailingSeparators(value) {
|
|
27
|
+
return value.replace(/[\\/]+$/, '');
|
|
28
|
+
}
|
|
29
|
+
function hasTerminalPathSegment(value, segment) {
|
|
30
|
+
const normalized = normalizePathForComparison(value);
|
|
31
|
+
return normalized.endsWith(`/${segment}`) || normalized === segment;
|
|
32
|
+
}
|
|
33
|
+
function dirnameWithTrailingSeparator(value) {
|
|
34
|
+
const trimmed = trimTrailingSeparators(value);
|
|
35
|
+
if (!trimmed) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const separatorIndex = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
39
|
+
if (separatorIndex < 0) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return trimmed.slice(0, separatorIndex + 1);
|
|
43
|
+
}
|
|
44
|
+
function inferAppPathFromLegacyConfigValue(value, leaf) {
|
|
45
|
+
if (!value || !hasTerminalPathSegment(value, leaf)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return dirnameWithTrailingSeparator(value);
|
|
49
|
+
}
|
|
50
|
+
export function deriveConfiguredSourcePath(appPath) {
|
|
51
|
+
const base = trimPathValue(appPath);
|
|
52
|
+
if (!base) {
|
|
53
|
+
return 'source/';
|
|
54
|
+
}
|
|
55
|
+
return `${base.replace(/[\\/]+$/, '')}/source/`;
|
|
56
|
+
}
|
|
57
|
+
export function deriveConfiguredStoragePath(appPath) {
|
|
58
|
+
const base = trimPathValue(appPath);
|
|
59
|
+
if (!base) {
|
|
60
|
+
return 'storage/';
|
|
61
|
+
}
|
|
62
|
+
return `${base.replace(/[\\/]+$/, '')}/storage/`;
|
|
63
|
+
}
|
|
64
|
+
export function inferConfiguredAppPathFromLegacyConfig(config) {
|
|
65
|
+
const explicitAppPath = trimPathValue(config.appPath);
|
|
66
|
+
if (explicitAppPath) {
|
|
67
|
+
return explicitAppPath;
|
|
68
|
+
}
|
|
69
|
+
const candidates = [
|
|
70
|
+
inferAppPathFromLegacyConfigValue(trimPathValue(config.appRootPath), 'source'),
|
|
71
|
+
inferAppPathFromLegacyConfigValue(trimPathValue(config.storagePath), 'storage'),
|
|
72
|
+
].filter((value) => Boolean(value));
|
|
73
|
+
if (candidates.length === 0) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const [first] = candidates;
|
|
77
|
+
if (!first) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
return candidates.every((candidate) => areConfiguredPathsEquivalent(candidate, first)) ? first : undefined;
|
|
81
|
+
}
|
|
82
|
+
export function resolveConfiguredAppPath(config, scope) {
|
|
83
|
+
const configuredAppPath = inferConfiguredAppPathFromLegacyConfig(config);
|
|
84
|
+
return configuredAppPath ? resolveConfiguredEnvPath(configuredAppPath, scope) : undefined;
|
|
85
|
+
}
|
|
86
|
+
export function resolveConfiguredSourcePath(config, scope) {
|
|
87
|
+
const legacySourcePath = trimPathValue(config.appRootPath);
|
|
88
|
+
if (legacySourcePath) {
|
|
89
|
+
return resolveConfiguredEnvPath(legacySourcePath, scope);
|
|
90
|
+
}
|
|
91
|
+
const appPath = resolveConfiguredAppPath(config, scope);
|
|
92
|
+
return appPath ? path.join(appPath, 'source') : undefined;
|
|
93
|
+
}
|
|
94
|
+
export function resolveConfiguredStoragePath(config, scope) {
|
|
95
|
+
const legacyStoragePath = trimPathValue(config.storagePath);
|
|
96
|
+
if (legacyStoragePath) {
|
|
97
|
+
return resolveConfiguredEnvPath(legacyStoragePath, scope);
|
|
98
|
+
}
|
|
99
|
+
const appPath = resolveConfiguredAppPath(config, scope);
|
|
100
|
+
return appPath ? path.join(appPath, 'storage') : undefined;
|
|
101
|
+
}
|