mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: refactor output dir
This commit is contained in:
@@ -3,8 +3,9 @@ import { processLine, processLineFromReadline } from './process-line';
|
||||
import { readFileByLine } from './fetch-text-by-line';
|
||||
import path from 'node:path';
|
||||
import fsp from 'node:fs/promises';
|
||||
import { SOURCE_DIR } from '../constants/dir';
|
||||
|
||||
const file = path.resolve(__dirname, '../../Source/domainset/cdn.conf');
|
||||
const file = path.join(SOURCE_DIR, 'domainset/cdn.conf');
|
||||
|
||||
group('read file by line', () => {
|
||||
bench('readFileByLine', () => processLineFromReadline(readFileByLine(file)));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import path, { dirname } from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import fsp from 'node:fs/promises';
|
||||
import { OUTPUT_CLASH_DIR, OUTPUT_SINGBOX_DIR, OUTPUT_SURGE_DIR } from '../constants/dir';
|
||||
|
||||
export const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
|
||||
|
||||
@@ -52,10 +53,6 @@ export const domainWildCardToRegex = (domain: string) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
const OUTPUT_SURGE_DIR = path.resolve(__dirname, '../../List');
|
||||
const OUTPUT_CLASH_DIR = path.resolve(__dirname, '../../Clash');
|
||||
const OUTPUT_SINGBOX_DIR = path.resolve(__dirname, '../../sing-box');
|
||||
|
||||
export const output = (id: string, type: 'non_ip' | 'ip' | 'domainset') => {
|
||||
return [
|
||||
path.join(OUTPUT_SURGE_DIR, type, id + '.conf'),
|
||||
|
||||
@@ -25,6 +25,11 @@ export const treeDir = async (rootPath: string): Promise<TreeTypeArray> => {
|
||||
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') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const childFullPath = child.parentPath + sep + child.name;
|
||||
const childRelativeToRoot = dirRelativeToRoot + sep + child.name;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user