@nocobase/cli 2.1.0-beta.42-test.1 → 2.1.0-beta.42-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/dist/commands/init.js +18 -0
- package/dist/commands/install.js +20 -4
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Command, Flags } from '@oclif/core';
|
|
10
10
|
import pc from 'picocolors';
|
|
11
|
+
import crypto from 'node:crypto';
|
|
11
12
|
import { existsSync } from 'node:fs';
|
|
12
13
|
import path from 'node:path';
|
|
13
14
|
import { stdin as stdinStream, stdout as stdoutStream } from 'node:process';
|
|
@@ -84,6 +85,16 @@ function explicitApiBaseUrlFlag(flags) {
|
|
|
84
85
|
function explicitDbHostFlag(flags) {
|
|
85
86
|
return String(flags['db-host'] ?? '').trim();
|
|
86
87
|
}
|
|
88
|
+
function optionalInitString(value) {
|
|
89
|
+
const text = String(value ?? '').trim();
|
|
90
|
+
return text || undefined;
|
|
91
|
+
}
|
|
92
|
+
function resolveManagedAppKey(value) {
|
|
93
|
+
return optionalInitString(value) ?? crypto.randomBytes(32).toString('hex');
|
|
94
|
+
}
|
|
95
|
+
function resolveManagedTimeZone(value) {
|
|
96
|
+
return optionalInitString(value) ?? (Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC');
|
|
97
|
+
}
|
|
87
98
|
function shouldAllowExistingInitEnv() {
|
|
88
99
|
return argvHasToken(process.argv.slice(2), ['--force', '-f']);
|
|
89
100
|
}
|
|
@@ -803,6 +814,7 @@ Prompt modes:
|
|
|
803
814
|
}
|
|
804
815
|
async persistManagedEnvConfig(results, flags = {}) {
|
|
805
816
|
const envName = String(results.appName ?? DEFAULT_INIT_APP_NAME).trim() || DEFAULT_INIT_APP_NAME;
|
|
817
|
+
const existingEnv = await getEnv(envName, { scope: resolveDefaultConfigScope() });
|
|
806
818
|
const appPort = String(results.appPort ?? '').trim();
|
|
807
819
|
const source = String(results.source ?? '').trim();
|
|
808
820
|
const version = resolveInitDownloadVersion(results);
|
|
@@ -826,11 +838,15 @@ Prompt modes:
|
|
|
826
838
|
const authUsername = authType === 'basic' ? String(results.username ?? results.rootUsername ?? '').trim() : '';
|
|
827
839
|
const accessToken = String(results.accessToken ?? '');
|
|
828
840
|
const skipDownload = results.skipDownload === true;
|
|
841
|
+
const appKey = resolveManagedAppKey(results.appKey ?? existingEnv?.config.appKey);
|
|
842
|
+
const timeZone = resolveManagedTimeZone(results.timeZone ?? existingEnv?.config.timezone);
|
|
829
843
|
const builtinDb = explicitDbHostFlag(flags)
|
|
830
844
|
? false
|
|
831
845
|
: results.builtinDb === undefined
|
|
832
846
|
? undefined
|
|
833
847
|
: Boolean(results.builtinDb);
|
|
848
|
+
results.appKey = appKey;
|
|
849
|
+
results.timeZone = timeZone;
|
|
834
850
|
await upsertEnv(envName, {
|
|
835
851
|
...(source === 'docker'
|
|
836
852
|
? { kind: 'docker' }
|
|
@@ -852,6 +868,8 @@ Prompt modes:
|
|
|
852
868
|
...(appRootPath ? { appRootPath } : {}),
|
|
853
869
|
...(storagePath ? { storagePath } : {}),
|
|
854
870
|
...(appPort ? { appPort } : {}),
|
|
871
|
+
...(appKey ? { appKey } : {}),
|
|
872
|
+
...(timeZone ? { timezone: timeZone } : {}),
|
|
855
873
|
...(!skipDownload && results.devDependencies !== undefined
|
|
856
874
|
? { devDependencies: Boolean(results.devDependencies) }
|
|
857
875
|
: {}),
|
package/dist/commands/install.js
CHANGED
|
@@ -843,6 +843,18 @@ export default class Install extends Command {
|
|
|
843
843
|
const text = String(value).trim();
|
|
844
844
|
return text || undefined;
|
|
845
845
|
}
|
|
846
|
+
static resolveManagedAppKey(value) {
|
|
847
|
+
return Install.toOptionalPromptString(value) ?? crypto.randomBytes(32).toString('hex');
|
|
848
|
+
}
|
|
849
|
+
static resolveManagedTimeZone(value) {
|
|
850
|
+
return Install.toOptionalPromptString(value) ?? (Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC');
|
|
851
|
+
}
|
|
852
|
+
async ensureManagedAppRuntimeConfig(params) {
|
|
853
|
+
const savedEnv = await getEnv(params.envName, { scope: resolveDefaultConfigScope() });
|
|
854
|
+
const savedConfig = savedEnv?.config;
|
|
855
|
+
params.appResults.appKey = Install.resolveManagedAppKey(params.appResults.appKey ?? savedConfig?.appKey);
|
|
856
|
+
params.appResults.timeZone = Install.resolveManagedTimeZone(params.appResults.timeZone ?? savedConfig?.timezone);
|
|
857
|
+
}
|
|
846
858
|
static async validateAppPort(value, values) {
|
|
847
859
|
const formatError = validateTcpPort(value);
|
|
848
860
|
if (formatError) {
|
|
@@ -1665,8 +1677,8 @@ export default class Install extends Command {
|
|
|
1665
1677
|
const dbSchema = optionalEnvString(params.dbResults.dbSchema);
|
|
1666
1678
|
const dbTablePrefix = optionalEnvString(params.dbResults.dbTablePrefix);
|
|
1667
1679
|
const dbUnderscored = optionalEnvBoolean(params.dbResults.dbUnderscored);
|
|
1668
|
-
const appKey =
|
|
1669
|
-
const timeZone =
|
|
1680
|
+
const appKey = Install.resolveManagedAppKey(params.appResults.appKey);
|
|
1681
|
+
const timeZone = Install.resolveManagedTimeZone(params.appResults.timeZone);
|
|
1670
1682
|
const containerName = Install.buildDockerAppContainerName(params.envName, params.dockerContainerPrefix ?? params.workspaceName);
|
|
1671
1683
|
const configuredEnvFile = String(params.appResults.envFile ?? '').trim();
|
|
1672
1684
|
const envFile = await resolveDockerEnvFileArg(params.envName, configuredEnvFile ? { envFile: configuredEnvFile } : undefined);
|
|
@@ -1889,8 +1901,8 @@ export default class Install extends Command {
|
|
|
1889
1901
|
const storagePath = resolveConfiguredEnvPath(configuredStoragePath) ??
|
|
1890
1902
|
resolveEnvRelativePath(defaultInstallStoragePath(params.envName));
|
|
1891
1903
|
const dbDialect = String(params.dbResults.dbDialect ?? 'postgres').trim() || 'postgres';
|
|
1892
|
-
const appKey =
|
|
1893
|
-
const timeZone =
|
|
1904
|
+
const appKey = Install.resolveManagedAppKey(params.appResults.appKey);
|
|
1905
|
+
const timeZone = Install.resolveManagedTimeZone(params.appResults.timeZone);
|
|
1894
1906
|
const env = {
|
|
1895
1907
|
STORAGE_PATH: storagePath,
|
|
1896
1908
|
APP_PORT: String(params.appResults.appPort ?? DEFAULT_INSTALL_APP_PORT).trim() || DEFAULT_INSTALL_APP_PORT,
|
|
@@ -2280,6 +2292,10 @@ export default class Install extends Command {
|
|
|
2280
2292
|
}
|
|
2281
2293
|
const promptResults = await this.collectPromptResults(parsed, flags.yes);
|
|
2282
2294
|
const { envName, appResults, downloadResults, dbResults, rootResults, envAddResults } = promptResults;
|
|
2295
|
+
await this.ensureManagedAppRuntimeConfig({
|
|
2296
|
+
envName,
|
|
2297
|
+
appResults,
|
|
2298
|
+
});
|
|
2283
2299
|
const source = String(downloadResultsValue(downloadResults, 'source') ?? '').trim();
|
|
2284
2300
|
const usesDockerResources = Boolean(dbResults.builtinDb) || source === 'docker';
|
|
2285
2301
|
const dockerNetworkName = usesDockerResources
|