From 7d40c2603add6d527093d7c8ab5fd6e50cfdcb3f Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Sat, 8 Oct 2022 23:42:42 +0800 Subject: [PATCH] refactor(cli): fixing cli config and log issues --- packages/cli/src/utilities.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/utilities.ts b/packages/cli/src/utilities.ts index 0cac14aa6..2f03ceaf9 100644 --- a/packages/cli/src/utilities.ts +++ b/packages/cli/src/utilities.ts @@ -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 ( } }; +const cliConfig = new Map>(); + 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; };