0
Fork 0
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:
Gao Sun 2022-10-08 23:42:42 +08:00
parent 911117a785
commit 7d40c2603a
No known key found for this signature in database
GPG key ID: 13EBE123E4773688

View file

@ -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;
};