wireguard-dashboard-admin/build/info.ts

58 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2022-02-27 13:31:19 +08:00
import type { Plugin } from "vite";
2024-03-09 16:27:52 +08:00
import { getPackageSize } from "./utils";
import dayjs, { type Dayjs } from "dayjs";
2022-02-27 13:31:19 +08:00
import duration from "dayjs/plugin/duration";
2024-03-09 16:27:52 +08:00
import gradientString from "gradient-string";
import boxen, { type Options as BoxenOptions } from "boxen";
2022-02-27 13:31:19 +08:00
dayjs.extend(duration);
2024-03-09 16:27:52 +08:00
const welcomeMessage = gradientString("cyan", "magenta").multiline(
2024-05-10 12:09:23 +08:00
`您好! 欢迎使用 pure-admin 开源项目\n我们为您精心准备了下面两个贴心的保姆级文档\nhttps://pure-admin.github.io/pure-admin-doc\nhttps://pure-admin-utils.netlify.app`
2024-03-09 16:27:52 +08:00
);
const boxenOptions: BoxenOptions = {
padding: 0.5,
borderColor: "cyan",
borderStyle: "round"
};
2022-02-27 13:31:19 +08:00
export function viteBuildInfo(): Plugin {
let config: { command: string };
let startTime: Dayjs;
let endTime: Dayjs;
2022-12-03 15:20:30 +08:00
let outDir: string;
2022-02-27 13:31:19 +08:00
return {
name: "vite:buildInfo",
2022-12-03 15:20:30 +08:00
configResolved(resolvedConfig) {
2022-02-27 13:31:19 +08:00
config = resolvedConfig;
2022-12-03 15:20:30 +08:00
outDir = resolvedConfig.build?.outDir ?? "dist";
2022-02-27 13:31:19 +08:00
},
buildStart() {
2024-03-09 16:27:52 +08:00
console.log(boxen(welcomeMessage, boxenOptions));
2022-02-27 13:31:19 +08:00
if (config.command === "build") {
startTime = dayjs(new Date());
}
},
closeBundle() {
if (config.command === "build") {
endTime = dayjs(new Date());
2024-03-09 16:27:52 +08:00
getPackageSize({
2022-12-03 15:20:30 +08:00
folder: outDir,
2022-08-22 21:34:55 +08:00
callback: (size: string) => {
console.log(
2024-03-09 16:27:52 +08:00
boxen(
gradientString("cyan", "magenta").multiline(
`🎉 恭喜打包完成(总用时${dayjs
2022-08-22 21:34:55 +08:00
.duration(endTime.diff(startTime))
.format("mm分ss秒")}${size}`
2024-03-09 16:27:52 +08:00
),
boxenOptions
2022-02-27 13:31:19 +08:00
)
2022-08-22 21:34:55 +08:00
);
}
2022-02-27 13:31:19 +08:00
});
}
}
};
}