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:
parent
3206ab2daa
commit
310698b0d2
7 changed files with 21 additions and 13 deletions
6
.changeset/three-pigs-search.md
Normal file
6
.changeset/three-pigs-search.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
"@logto/shared": patch
|
||||
"@logto/cli": patch
|
||||
---
|
||||
|
||||
align cli output for a better looking
|
|
@ -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`);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
15
packages/shared/src/node/env/ConsoleLog.ts
vendored
15
packages/shared/src/node/env/ConsoleLog.ts
vendored
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue