From 730eec003e5ee1f0b7533af54991661799e9a5cf Mon Sep 17 00:00:00 2001 From: SukkaW Date: Mon, 16 Dec 2024 22:39:39 +0800 Subject: [PATCH] Chore: minor changes --- Build/build-chn-cidr.ts | 8 ++------ Build/constants/description.ts | 14 +++++++++----- Build/download-previous-build.ts | 28 ++++++++++++---------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Build/build-chn-cidr.ts b/Build/build-chn-cidr.ts index f68c64ff..5c9c93e5 100644 --- a/Build/build-chn-cidr.ts +++ b/Build/build-chn-cidr.ts @@ -7,6 +7,7 @@ import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from '. import { appendArrayInPlace } from './lib/append-array-in-place'; import { IPListOutput } from './lib/create-file'; import { cachedOnlyFail } from './lib/fs-memo'; +import { createFileDescription } from './constants/description'; const PROBE_CHN_CIDR_V4 = [ // NetEase Hangzhou @@ -48,12 +49,7 @@ export const buildChnCidr = task(require.main === module, __filename)(async (spa const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise); // Can not use SHARED_DESCRIPTION here as different license - const description = [ - 'License: CC BY-SA 2.0', - 'Homepage: https://ruleset.skk.moe', - 'GitHub: https://github.com/SukkaW/Surge', - '' - ]; + const description = createFileDescription('CC BY-SA 2.0'); return Promise.all([ new IPListOutput(span, 'china_ip', false) diff --git a/Build/constants/description.ts b/Build/constants/description.ts index e3adad18..e1219b37 100644 --- a/Build/constants/description.ts +++ b/Build/constants/description.ts @@ -1,5 +1,9 @@ -export const SHARED_DESCRIPTION = [ - 'License: AGPL 3.0', - 'Homepage: https://ruleset.skk.moe', - 'GitHub: https://github.com/SukkaW/Surge' -]; +export function createFileDescription(license = 'AGPL 3.0') { + return [ + `License: ${license}`, + 'Homepage: https://ruleset.skk.moe', + 'GitHub: https://github.com/SukkaW/Surge' + ]; +} + +export const SHARED_DESCRIPTION = createFileDescription('AGPL 3.0'); diff --git a/Build/download-previous-build.ts b/Build/download-previous-build.ts index 1faa972a..005c45b2 100644 --- a/Build/download-previous-build.ts +++ b/Build/download-previous-build.ts @@ -63,7 +63,18 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a const extract = tarExtract( publicDir, { - ignore: tarOnIgnore, + ignore(_: string, header?: TarEntryHeaders) { + if (header) { + if (header.type !== 'file' && header.type !== 'directory') { + return true; + } + if (header.type === 'file' && path.extname(header.name) === '.ts') { + return true; + } + } + + return false; + }, map(header) { header.name = header.name.replace(pathPrefix, ''); return header; @@ -78,18 +89,3 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a ); }); }); - -function tarOnIgnore(_: string, header?: TarEntryHeaders) { - if (header) { - if (header.type !== 'file' && header.type !== 'directory') { - return true; - } - - const extname = path.extname(header.name); - if (extname === '.ts') { - return true; - } - } - - return false; -}