Perf: improve generate public speed [skip ci]

This commit is contained in:
SukkaW
2025-06-07 19:00:03 +08:00
parent a671973858
commit 9635db8288
3 changed files with 48 additions and 45 deletions

View File

@@ -1,5 +1,6 @@
import fsp from 'node:fs/promises';
import { sep } from 'node:path';
import type { VoidOrVoidArray } from './misc';
// eslint-disable-next-line sukka/no-export-const-enum -- TODO: fix this in the future
export const enum TreeFileType {
@@ -23,13 +24,12 @@ interface TreeDirectoryType {
export type TreeType = TreeDirectoryType | TreeFile;
export type TreeTypeArray = TreeType[];
type VoidOrVoidArray = void | VoidOrVoidArray[];
export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
const tree: TreeTypeArray = [];
const promises: Array<Promise<VoidOrVoidArray>> = [];
const walk = async (dir: string, node: TreeTypeArray, dirRelativeToRoot = ''): Promise<VoidOrVoidArray> => {
const promises: Array<Promise<VoidOrVoidArray>> = [];
for await (const child of await fsp.opendir(dir)) {
// Ignore hidden files
if (child.name[0] === '.' || child.name === 'CNAME') {
@@ -60,10 +60,10 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
continue;
}
}
return Promise.all(promises);
};
await walk(rootPath, tree);
await Promise.all(promises);
return tree;
}