feat: Add log --level cli option (#1973)
Co-authored-by: nickbar01234 <nickbar01234gmail.com> Co-authored-by: Aaron <aaronklinker1@gmail.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
initialize,
|
||||
} from '../../core';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
import consola from 'consola';
|
||||
import consola, { LogLevels } from 'consola';
|
||||
|
||||
vi.mock('../../core/build');
|
||||
const buildMock = vi.mocked(build);
|
||||
@@ -139,6 +139,21 @@ describe('CLI', () => {
|
||||
expect(createServerMock).toBeCalledWith({
|
||||
debug: true,
|
||||
});
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
|
||||
it('should set log --level', async () => {
|
||||
mockArgv('--level', 'warn');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.warn);
|
||||
});
|
||||
|
||||
it('--debug should override --level', async () => {
|
||||
mockArgv('--debug', '--level', 'silent');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -231,6 +246,21 @@ describe('CLI', () => {
|
||||
expect(buildMock).toBeCalledWith({
|
||||
debug: true,
|
||||
});
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
|
||||
it('should set log --level', async () => {
|
||||
mockArgv('build', '--level', 'warn');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.warn);
|
||||
});
|
||||
|
||||
it('--debug should override --level', async () => {
|
||||
mockArgv('build', '--debug', '--level', 'silent');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -312,6 +342,21 @@ describe('CLI', () => {
|
||||
debug: true,
|
||||
zip: {},
|
||||
});
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
|
||||
it('should set log --level', async () => {
|
||||
mockArgv('zip', '--level', 'warn');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.warn);
|
||||
});
|
||||
|
||||
it('--debug should override --level', async () => {
|
||||
mockArgv('zip', '--debug', '--level', 'silent');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
|
||||
it('should pass undefined for zipSources when --sources is not passed', async () => {
|
||||
@@ -381,6 +426,21 @@ describe('CLI', () => {
|
||||
expect(prepareMock).toBeCalledWith({
|
||||
debug: true,
|
||||
});
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
|
||||
it('should set log --level', async () => {
|
||||
mockArgv('prepare', '--level', 'warn');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.warn);
|
||||
});
|
||||
|
||||
it('--debug should override --level', async () => {
|
||||
mockArgv('prepare', '--debug', '--level', 'silent');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -415,6 +475,21 @@ describe('CLI', () => {
|
||||
expect(cleanMock).toBeCalledWith({
|
||||
debug: true,
|
||||
});
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
|
||||
it('should set log --level', async () => {
|
||||
mockArgv('clean', '--level', 'warn');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.warn);
|
||||
});
|
||||
|
||||
it('--debug should override --level', async () => {
|
||||
mockArgv('clean', '--debug', '--level', 'silent');
|
||||
await importCli();
|
||||
|
||||
expect(consola.level).toBe(LogLevels.debug);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CAC, Command } from 'cac';
|
||||
import consola, { LogLevels } from 'consola';
|
||||
import consola, { LogLevels, LogType } from 'consola';
|
||||
import { filterTruthy, toArray } from '../core/utils/arrays';
|
||||
import { printHeader } from '../core/utils/log';
|
||||
import { formatDuration } from '../core/utils/time';
|
||||
@@ -19,6 +19,11 @@ export function wrapAction(
|
||||
},
|
||||
) {
|
||||
return async (...args: any[]) => {
|
||||
const level: LogType | undefined = args.find((arg) => arg?.level)?.level;
|
||||
if (level && Object.keys(LogLevels).includes(level)) {
|
||||
consola.level = LogLevels[level];
|
||||
}
|
||||
|
||||
// Enable consola's debug mode globally at the start of all commands when
|
||||
// the `--debug` flag is passed
|
||||
const isDebug = !!args.find((arg) => arg?.debug);
|
||||
|
||||
@@ -9,6 +9,10 @@ import {
|
||||
const cli = cac('wxt');
|
||||
|
||||
cli.option('--debug', 'enable debug mode');
|
||||
cli.option(
|
||||
'--level <level>',
|
||||
'specify log level ("silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose")',
|
||||
);
|
||||
|
||||
// DEV
|
||||
cli
|
||||
|
||||
Reference in New Issue
Block a user