mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Perf: avoid string comparision
This commit is contained in:
@@ -23,13 +23,6 @@ export const buildCommon = task(require.main === module, __filename)(async (span
|
||||
|
||||
const paths = await new Fdir()
|
||||
.withRelativePaths()
|
||||
// .exclude((dirName, dirPath) => {
|
||||
// if (dirName === 'domainset' || dirName === 'ip' || dirName === 'non_ip') {
|
||||
// return false;
|
||||
// }
|
||||
// console.error(picocolors.red(`[build-comman] Unknown dir: ${dirPath}`));
|
||||
// return true;
|
||||
// })
|
||||
.filter((filepath, isDirectory) => {
|
||||
if (isDirectory) return true;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
||||
import fsp from 'node:fs/promises';
|
||||
|
||||
import { task } from './trace';
|
||||
import { treeDir } from './lib/tree-dir';
|
||||
import { treeDir, TreeFileType } from './lib/tree-dir';
|
||||
import type { TreeType, TreeTypeArray } from './lib/tree-dir';
|
||||
|
||||
import { OUTPUT_MOCK_DIR, OUTPUT_MODULES_DIR, PUBLIC_DIR, ROOT_DIR } from './constants/dir';
|
||||
@@ -101,7 +101,7 @@ function walk(tree: TreeTypeArray) {
|
||||
tree.sort(prioritySorter);
|
||||
for (let i = 0, len = tree.length; i < len; i++) {
|
||||
const entry = tree[i];
|
||||
if (entry.type === 'directory') {
|
||||
if (entry.type === TreeFileType.DIRECTORY) {
|
||||
result += html`
|
||||
<li class="folder">
|
||||
${entry.name}
|
||||
|
||||
@@ -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