mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: avoid string comparision
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
import fsp from 'node:fs/promises';
|
||||
import { sep } from 'node:path';
|
||||
|
||||
interface TreeFileType {
|
||||
type: 'file',
|
||||
// eslint-disable-next-line sukka/no-export-const-enum -- TODO: fix this in the future
|
||||
export const enum TreeFileType {
|
||||
FILE = 1,
|
||||
DIRECTORY = 2
|
||||
}
|
||||
|
||||
interface TreeFile {
|
||||
type: TreeFileType.FILE,
|
||||
name: string,
|
||||
path: string
|
||||
}
|
||||
|
||||
interface TreeDirectoryType {
|
||||
type: 'directory',
|
||||
type: TreeFileType.DIRECTORY,
|
||||
name: string,
|
||||
path: string,
|
||||
children: TreeTypeArray
|
||||
}
|
||||
|
||||
export type TreeType = TreeDirectoryType | TreeFileType;
|
||||
export type TreeType = TreeDirectoryType | TreeFile;
|
||||
export type TreeTypeArray = TreeType[];
|
||||
|
||||
type VoidOrVoidArray = void | VoidOrVoidArray[];
|
||||
@@ -35,7 +41,7 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
|
||||
|
||||
if (child.isDirectory()) {
|
||||
const newNode: TreeDirectoryType = {
|
||||
type: 'directory',
|
||||
type: TreeFileType.DIRECTORY,
|
||||
name: child.name,
|
||||
path: childRelativeToRoot,
|
||||
children: []
|
||||
@@ -45,8 +51,8 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
|
||||
continue;
|
||||
}
|
||||
if (child.isFile()) {
|
||||
const newNode: TreeFileType = {
|
||||
type: 'file',
|
||||
const newNode: TreeFile = {
|
||||
type: TreeFileType.FILE,
|
||||
name: child.name,
|
||||
path: childRelativeToRoot
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user