mirror of
https://github.com/logto-io/logto.git
synced 2025-03-31 22:51:25 -05:00
refactor(cli): fixing cli config and log issues
This commit is contained in:
parent
911117a785
commit
7d40c2603a
1 changed files with 12 additions and 2 deletions
|
@ -2,7 +2,7 @@ import { execSync } from 'child_process';
|
|||
import { createWriteStream } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { conditionalString } from '@silverhand/essentials';
|
||||
import { conditionalString, Optional } from '@silverhand/essentials';
|
||||
import chalk from 'chalk';
|
||||
import got, { Progress } from 'got';
|
||||
import { HttpsProxyAgent } from 'hpagent';
|
||||
|
@ -28,7 +28,7 @@ export const log: Log = Object.freeze({
|
|||
console.log(chalk.blue('[info]'), ...args);
|
||||
},
|
||||
succeed: (...args) => {
|
||||
console.log(chalk.green('[succeed] ✔'), ...args);
|
||||
log.info(chalk.green('✔'), ...args);
|
||||
},
|
||||
warn: (...args) => {
|
||||
console.warn(chalk.yellow('[warn]'), ...args);
|
||||
|
@ -109,6 +109,8 @@ export const oraPromise = async <T>(
|
|||
}
|
||||
};
|
||||
|
||||
const cliConfig = new Map<string, Optional<string>>();
|
||||
|
||||
export type GetCliConfig = {
|
||||
key: string;
|
||||
readableKey: string;
|
||||
|
@ -117,6 +119,10 @@ export type GetCliConfig = {
|
|||
};
|
||||
|
||||
export const getCliConfig = async ({ key, readableKey, comments, defaultValue }: GetCliConfig) => {
|
||||
if (cliConfig.has(key)) {
|
||||
return cliConfig.get(key);
|
||||
}
|
||||
|
||||
const { [key]: value } = process.env;
|
||||
|
||||
if (!value) {
|
||||
|
@ -137,9 +143,13 @@ export const getCliConfig = async ({ key, readableKey, comments, defaultValue }:
|
|||
throw error;
|
||||
});
|
||||
|
||||
cliConfig.set(key, input);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
cliConfig.set(key, value);
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue