0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

refactor(cli): polish cli output (#4545)

* refactor(cli): polish cli output

* chore: add changeset
This commit is contained in:
Gao Sun 2023-09-18 18:27:25 +08:00 committed by GitHub
parent 3206ab2daa
commit 310698b0d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 13 deletions

View file

@ -0,0 +1,6 @@
---
"@logto/shared": patch
"@logto/cli": patch
---
align cli output for a better looking

View file

@ -203,7 +203,6 @@ export const addOfficialConnectors = async (
) => {
const packages = await oraPromise(fetchOfficialConnectorList(includingCloudConnectors), {
text: 'Fetch official connector list',
prefixText: chalk.blue('[info]'),
});
consoleLog.info(`Found ${packages.length} official connectors`);

View file

@ -1,4 +1,3 @@
import chalk from 'chalk';
import type { DatabasePool } from 'slonik';
import type { CommandModule } from 'yargs';
@ -24,7 +23,6 @@ export const seedByPool = async (pool: DatabasePool, cloud = false) => {
await oraPromise(createTables(connection), {
text: 'Create tables',
prefixText: chalk.blue('[info]'),
});
await seedTables(connection, latestTimestamp, cloud);

View file

@ -49,9 +49,9 @@ export const seedOidcConfigs = async (pool: DatabaseTransactionConnection, tenan
const { value, fromEnv } = await oidcConfigReaders[key]();
if (fromEnv) {
consoleLog.info(tenantPrefix, `Read config ${chalk.green(key)} from env`);
consoleLog.succeed(tenantPrefix, `Read config ${chalk.green(key)} from env`);
} else {
consoleLog.info(tenantPrefix, `Generated config ${chalk.green(key)}`);
consoleLog.succeed(tenantPrefix, `Generated config ${chalk.green(key)}`);
}
await updateValueByKey(pool, tenantId, key, value);

View file

@ -150,7 +150,6 @@ export const decompress = async (toPath: string, tarPath: string) => {
run(),
{
text: `Decompress to ${toPath}`,
prefixText: chalk.blue('[info]'),
},
true
);
@ -166,7 +165,6 @@ export const seedDatabase = async (instancePath: string, cloud: boolean) => {
await oraPromise(fs.rm(instancePath, { force: true, recursive: true }), {
text: 'Clean up',
prefixText: chalk.blue('[info]'),
});
consoleLog.fatal(

View file

@ -51,7 +51,7 @@ export const downloadFile = async (url: string, destination: string) => {
});
const spinner = ora({
text: 'Connecting',
prefixText: chalk.blue('[info]'),
prefixText: ConsoleLog.prefixes.info,
}).start();
stream.pipe(file);
@ -91,7 +91,7 @@ export const oraPromise = async <T>(
options?: Options,
exitOnError = false
) => {
const spinner = ora(options).start();
const spinner = ora({ prefixText: ConsoleLog.prefixes.info, ...options }).start();
try {
const result = await promise;

View file

@ -1,10 +1,17 @@
import chalk from 'chalk';
export default class ConsoleLog {
static prefixes = Object.freeze({
info: chalk.bold(chalk.blue('info')),
warn: chalk.bold(chalk.yellow('warn')),
error: chalk.bold(chalk.red('error')),
fatal: chalk.bold(chalk.red('fatal')),
});
plain = console.log;
info: typeof console.log = (...args) => {
console.log(chalk.bold(chalk.blue('info')), ...args);
console.log(ConsoleLog.prefixes.info, ...args);
};
succeed: typeof console.log = (...args) => {
@ -12,15 +19,15 @@ export default class ConsoleLog {
};
warn: typeof console.log = (...args) => {
console.warn(chalk.bold(chalk.yellow('warn')), ...args);
console.warn(ConsoleLog.prefixes.warn, ...args);
};
error: typeof console.log = (...args) => {
console.error(chalk.bold(chalk.red('error')), ...args);
console.error(ConsoleLog.prefixes.error, ...args);
};
fatal: (...args: Parameters<typeof console.log>) => never = (...args) => {
console.error(chalk.bold(chalk.red('fatal')), ...args);
console.error(ConsoleLog.prefixes.fatal, ...args);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
};