mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Chore: more refactor to the bun
This commit is contained in:
parent
071b8120a6
commit
ec338a659f
@ -13,7 +13,7 @@ const getS3OSSDomains = async (): Promise<Set<string>> => {
|
|||||||
const publicSuffixFile = Bun.file(publicSuffixPath);
|
const publicSuffixFile = Bun.file(publicSuffixPath);
|
||||||
|
|
||||||
if (await publicSuffixFile.exists()) {
|
if (await publicSuffixFile.exists()) {
|
||||||
for await (const line of readFileByLine(publicSuffixPath)) {
|
for await (const line of readFileByLine(publicSuffixFile)) {
|
||||||
trie.add(line);
|
trie.add(line);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
// @ts-check
|
import tar from 'tar';
|
||||||
const tar = require('tar');
|
import fsp from 'fs/promises';
|
||||||
const fsp = require('fs/promises');
|
import path from 'path';
|
||||||
const path = require('path');
|
import os from 'os';
|
||||||
const { tmpdir } = require('os');
|
import { Readable } from 'stream';
|
||||||
const { Readable } = require('stream');
|
import { pipeline } from 'stream/promises';
|
||||||
const { pipeline } = require('stream/promises');
|
import { readFileByLine } from './lib/fetch-remote-text-by-line';
|
||||||
const { readFileByLine } = require('./lib/fetch-remote-text-by-line');
|
import { isCI } from 'ci-info';
|
||||||
const { isCI } = require('ci-info');
|
import { task, traceAsync } from './lib/trace-runner';
|
||||||
const { task, traceAsync } = require('./lib/trace-runner');
|
|
||||||
|
|
||||||
const downloadPreviousBuild = task(__filename, async () => {
|
export const downloadPreviousBuild = task(__filename, async () => {
|
||||||
const filesList = ['Clash', 'List'];
|
const filesList = ['Clash', 'List'];
|
||||||
|
|
||||||
let allFileExists = true;
|
let allFileExists = true;
|
||||||
@ -41,7 +40,7 @@ const downloadPreviousBuild = task(__filename, async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const extractedPath = path.join(tmpdir(), `sukka-surge-last-build-extracted-${Date.now()}`);
|
const extractedPath = path.join(os.tmpdir(), `sukka-surge-last-build-extracted-${Date.now()}`);
|
||||||
|
|
||||||
await traceAsync(
|
await traceAsync(
|
||||||
'Download and extract previous build',
|
'Download and extract previous build',
|
||||||
@ -49,7 +48,7 @@ const downloadPreviousBuild = task(__filename, async () => {
|
|||||||
fetch('https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master'),
|
fetch('https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master'),
|
||||||
fsp.mkdir(extractedPath, { recursive: true })
|
fsp.mkdir(extractedPath, { recursive: true })
|
||||||
]).then(([resp]) => pipeline(
|
]).then(([resp]) => pipeline(
|
||||||
Readable.fromWeb(resp.body),
|
Readable.fromWeb(resp.body!),
|
||||||
tar.x({
|
tar.x({
|
||||||
cwd: extractedPath,
|
cwd: extractedPath,
|
||||||
/**
|
/**
|
||||||
@ -78,7 +77,7 @@ const downloadPreviousBuild = task(__filename, async () => {
|
|||||||
// return fsp.unlink(extractedPath).catch(() => { });
|
// return fsp.unlink(extractedPath).catch(() => { });
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadPublicSuffixList = task(__filename, async () => {
|
export const downloadPublicSuffixList = task(__filename, async () => {
|
||||||
const publicSuffixDir = path.resolve(__dirname, '../node_modules/.cache');
|
const publicSuffixDir = path.resolve(__dirname, '../node_modules/.cache');
|
||||||
const publicSuffixPath = path.join(publicSuffixDir, 'public_suffix_list_dat.txt');
|
const publicSuffixPath = path.join(publicSuffixDir, 'public_suffix_list_dat.txt');
|
||||||
|
|
||||||
@ -90,9 +89,6 @@ const downloadPublicSuffixList = task(__filename, async () => {
|
|||||||
return Bun.write(publicSuffixPath, resp);
|
return Bun.write(publicSuffixPath, resp);
|
||||||
}, 'download-publicsuffixlist');
|
}, 'download-publicsuffixlist');
|
||||||
|
|
||||||
module.exports.downloadPreviousBuild = downloadPreviousBuild;
|
|
||||||
module.exports.downloadPublicSuffixList = downloadPublicSuffixList;
|
|
||||||
|
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
downloadPreviousBuild(),
|
downloadPreviousBuild(),
|
||||||
@ -19,7 +19,7 @@ async function compareAndWriteFile(linesA, filePath) {
|
|||||||
} else {
|
} else {
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
for await (const lineB of readFileByLine(filePath)) {
|
for await (const lineB of readFileByLine(file)) {
|
||||||
const lineA = linesA[index];
|
const lineA = linesA[index];
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint-sukka/node": "^4.1.7",
|
"@eslint-sukka/node": "^4.1.7",
|
||||||
"@types/mocha": "10.0.2",
|
"@types/mocha": "10.0.2",
|
||||||
|
"@types/tar": "^6.1.9",
|
||||||
"bun-types": "^1.0.11",
|
"bun-types": "^1.0.11",
|
||||||
"chai": "4.3.10",
|
"chai": "4.3.10",
|
||||||
"eslint-config-sukka": "4.1.7",
|
"eslint-config-sukka": "4.1.7",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user