mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: improve generate public speed [skip ci]
This commit is contained in:
@@ -32,6 +32,8 @@ interface Write {
|
||||
): Promise<void>
|
||||
}
|
||||
|
||||
export type VoidOrVoidArray = void | VoidOrVoidArray[];
|
||||
|
||||
export function mkdirp(dir: string) {
|
||||
if (fs.existsSync(dir)) {
|
||||
return;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user