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()
|
const paths = await new Fdir()
|
||||||
.withRelativePaths()
|
.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) => {
|
.filter((filepath, isDirectory) => {
|
||||||
if (isDirectory) return true;
|
if (isDirectory) return true;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|||||||
import fsp from 'node:fs/promises';
|
import fsp from 'node:fs/promises';
|
||||||
|
|
||||||
import { task } from './trace';
|
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 type { TreeType, TreeTypeArray } from './lib/tree-dir';
|
||||||
|
|
||||||
import { OUTPUT_MOCK_DIR, OUTPUT_MODULES_DIR, PUBLIC_DIR, ROOT_DIR } from './constants/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);
|
tree.sort(prioritySorter);
|
||||||
for (let i = 0, len = tree.length; i < len; i++) {
|
for (let i = 0, len = tree.length; i < len; i++) {
|
||||||
const entry = tree[i];
|
const entry = tree[i];
|
||||||
if (entry.type === 'directory') {
|
if (entry.type === TreeFileType.DIRECTORY) {
|
||||||
result += html`
|
result += html`
|
||||||
<li class="folder">
|
<li class="folder">
|
||||||
${entry.name}
|
${entry.name}
|
||||||
|
|||||||
@@ -1,20 +1,26 @@
|
|||||||
import fsp from 'node:fs/promises';
|
import fsp from 'node:fs/promises';
|
||||||
import { sep } from 'node:path';
|
import { sep } from 'node:path';
|
||||||
|
|
||||||
interface TreeFileType {
|
// eslint-disable-next-line sukka/no-export-const-enum -- TODO: fix this in the future
|
||||||
type: 'file',
|
export const enum TreeFileType {
|
||||||
|
FILE = 1,
|
||||||
|
DIRECTORY = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TreeFile {
|
||||||
|
type: TreeFileType.FILE,
|
||||||
name: string,
|
name: string,
|
||||||
path: string
|
path: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TreeDirectoryType {
|
interface TreeDirectoryType {
|
||||||
type: 'directory',
|
type: TreeFileType.DIRECTORY,
|
||||||
name: string,
|
name: string,
|
||||||
path: string,
|
path: string,
|
||||||
children: TreeTypeArray
|
children: TreeTypeArray
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TreeType = TreeDirectoryType | TreeFileType;
|
export type TreeType = TreeDirectoryType | TreeFile;
|
||||||
export type TreeTypeArray = TreeType[];
|
export type TreeTypeArray = TreeType[];
|
||||||
|
|
||||||
type VoidOrVoidArray = void | VoidOrVoidArray[];
|
type VoidOrVoidArray = void | VoidOrVoidArray[];
|
||||||
@@ -35,7 +41,7 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
|
|||||||
|
|
||||||
if (child.isDirectory()) {
|
if (child.isDirectory()) {
|
||||||
const newNode: TreeDirectoryType = {
|
const newNode: TreeDirectoryType = {
|
||||||
type: 'directory',
|
type: TreeFileType.DIRECTORY,
|
||||||
name: child.name,
|
name: child.name,
|
||||||
path: childRelativeToRoot,
|
path: childRelativeToRoot,
|
||||||
children: []
|
children: []
|
||||||
@@ -45,8 +51,8 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (child.isFile()) {
|
if (child.isFile()) {
|
||||||
const newNode: TreeFileType = {
|
const newNode: TreeFile = {
|
||||||
type: 'file',
|
type: TreeFileType.FILE,
|
||||||
name: child.name,
|
name: child.name,
|
||||||
path: childRelativeToRoot
|
path: childRelativeToRoot
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user