vehicle-monitor/build/info.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-02-26 16:31:59 +08:00
import boxen, { type Options as BoxenOptions } from 'boxen';
import dayjs, { type Dayjs } from 'dayjs';
import duration from 'dayjs/plugin/duration';
import gradientString from 'gradient-string';
import { wrapperEnv } from './utils';
2025-02-24 22:45:14 +08:00
dayjs.extend(duration);
const boxenOptions: BoxenOptions = {
2025-02-25 23:14:50 +08:00
padding: 0.94,
2025-02-26 16:31:59 +08:00
borderColor: 'cyan',
borderStyle: 'round',
textAlignment: 'left',
2025-02-24 22:45:14 +08:00
};
/* 输出日志信息 */
const printLogMessage = (VITE_PORT: number) => {
2025-02-26 16:31:59 +08:00
return gradientString('cyan', 'magenta').multiline(
2025-03-13 23:01:44 +08:00
`欢迎使用此项目,项目访问地址如下:
2025-02-25 23:14:50 +08:00
http://localhost:${VITE_PORT}`
);
2025-02-24 22:45:14 +08:00
};
2025-02-25 23:14:50 +08:00
export const viteConsoleLog = (mode) => {
const { VITE_PORT } = wrapperEnv(mode);
2025-02-24 22:45:14 +08:00
2025-02-25 23:14:50 +08:00
let config: { command: string };
let startTime: Dayjs;
let endTime: Dayjs;
return {
2025-02-26 16:31:59 +08:00
name: 'vite:buildInfo',
2025-02-25 23:14:50 +08:00
configResolved(resolvedConfig) {
config = resolvedConfig;
},
buildStart() {
console.log(boxen(printLogMessage(VITE_PORT), boxenOptions));
2025-02-26 16:31:59 +08:00
if (config.command === 'build') {
2025-02-25 23:14:50 +08:00
startTime = dayjs(new Date());
}
},
closeBundle() {
2025-02-26 16:31:59 +08:00
if (config.command === 'build') {
2025-02-25 23:14:50 +08:00
endTime = dayjs(new Date());
2025-02-26 16:31:59 +08:00
const format = dayjs.duration(endTime.diff(startTime)).format('mm分ss秒');
2025-02-25 23:14:50 +08:00
console.log(
boxen(
2025-02-26 16:31:59 +08:00
gradientString('cyan', 'magenta').multiline(`🎉 恭喜打包完成(总用时${format}`),
2025-02-25 23:14:50 +08:00
boxenOptions
)
);
}
},
};
2025-02-24 22:45:14 +08:00
};