mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Perf: speed up public folder setup / remove unused mkdir call
This commit is contained in:
parent
74293ac2f8
commit
38be4ab0c6
@ -1,4 +1,3 @@
|
|||||||
import fsp from 'fs/promises';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as tldts from 'tldts';
|
import * as tldts from 'tldts';
|
||||||
import { processLine } from './lib/process-line';
|
import { processLine } from './lib/process-line';
|
||||||
@ -67,9 +66,7 @@ export const buildInternalCDNDomains = task(import.meta.path, async () => {
|
|||||||
processLocalRuleSet(path.resolve(import.meta.dir, '../List/non_ip/stream.conf')),
|
processLocalRuleSet(path.resolve(import.meta.dir, '../List/non_ip/stream.conf')),
|
||||||
processLocalRuleSet(path.resolve(import.meta.dir, '../List/non_ip/telegram.conf')),
|
processLocalRuleSet(path.resolve(import.meta.dir, '../List/non_ip/telegram.conf')),
|
||||||
processLocalDomainSet(path.resolve(import.meta.dir, '../List/domainset/cdn.conf')),
|
processLocalDomainSet(path.resolve(import.meta.dir, '../List/domainset/cdn.conf')),
|
||||||
processLocalDomainSet(path.resolve(import.meta.dir, '../List/domainset/download.conf')),
|
processLocalDomainSet(path.resolve(import.meta.dir, '../List/domainset/download.conf'))
|
||||||
|
|
||||||
fsp.mkdir(path.resolve(import.meta.dir, '../List/internal'), { recursive: true })
|
|
||||||
]))[0];
|
]))[0];
|
||||||
|
|
||||||
return compareAndWriteFile(
|
return compareAndWriteFile(
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { fetchRemoteTextAndReadByLine } from './lib/fetch-text-by-line';
|
import { fetchRemoteTextAndReadByLine } from './lib/fetch-text-by-line';
|
||||||
import { processLineFromReadline } from './lib/process-line';
|
import { processLineFromReadline } from './lib/process-line';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fsp from 'fs/promises';
|
|
||||||
import { task } from './lib/trace-runner';
|
import { task } from './lib/trace-runner';
|
||||||
|
|
||||||
import { exclude, merge } from 'fast-cidr-tools';
|
import { exclude, merge } from 'fast-cidr-tools';
|
||||||
@ -27,10 +26,7 @@ const RESERVED_IPV4_CIDR = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const buildInternalReverseChnCIDR = task(import.meta.path, async () => {
|
export const buildInternalReverseChnCIDR = task(import.meta.path, async () => {
|
||||||
const cidr = (await Promise.all([
|
const cidr = await processLineFromReadline(await fetchRemoteTextAndReadByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt'));
|
||||||
processLineFromReadline(await fetchRemoteTextAndReadByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt')),
|
|
||||||
fsp.mkdir(path.resolve(import.meta.dir, '../List/internal'), { recursive: true })
|
|
||||||
]))[0];
|
|
||||||
|
|
||||||
const reversedCidr = merge(
|
const reversedCidr = merge(
|
||||||
exclude(
|
exclude(
|
||||||
|
|||||||
@ -1,31 +1,37 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fsp from 'fs/promises';
|
|
||||||
import { task } from './lib/trace-runner';
|
import { task } from './lib/trace-runner';
|
||||||
import { treeDir } from './lib/tree-dir';
|
import { treeDir } from './lib/tree-dir';
|
||||||
import type { TreeType, TreeTypeArray } from './lib/tree-dir';
|
import type { TreeType, TreeTypeArray } from './lib/tree-dir';
|
||||||
|
import listDir from '@sukka/listdir';
|
||||||
|
|
||||||
const rootPath = path.resolve(import.meta.dir, '../');
|
const rootPath = path.resolve(import.meta.dir, '../');
|
||||||
const publicPath = path.resolve(import.meta.dir, '../public');
|
const publicPath = path.resolve(import.meta.dir, '../public');
|
||||||
|
|
||||||
const folderAndFilesToBeDeployed = [
|
const folderAndFilesToBeDeployed = [
|
||||||
'Mock',
|
`Mock${path.sep}`,
|
||||||
'List',
|
`List${path.sep}`,
|
||||||
'Clash',
|
`Clash${path.sep}`,
|
||||||
'Modules',
|
`Modules${path.sep}`,
|
||||||
'Script',
|
`Script${path.sep}`,
|
||||||
'LICENSE'
|
'LICENSE'
|
||||||
];
|
];
|
||||||
|
|
||||||
export const buildPublic = task(import.meta.path, async () => {
|
export const buildPublic = task(import.meta.path, async () => {
|
||||||
await fsp.mkdir(publicPath, { recursive: true });
|
const filesToBeCopied = (await listDir(
|
||||||
await Promise.all(folderAndFilesToBeDeployed.map(dir => fsp.cp(
|
rootPath, {
|
||||||
path.resolve(rootPath, dir),
|
ignoreHidden: true,
|
||||||
path.resolve(publicPath, dir),
|
ignorePattern: /node_modules|Build|public/
|
||||||
{ force: true, recursive: true }
|
}
|
||||||
)));
|
)).filter(file => folderAndFilesToBeDeployed.some(folderOrFile => file.startsWith(folderOrFile)));
|
||||||
|
|
||||||
|
await Promise.all(filesToBeCopied.map(file => {
|
||||||
|
const src = path.resolve(rootPath, file);
|
||||||
|
const dest = path.resolve(publicPath, file);
|
||||||
|
|
||||||
|
return Bun.write(dest, Bun.file(src));
|
||||||
|
}));
|
||||||
|
|
||||||
const html = generateHtml(await treeDir(publicPath));
|
const html = generateHtml(await treeDir(publicPath));
|
||||||
|
|
||||||
return Bun.write(path.join(publicPath, 'index.html'), html);
|
return Bun.write(path.join(publicPath, 'index.html'), html);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,7 +105,7 @@ function generateHtml(tree: TreeTypeArray) {
|
|||||||
<p>
|
<p>
|
||||||
Made by <a href="https://skk.moe">Sukka</a> | <a href="https://github.com/SukkaW/Surge/">Source @ GitHub</a> | Licensed under <a href="/LICENSE" target="_blank">AGPL-3.0</a>
|
Made by <a href="https://skk.moe">Sukka</a> | <a href="https://github.com/SukkaW/Surge/">Source @ GitHub</a> | Licensed under <a href="/LICENSE" target="_blank">AGPL-3.0</a>
|
||||||
</p>
|
</p>
|
||||||
<p>Last Build: 2023-12-03T16:54:15.820Z</p>
|
<p>Last Build: ${new Date().toISOString()}</p>
|
||||||
<br>`;
|
<br>`;
|
||||||
|
|
||||||
html += '<ul class="directory-list">';
|
html += '<ul class="directory-list">';
|
||||||
|
|||||||
@ -101,8 +101,6 @@ export const buildSSPanelUIMAppProfile = task(import.meta.path, async () => {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
await fsp.mkdir(path.resolve(import.meta.dir, '../List/internal'), { recursive: true });
|
|
||||||
|
|
||||||
await compareAndWriteFile(
|
await compareAndWriteFile(
|
||||||
output,
|
output,
|
||||||
path.resolve(import.meta.dir, '../List/internal/appprofile.php')
|
path.resolve(import.meta.dir, '../List/internal/appprofile.php')
|
||||||
|
|||||||
@ -47,19 +47,20 @@ export const downloadPreviousBuild = task(import.meta.path, async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const extractedPath = path.join(os.tmpdir(), `sukka-surge-last-build-extracted-${Date.now()}`);
|
|
||||||
const filesList = buildOutputList.map(f => path.join('ruleset.skk.moe-master', f));
|
const filesList = buildOutputList.map(f => path.join('ruleset.skk.moe-master', f));
|
||||||
|
|
||||||
await traceAsync(
|
await traceAsync(
|
||||||
'Download and extract previous build',
|
'Download and extract previous build',
|
||||||
async () => {
|
async () => {
|
||||||
const resp = (await Promise.all([
|
const resp = await fetchWithRetry('https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master', defaultRequestInit);
|
||||||
fetchWithRetry('https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master', defaultRequestInit),
|
|
||||||
fsp.mkdir(extractedPath, { recursive: true })
|
if (!resp.body) {
|
||||||
]))[0];
|
throw new Error('Download previous build failed! No body found');
|
||||||
|
}
|
||||||
|
|
||||||
const extract = tarStream.extract();
|
const extract = tarStream.extract();
|
||||||
Readable.fromWeb(resp.body!).pipe(zlib.createGunzip()).pipe(extract);
|
Readable.fromWeb(resp.body).pipe(zlib.createGunzip()).pipe(extract);
|
||||||
|
|
||||||
for await (const entry of extract) {
|
for await (const entry of extract) {
|
||||||
if (entry.header.type !== 'file') {
|
if (entry.header.type !== 'file') {
|
||||||
entry.resume(); // Drain the entry
|
entry.resume(); // Drain the entry
|
||||||
@ -85,13 +86,8 @@ export const downloadPreviousBuild = task(import.meta.path, async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const downloadPublicSuffixList = task(import.meta.path, async () => {
|
export const downloadPublicSuffixList = task(import.meta.path, async () => {
|
||||||
const publicSuffixDir = path.resolve(import.meta.dir, '../node_modules/.cache');
|
const publicSuffixPath = path.resolve(import.meta.dir, '../node_modules/.cache/public_suffix_list_dat.txt');
|
||||||
const publicSuffixPath = path.join(publicSuffixDir, 'public_suffix_list_dat.txt');
|
const resp = await fetchWithRetry('https://publicsuffix.org/list/public_suffix_list.dat', defaultRequestInit);
|
||||||
|
|
||||||
const resp = (await Promise.all([
|
|
||||||
fetchWithRetry('https://publicsuffix.org/list/public_suffix_list.dat', defaultRequestInit),
|
|
||||||
fsp.mkdir(publicSuffixDir, { recursive: true })
|
|
||||||
]))[0];
|
|
||||||
|
|
||||||
return Bun.write(publicSuffixPath, resp as Response);
|
return Bun.write(publicSuffixPath, resp as Response);
|
||||||
}, 'download-publicsuffixlist');
|
}, 'download-publicsuffixlist');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user