diff --git a/package.json b/package.json index 5a2715bb..0bf9cf26 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@types/json-schema": "^7.0.15", "ahooks": "^3.8.0", "axios": "^1.7.2", + "cli-color": "^2.0.4", "dayjs": "1.11.5", "foxact": "^0.2.35", "i18next": "^23.11.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 21481811..64a42352 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -73,6 +73,9 @@ importers: axios: specifier: ^1.7.2 version: 1.7.2 + cli-color: + specifier: ^2.0.4 + version: 2.0.4 dayjs: specifier: 1.11.5 version: 1.11.5 @@ -2624,6 +2627,13 @@ packages: } engines: { node: ">=10" } + cli-color@2.0.4: + resolution: + { + integrity: sha512-zlnpg0jNcibNrO7GG9IeHH7maWFeCz+Ja1wx/7tZNU5ASSSSZ+/qZciM0/LHCYxSdqv5h2sdbQ/PXYdOuetXvA==, + } + engines: { node: ">=0.10" } + client-only@0.0.1: resolution: { @@ -2739,6 +2749,13 @@ packages: integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==, } + d@1.0.2: + resolution: + { + integrity: sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==, + } + engines: { node: ">=0.12" } + data-uri-to-buffer@4.0.1: resolution: { @@ -2833,6 +2850,32 @@ packages: integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==, } + es5-ext@0.10.64: + resolution: + { + integrity: sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==, + } + engines: { node: ">=0.10" } + + es6-iterator@2.0.3: + resolution: + { + integrity: sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==, + } + + es6-symbol@3.1.4: + resolution: + { + integrity: sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==, + } + engines: { node: ">=0.12" } + + es6-weak-map@2.0.3: + resolution: + { + integrity: sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==, + } + esbuild@0.21.5: resolution: { @@ -2862,6 +2905,13 @@ packages: } engines: { node: ">=10" } + esniff@2.0.1: + resolution: + { + integrity: sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==, + } + engines: { node: ">=0.10" } + estree-util-is-identifier-name@3.0.0: resolution: { @@ -2881,6 +2931,12 @@ packages: } engines: { node: ">=0.10.0" } + event-emitter@0.3.5: + resolution: + { + integrity: sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==, + } + execa@4.1.0: resolution: { @@ -2888,6 +2944,12 @@ packages: } engines: { node: ">=10" } + ext@1.7.0: + resolution: + { + integrity: sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==, + } + extend@3.0.2: resolution: { @@ -3190,6 +3252,12 @@ packages: } engines: { node: ">=0.10.0" } + is-promise@2.2.2: + resolution: + { + integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==, + } + is-stream@2.0.1: resolution: { @@ -3326,6 +3394,12 @@ packages: } engines: { node: ">=10" } + lru-queue@0.1.0: + resolution: + { + integrity: sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==, + } + magic-string@0.30.10: resolution: { @@ -3380,6 +3454,13 @@ packages: integrity: sha512-0H44vDimn51F0YwvxSJSm0eCDOJTRlmN0R1yBh4HLj9wiV1Dn0QoXGbvFAWj2hSItVTlCmBF1hqKlIyUBVFLPg==, } + memoizee@0.4.17: + resolution: + { + integrity: sha512-DGqD7Hjpi/1or4F/aYAspXKNm5Yili0QDAFAY4QYvpqpgiY6+1jOfqpmByzjxbWd/T9mChbCArXAbDAsTm5oXA==, + } + engines: { node: ">=0.12" } + meow@13.2.0: resolution: { @@ -3644,6 +3725,12 @@ packages: engines: { node: ^18 || >=20 } hasBin: true + next-tick@1.1.0: + resolution: + { + integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==, + } + no-case@3.0.4: resolution: { @@ -4278,6 +4365,13 @@ packages: engines: { node: ">=10" } hasBin: true + timers-ext@0.1.8: + resolution: + { + integrity: sha512-wFH7+SEAcKfJpfLPkrgMPvvwnEtj8W4IurvEyrKsDleXnKLCDw71w8jltvfLa8Rm4qQxxT4jmDBYbJG/z7qoww==, + } + engines: { node: ">=0.12" } + to-fast-properties@2.0.0: resolution: { @@ -4323,6 +4417,12 @@ packages: } engines: { node: ">=0.6.11 <=0.7.0 || >=0.7.3" } + type@2.7.3: + resolution: + { + integrity: sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==, + } + types-pac@1.0.2: resolution: { @@ -6310,6 +6410,14 @@ snapshots: chownr@2.0.0: {} + cli-color@2.0.4: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + es6-iterator: 2.0.3 + memoizee: 0.4.17 + timers-ext: 0.1.8 + client-only@0.0.1: {} clsx@2.1.1: {} @@ -6369,6 +6477,11 @@ snapshots: csstype@3.1.3: {} + d@1.0.2: + dependencies: + es5-ext: 0.10.64 + type: 2.7.3 + data-uri-to-buffer@4.0.1: {} dayjs@1.11.5: {} @@ -6413,6 +6526,31 @@ snapshots: dependencies: is-arrayish: 0.2.1 + es5-ext@0.10.64: + dependencies: + es6-iterator: 2.0.3 + es6-symbol: 3.1.4 + esniff: 2.0.1 + next-tick: 1.1.0 + + es6-iterator@2.0.3: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + es6-symbol: 3.1.4 + + es6-symbol@3.1.4: + dependencies: + d: 1.0.2 + ext: 1.7.0 + + es6-weak-map@2.0.3: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + es6-iterator: 2.0.3 + es6-symbol: 3.1.4 + esbuild@0.21.5: optionalDependencies: "@esbuild/aix-ppc64": 0.21.5 @@ -6445,12 +6583,24 @@ snapshots: escape-string-regexp@4.0.0: {} + esniff@2.0.1: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + event-emitter: 0.3.5 + type: 2.7.3 + estree-util-is-identifier-name@3.0.0: {} estree-walker@2.0.2: {} esutils@2.0.3: {} + event-emitter@0.3.5: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + execa@4.1.0: dependencies: cross-spawn: 7.0.3 @@ -6463,6 +6613,10 @@ snapshots: signal-exit: 3.0.7 strip-final-newline: 2.0.0 + ext@1.7.0: + dependencies: + type: 2.7.3 + extend@3.0.2: {} fetch-blob@3.2.0: @@ -6622,6 +6776,8 @@ snapshots: is-plain-object@5.0.0: {} + is-promise@2.2.2: {} + is-stream@2.0.1: {} isexe@2.0.0: {} @@ -6676,6 +6832,10 @@ snapshots: dependencies: yallist: 4.0.0 + lru-queue@0.1.0: + dependencies: + es5-ext: 0.10.64 + magic-string@0.30.10: dependencies: "@jridgewell/sourcemap-codec": 1.4.15 @@ -6769,6 +6929,17 @@ snapshots: dependencies: "@types/mdast": 4.0.4 + memoizee@0.4.17: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + es6-weak-map: 2.0.3 + event-emitter: 0.3.5 + is-promise: 2.2.2 + lru-queue: 0.1.0 + next-tick: 1.1.0 + timers-ext: 0.1.8 + meow@13.2.0: {} merge-stream@2.0.0: {} @@ -6971,6 +7142,8 @@ snapshots: nanoid@5.0.7: {} + next-tick@1.1.0: {} + no-case@3.0.4: dependencies: lower-case: 2.0.2 @@ -7355,6 +7528,11 @@ snapshots: commander: 2.20.3 source-map-support: 0.5.21 + timers-ext@0.1.8: + dependencies: + es5-ext: 0.10.64 + next-tick: 1.1.0 + to-fast-properties@2.0.0: {} to-regex-range@5.0.1: @@ -7371,6 +7549,8 @@ snapshots: tunnel@0.0.6: {} + type@2.7.3: {} + types-pac@1.0.2: {} typescript@5.5.3: {} diff --git a/scripts/check.mjs b/scripts/check.mjs index ab0eac92..f3066a9e 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -7,6 +7,7 @@ import AdmZip from "adm-zip"; import fetch from "node-fetch"; import proxyAgent from "https-proxy-agent"; import { execSync } from "child_process"; +import { log_info, log_debug, log_error, log_success } from "./utils.mjs"; const cwd = process.cwd(); const TEMP_DIR = path.join(cwd, "node_modules/.verge"); @@ -92,9 +93,9 @@ async function getLatestAlphaVersion() { }); let v = await response.text(); META_ALPHA_VERSION = v.trim(); // Trim to remove extra whitespaces - console.log(`Latest alpha version: ${META_ALPHA_VERSION}`); + log_info(`Latest alpha version: ${META_ALPHA_VERSION}`); } catch (error) { - console.error("Error fetching latest alpha version:", error.message); + log_error("Error fetching latest alpha version:", error.message); process.exit(1); } } @@ -139,9 +140,9 @@ async function getLatestReleaseVersion() { }); let v = await response.text(); META_VERSION = v.trim(); // Trim to remove extra whitespaces - console.log(`Latest release version: ${META_VERSION}`); + log_info(`Latest release version: ${META_VERSION}`); } catch (error) { - console.error("Error fetching latest release version:", error.message); + log_error("Error fetching latest release version:", error.message); process.exit(1); } } @@ -222,11 +223,11 @@ async function resolveSidecar(binInfo) { if (zipFile.endsWith(".zip")) { const zip = new AdmZip(tempZip); zip.getEntries().forEach((entry) => { - console.log(`[DEBUG]: "${name}" entry name`, entry.entryName); + log_debug(`"${name}" entry name`, entry.entryName); }); zip.extractAllTo(tempDir, true); await fsp.rename(tempExe, sidecarPath); - console.log(`[INFO]: "${name}" unzip finished`); + log_success(`unzip finished: "${name}"`); } else if (zipFile.endsWith(".tgz")) { // tgz await fsp.mkdir(tempDir, { recursive: true }); @@ -236,14 +237,14 @@ async function resolveSidecar(binInfo) { //strip: 1, // 可能需要根据实际的 .tgz 文件结构调整 }); const files = await fsp.readdir(tempDir); - console.log(`[DEBUG]: "${name}" files in tempDir:`, files); + log_debug(`"${name}" files in tempDir:`, files); const extractedFile = files.find((file) => file.startsWith("虚空终端-")); if (extractedFile) { const extractedFilePath = path.join(tempDir, extractedFile); await fsp.rename(extractedFilePath, sidecarPath); - console.log(`[INFO]: "${name}" file renamed to "${sidecarPath}"`); + log_success(`"${name}" file renamed to "${sidecarPath}"`); execSync(`chmod 755 ${sidecarPath}`); - console.log(`[INFO]: "${name}" chmod binary finished`); + log_success(`chmod binary finished: "${name}"`); } else { throw new Error(`Expected file not found in ${tempDir}`); } @@ -253,16 +254,16 @@ async function resolveSidecar(binInfo) { const writeStream = fs.createWriteStream(sidecarPath); await new Promise((resolve, reject) => { const onError = (error) => { - console.error(`[ERROR]: "${name}" gz failed:`, error.message); + log_error(`"${name}" gz failed:`, error.message); reject(error); }; readStream .pipe(zlib.createGunzip().on("error", onError)) .pipe(writeStream) .on("finish", () => { - console.log(`[INFO]: "${name}" gunzip finished`); + log_success(`chmod binary finished: "${name}"`); execSync(`chmod 755 ${sidecarPath}`); - console.log(`[INFO]: "${name}" chmod binary finished`); + log_success(`chmod binary finished: "${name}"`); resolve(); }) .on("error", onError); @@ -292,7 +293,7 @@ async function resolveResource(binInfo) { await fsp.mkdir(resDir, { recursive: true }); await downloadFile(downloadURL, targetPath); - console.log(`[INFO]: ${file} finished`); + log_success(`${file} finished`); } /** @@ -319,7 +320,7 @@ async function downloadFile(url, path) { const buffer = await response.arrayBuffer(); await fsp.writeFile(path, new Uint8Array(buffer)); - console.log(`[INFO]: download finished "${url}"`); + log_success(`download finished: ${file}`); } // SimpleSC.dll @@ -344,11 +345,11 @@ const resolvePlugin = async () => { } const zip = new AdmZip(tempZip); zip.getEntries().forEach((entry) => { - console.log(`[DEBUG]: "SimpleSC" entry name`, entry.entryName); + log_debug(`"SimpleSC" entry name`, entry.entryName); }); zip.extractAllTo(tempDir, true); await fsp.cp(tempDll, pluginPath, { recursive: true, force: true }); - console.log(`[INFO]: "SimpleSC" unzip finished`); + log_success(`unzip finished: "SimpleSC"`); } finally { await fsp.rm(tempDir, { recursive: true, force: true }); } @@ -366,7 +367,7 @@ const resolveServicePermission = async () => { const targetPath = path.join(resDir, f); if (fs.existsSync(targetPath)) { execSync(`chmod 755 ${targetPath}`); - console.log(`[INFO]: "${targetPath}" chmod finished`); + log_success(`chmod finished: "${f}"`); } } }; @@ -481,7 +482,7 @@ async function runTask() { await task.func(); break; } catch (err) { - console.error(`[ERROR]: task::${task.name} try ${i} ==`, err.message); + log_error(`task::${task.name} try ${i} ==`, err.message); if (i === task.retry - 1) throw err; } } diff --git a/scripts/utils.mjs b/scripts/utils.mjs new file mode 100644 index 00000000..3db9a14e --- /dev/null +++ b/scripts/utils.mjs @@ -0,0 +1,11 @@ +import clc from "cli-color"; + +export const log_success = (msg, ...optionalParams) => + console.log(clc.green(msg), ...optionalParams); +export const log_error = (msg, ...optionalParams) => + console.log(clc.red(msg), ...optionalParams); +export const log_info = (msg, ...optionalParams) => + console.log(clc.bgBlue(msg), ...optionalParams); +var debugMsg = clc.xterm(245); +export const log_debug = (msg, ...optionalParams) => + console.log(debugMsg(msg), ...optionalParams);