feat(cli): add stepper to improve logging
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
import logger from 'signale';
|
||||
import decamelize from 'decamelize';
|
||||
import { join } from 'path';
|
||||
import { get } from 'lodash';
|
||||
import { readdirSync, existsSync, lstatSync, readFileSync } from 'fs-extra';
|
||||
import { CONFIG, SRC_DIR, WEBPACK_CONFIG_FILE } from './constant';
|
||||
|
||||
logger.config({
|
||||
displayTimestamp: true
|
||||
});
|
||||
|
||||
export const EXT_REGEXP = /\.\w+$/;
|
||||
export const SFC_REGEXP = /\.(vue)$/;
|
||||
export const DEMO_REGEXP = /\/demo$/;
|
||||
@@ -119,4 +114,4 @@ export function getCssLang(): string {
|
||||
return preprocessor;
|
||||
}
|
||||
|
||||
export { logger, decamelize };
|
||||
export { decamelize };
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import logger from 'signale';
|
||||
|
||||
logger.config({
|
||||
displayTimestamp: true
|
||||
});
|
||||
|
||||
const methods = ['success', 'start', 'error'] as const;
|
||||
|
||||
type Stepper = Pick<typeof logger, typeof methods[number]>;
|
||||
|
||||
export function getStepper(totalStep: number) {
|
||||
const stepper = {} as Stepper;
|
||||
let currentStep = 0;
|
||||
|
||||
methods.forEach(key => {
|
||||
stepper[key] = (message, ...args) => {
|
||||
const prefix = `[${++currentStep}/${totalStep}] `;
|
||||
return logger[key](prefix + message, ...args);
|
||||
};
|
||||
});
|
||||
|
||||
return stepper;
|
||||
}
|
||||
|
||||
export { logger };
|
||||
Reference in New Issue
Block a user