mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-03 13:44:47 +08:00
chore: 优化build/info.ts文件中的一些函数,使其友好支持esm
This commit is contained in:
34
build/utils.ts
Normal file
34
build/utils.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { readdir, stat } from "node:fs";
|
||||
import { sum, formatBytes } from "@pureadmin/utils";
|
||||
|
||||
const fileListTotal: number[] = [];
|
||||
|
||||
/**
|
||||
* @description 获取指定文件夹中所有文件的总大小
|
||||
*/
|
||||
export const getPackageSize = options => {
|
||||
const { folder = "dist", callback, format = true } = options;
|
||||
readdir(folder, (err, files: string[]) => {
|
||||
if (err) throw err;
|
||||
let count = 0;
|
||||
const checkEnd = () => {
|
||||
++count == files.length &&
|
||||
callback(format ? formatBytes(sum(fileListTotal)) : sum(fileListTotal));
|
||||
};
|
||||
files.forEach((item: string) => {
|
||||
stat(`${folder}/${item}`, async (err, stats) => {
|
||||
if (err) throw err;
|
||||
if (stats.isFile()) {
|
||||
fileListTotal.push(stats.size);
|
||||
checkEnd();
|
||||
} else if (stats.isDirectory()) {
|
||||
getPackageSize({
|
||||
folder: `${folder}/${item}/`,
|
||||
callback: checkEnd
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
files.length === 0 && callback(0);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user