From 6a08be3f50a998c4c4f15ba93298e6d023b7c23c Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Wed, 11 Feb 2026 23:02:11 +0800 Subject: [PATCH] updates --- libraries/deno-commons-mod.ts | 45 +++++++++++++++++++++---- script-meta-v2.json | 46 +++++++++++++------------- single-scripts/decode-uri-component.ts | 9 +++-- single-scripts/decode-uri.ts | 9 +++-- single-scripts/encode-uri-component.ts | 9 +++-- single-scripts/encode-uri.ts | 9 +++-- single-scripts/git-check.ts | 19 +++++------ single-scripts/hjson.ts | 10 +++--- single-scripts/json5.ts | 10 +++--- single-scripts/post-note.ts | 24 +++++++------- 10 files changed, 108 insertions(+), 82 deletions(-) diff --git a/libraries/deno-commons-mod.ts b/libraries/deno-commons-mod.ts index 7d3fafb..1d8b5ba 100644 --- a/libraries/deno-commons-mod.ts +++ b/libraries/deno-commons-mod.ts @@ -2,7 +2,8 @@ // - https://docs.deno.com/runtime/fundamentals/testing/ import {decodeBase64, encodeBase64} from "jsr:@std/encoding/base64"; -import {dirname, fromFileUrl} from "https://deno.land/std/path/mod.ts"; +import {dirname, fromFileUrl} from "jsr:@std/path"; +import {toArrayBuffer} from "jsr:@std/streams"; import {spawn, SpawnOptionsWithoutStdio} from "node:child_process"; import {mkdir, readFile, readFileSync, rm, writeFile} from "node:fs"; @@ -22,6 +23,36 @@ export function osEnv(key: string): string | undefined { return isDeno() ? Deno.env.get(key) : process.env[key]; } +export function stdin(): ReadableStream { + return isDeno() ? Deno.stdin.readable : process.stdin; +} + +function streamToArrayBuffer(stream) { + const chunks = []; + return new Promise((resolve, reject) => { + stream.on("error", (err) => reject(err)); + stream.on("data", (chunk) => { + chunks.push(chunk); + }); + stream.on("end", () => { + const buffer = Buffer.concat(chunks); + resolve( + buffer.buffer.slice( + buffer.byteOffset, + buffer.byteOffset + buffer.byteLength, + ), + ); + }); + }); +} + +export function stdinToArrayBuffer(): Promise { + if (isDeno()) { + return toArrayBuffer(Deno.stdin.readable); + } + return streamToArrayBuffer(process.stdin); +} + export function exit(code?: number): never { isDeno() ? Deno.exit(code) : process.exit(code); } @@ -222,7 +253,7 @@ export function parseIntVal(val: any, defaultVal: number): number { } export function getEnv(envKey: string): string | null { - const homeDir = homeDir(); + const homeDir = getHomeDir(); if ((homeDir !== null) && envKey) { const envValue = readFileToStringSync( `${homeDir}/.config/envs/${envKey}`, @@ -705,18 +736,18 @@ export function getHomeDirOrDie(): string { } export function homeDirOrDie(): string { - const homeDir = homeDir(); + const homeDir = getHomeDir(); if (homeDir === null) { throw new Error("Cannot find home dir"); } return homeDir; } -export function getHomeDir(): string | null { - return homeDir(); +export function homeDir(): string | null { + return getHomeDir(); } -export function homeDir(): string | null { +export function getHomeDir(): string | null { // if (Deno.build.os === "windows") { // const userProfile = osEnv("USERPROFILE"); // if (userProfile) { @@ -734,7 +765,7 @@ export function homeDir(): string | null { export function resolveFilename(filename: string): string { if (filename.startsWith("~/")) { - return homeDir() + filename.substring(1); + return getHomeDir() + filename.substring(1); } return filename; } diff --git a/script-meta-v2.json b/script-meta-v2.json index ebdb335..f44706d 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -71,57 +71,57 @@ }, "decode-uri-component.ts": { "script_name": "decode-uri-component.ts", - "script_length": 895, - "script_sha256": "22af6c21359b50e8907ad2f25f5c1e42a0889c2415347cee5f693728f36931bf", + "script_length": 826, + "script_sha256": "c3a3adfa47d1d02552e470a54465d0879fc7c27a385eaeb05de0e390e8fac1a0", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/decode-uri-component.ts", "single_script_file": true, "publish_time": 1769010420928, - "update_time": 1770820648012 + "update_time": 1770822121773 }, "decode-uri.ts": { "script_name": "decode-uri.ts", - "script_length": 866, - "script_sha256": "0e529a1df2a6290f48cef047c9670b36434a81784c86e33e93467d1c406fb9c2", + "script_length": 797, + "script_sha256": "0a1734bfd5915ddb57078700b331f7a8caef10e67155bca0c440268b45e4049a", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/decode-uri.ts", "single_script_file": true, "publish_time": 1769010420927, - "update_time": 1770820648008 + "update_time": 1770822121766 }, "encode-uri-component.ts": { "script_name": "encode-uri-component.ts", - "script_length": 895, - "script_sha256": "f93d315d2b26474b1640c5f4ea4ddcb168dae85b9d1da4ed630cf76c0951dd2f", + "script_length": 826, + "script_sha256": "ad09cba79b7d73ba1d33392c11df30223468356e189b1f2ccaf50a13fc0e57a6", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/encode-uri-component.ts", "single_script_file": true, "publish_time": 1769010420927, - "update_time": 1770820648008 + "update_time": 1770822121766 }, "encode-uri.ts": { "script_name": "encode-uri.ts", - "script_length": 866, - "script_sha256": "99051fb4754203c685de490cdbc0addd0203b0866cd902f760d6cc3d8a1305c2", + "script_length": 797, + "script_sha256": "9982989109d8b2963ea60204ec9d4a42b99b91fc0b8f2edc04a59f7e536528e4", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/encode-uri.ts", "single_script_file": true, "publish_time": 1769010420927, - "update_time": 1770820648008 + "update_time": 1770822121767 }, "git-check.ts": { "script_name": "git-check.ts", "script_length": 3107, - "script_sha256": "59eed22fad7b3a4f4ddb6c9c5ba6781771fbff6e0f7d30e869039ddc93f27d94", + "script_sha256": "a407febeb4f00935f0de9bb02953b688016b2e1819627b88ab07ca08f2a68338", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/git-check.ts", "single_script_file": true, "publish_time": 1770541896791, - "update_time": 1770566275385 + "update_time": 1770822121766 }, "hjson.ts": { "script_name": "hjson.ts", - "script_length": 449, - "script_sha256": "0ff4ae6601124b92936d76d32d27c882edfbb3af1613362e3c3d13cbde5cbed8", + "script_length": 458, + "script_sha256": "8ef093d380b802ddc88253d382a907042e0cdb84fdfb2a2602b5237dc843f494", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/hjson.ts", "single_script_file": true, "publish_time": 1737375737613, - "update_time": 1737650670433 + "update_time": 1770822121766 }, "ip.ts": { "script_name": "ip.ts", @@ -134,12 +134,12 @@ }, "json5.ts": { "script_name": "json5.ts", - "script_length": 449, - "script_sha256": "b81ddc5b9f6f33df3521bda5f85e6378751356f104817d64b18272f839befbbf", + "script_length": 459, + "script_sha256": "42ec900affe351697490ae677bdd392ecccc2f27e453c3820e9e0a99a08bb135", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/json5.ts", "single_script_file": true, "publish_time": 1767969331870, - "update_time": 1767969331870 + "update_time": 1770822121767 }, "jsr-std-http-file-server-bundle.ts": { "script_name": "jsr-std-http-file-server-bundle.ts", @@ -170,12 +170,12 @@ }, "post-note.ts": { "script_name": "post-note.ts", - "script_length": 2030, - "script_sha256": "9fc2c3223882a9040d3becc7d1c5dfc5c89dfb313fa05c8605e041629d887881", + "script_length": 2049, + "script_sha256": "37f1b50234e7f7d143c65f9d0d37d99ef148a33d87be364a43b8c136d95abc3f", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/post-note.ts", "single_script_file": true, "publish_time": 1737475603673, - "update_time": 1769525844426 + "update_time": 1770822121771 }, "print-env.ts": { "script_name": "print-env.ts", diff --git a/single-scripts/decode-uri-component.ts b/single-scripts/decode-uri-component.ts index 49cc111..880138a 100755 --- a/single-scripts/decode-uri-component.ts +++ b/single-scripts/decode-uri-component.ts @@ -1,8 +1,7 @@ #!/usr/bin/env runts -- --allow-import -import {args, exit} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; +import {args, exit, stdinToArrayBuffer,} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; import {parseArgs} from "jsr:@std/cli/parse-args"; -import {toArrayBuffer} from "https://deno.land/std@0.203.0/streams/mod.ts"; const flags = parseArgs(args(), { boolean: ["help"], @@ -22,11 +21,11 @@ let input; if (flags.value) { input = flags.value; } else { - input = new TextDecoder().decode(await toArrayBuffer(Deno.stdin.readable)); + input = new TextDecoder().decode(await stdinToArrayBuffer()); } const encoded = decodeURIComponent(input); console.log(encoded); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T223654+08:00.MEQCIFtTTbxi8OppwMqWir2q -// 0UbxQBHhtTORJyhDnU1vUfOTAiA31LMua+CE7wqry2JYMVikX0iE7e4c/gbuLIFj/KszEw== +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T225504+08:00.MEYCIQDKLbuD0sgzk3bG7F20 +// VvDZHp3Eb2Jtf5u7V6vZ3+TtRQIhAIAOTgX9h7pLbT3fTNmkY5tyAQToY2zDaJ+qzRW7OTmh diff --git a/single-scripts/decode-uri.ts b/single-scripts/decode-uri.ts index b7e0b3e..c58a463 100755 --- a/single-scripts/decode-uri.ts +++ b/single-scripts/decode-uri.ts @@ -1,8 +1,7 @@ #!/usr/bin/env runts -- --allow-import -import {args, exit} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; +import {args, exit, stdinToArrayBuffer,} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; import {parseArgs} from "jsr:@std/cli/parse-args"; -import {toArrayBuffer} from "https://deno.land/std@0.203.0/streams/mod.ts"; const flags = parseArgs(args(), { boolean: ["help"], @@ -22,11 +21,11 @@ let input; if (flags.value) { input = flags.value; } else { - input = new TextDecoder().decode(await toArrayBuffer(Deno.stdin.readable)); + input = new TextDecoder().decode(await stdinToArrayBuffer()); } const encoded = decodeURI(input); console.log(encoded); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T223656+08:00.MEUCIQD2Z+EYNFmlGJF1mRwZ -// WtcimdYPCpkEiGWJ2nCoEFZhSAIgIcokRXUdswb+o/tjq098FbaBSRu2xk8t1qgKvBFp3hw= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T225506+08:00.MEUCIDfr8u5mUsFF99o/bljU +// QRarosqW3mkPVLil3xKqm9xbAiEAlE6HABKWVyN/vEIzW4H18Yz3nsoD9O+WlrvhoOzoDGk= diff --git a/single-scripts/encode-uri-component.ts b/single-scripts/encode-uri-component.ts index 14f3264..83431e9 100755 --- a/single-scripts/encode-uri-component.ts +++ b/single-scripts/encode-uri-component.ts @@ -1,8 +1,7 @@ #!/usr/bin/env runts -- --allow-import -import {args, exit} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; +import {args, exit, stdinToArrayBuffer,} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; import {parseArgs} from "jsr:@std/cli/parse-args"; -import {toArrayBuffer} from "https://deno.land/std@0.203.0/streams/mod.ts"; const flags = parseArgs(args(), { boolean: ["help"], @@ -22,11 +21,11 @@ let input; if (flags.value) { input = flags.value; } else { - input = new TextDecoder().decode(await toArrayBuffer(Deno.stdin.readable)); + input = new TextDecoder().decode(await stdinToArrayBuffer()); } const encoded = encodeURIComponent(input); console.log(encoded); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T223656+08:00.MEYCIQDWpN6TPlSUC2reXixQ -// cAsopGtVR7O1eHOZ8yMXhXJamAIhAKHLwiUf97ArNi0fYjQ8pfEkRXA6kfxM41Uj3rgYj1X/ +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T225507+08:00.MEYCIQDxWgMNdf4UdQgAbtSs +// FHQ5RxsfUUsmwqPoDLDj2KYacwIhAKv/68f8WC3TFJ7v0Fli7djrRNt80lB+qkdHg6ROXaK6 diff --git a/single-scripts/encode-uri.ts b/single-scripts/encode-uri.ts index b1c7ad0..7f7f5e9 100755 --- a/single-scripts/encode-uri.ts +++ b/single-scripts/encode-uri.ts @@ -1,8 +1,7 @@ #!/usr/bin/env runts -- --allow-import -import {args, exit} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; +import {args, exit, stdinToArrayBuffer,} from "https://script.hatter.ink/@43/deno-commons-mod.ts"; import {parseArgs} from "jsr:@std/cli/parse-args"; -import {toArrayBuffer} from "https://deno.land/std@0.203.0/streams/mod.ts"; const flags = parseArgs(args(), { boolean: ["help"], @@ -22,11 +21,11 @@ let input; if (flags.value) { input = flags.value; } else { - input = new TextDecoder().decode(await toArrayBuffer(Deno.stdin.readable)); + input = new TextDecoder().decode(await stdinToArrayBuffer()); } const encoded = encodeURI(input); console.log(encoded); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T223656+08:00.MEUCIHhfsF0mbPmh5MylnqPg -// MEXtiFQ3ncpqJcQruOqdUViLAiEA77/M0NfgxlerlG0zjY/r0Etz7fQ0TyqX8B1Qe1iev8Q= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T225148+08:00.MEUCIAwanQfv/7ixuUTMPJKh +// eU5BnGTKB5PeqmPHPkq5BpoJAiEAjASLCxu/w1Dm/6lz8yPlc71mChWo1M1MxiyiM3MQ6Cs= diff --git a/single-scripts/git-check.ts b/single-scripts/git-check.ts index 88c2e8d..61a2cb0 100755 --- a/single-scripts/git-check.ts +++ b/single-scripts/git-check.ts @@ -1,7 +1,9 @@ #!/usr/bin/env runts -- --allow-all import { + args, execCommandAndStdout, + exit, formatHumanTime, log, ProcessBar, @@ -10,12 +12,9 @@ import { term, uint8ArrayToHexString, writeStringToFile, -} from "https://script.hatter.ink/@35/deno-commons-mod.ts"; -import { - getGitLocalRev, - getGitRemoteRev, -} from "https://script.hatter.ink/@0/deno-git-mod.ts"; -import { parseArgs } from "jsr:@std/cli/parse-args"; +} from "https://script.hatter.ink/@41/deno-commons-mod.ts"; +import {getGitLocalRev, getGitRemoteRev,} from "https://script.hatter.ink/@0/deno-git-mod.ts"; +import {parseArgs} from "jsr:@std/cli/parse-args"; const MILLIS_OF_HOUR = 60 * 60 * 1000; @@ -35,7 +34,7 @@ interface GitCheckCache { } async function main() { - const flags = parseArgs(Deno.args, { + const flags = parseArgs(args(), { boolean: [ "help", ], @@ -95,11 +94,11 @@ git-check.ts [--interval NUMBER-OF-HOURS]`); log.error( `Check rev failed, local rev: ${localRev} vs remote rev: ${remoteRev}`, ); - Deno.exit(1); + exit(1); } } await main(); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260208T235727+08:00.MEUCIQDm/E1d7mGqJ4nbguao -// +eFwlDMp/x7ZOWn95z2BSnIrfwIgJg0lHcBV8C2fQ5B/4Suvq7f9/f+M2CHrNn9CSzve4wA= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T223841+08:00.MEYCIQDP6ccWgcPmrIdAWqjl +// pS3koxJgYGPETuczjTbo+/PE/QIhAIHpiz8WCp+8hQ/oBOotIG/7Jfc9ky+R1tPi2fKdJ3Wb diff --git a/single-scripts/hjson.ts b/single-scripts/hjson.ts index 6834084..d1dedfb 100755 --- a/single-scripts/hjson.ts +++ b/single-scripts/hjson.ts @@ -1,11 +1,11 @@ -#!/usr/bin/env runts -- --allow-env +#!/usr/bin/env runts -- --allow-env --allow-import +import {stdinToArrayBuffer} from "https://script.hatter.ink/@43/deno-commons-mod.ts"; import hjson from "npm:hjson"; -import { toArrayBuffer } from "https://deno.land/std@0.203.0/streams/mod.ts"; -const input = new TextDecoder().decode(await toArrayBuffer(Deno.stdin.readable)); +const input = new TextDecoder().decode(await stdinToArrayBuffer()); console.log(JSON.stringify(hjson.parse(input), null, 4)); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250124T004244+08:00.MEUCIQCmHkkAiwvLHOZpwb+M -// WLEa/guITGU2HD6ZD51SP/vwlgIgAIa/Pudrns1WkKMqn5VsR4/a6vDj1J52CUR/aN+bK8A= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T225507+08:00.MEUCIGr7QsOMEjjLKp5AOPux +// CtgKZemBdYsqPo8M7ieCmNriAiEA16LCcRqFGrgk7teLSkqICN7XuqJxvy0xCKb1Jz6sZxs= diff --git a/single-scripts/json5.ts b/single-scripts/json5.ts index 3c636e9..3d1c996 100755 --- a/single-scripts/json5.ts +++ b/single-scripts/json5.ts @@ -1,11 +1,11 @@ -#!/usr/bin/env runts -- --allow-env +#!/usr/bin/env runts -- --allow-env --allow-import +import {stdinToArrayBuffer,} from "https://script.hatter.ink/@43/deno-commons-mod.ts"; import josn5 from "npm:json5"; -import { toArrayBuffer } from "https://deno.land/std@0.203.0/streams/mod.ts"; -const input = new TextDecoder().decode(await toArrayBuffer(Deno.stdin.readable)); +const input = new TextDecoder().decode(await stdinToArrayBuffer()); console.log(JSON.stringify(josn5.parse(input), null, 4)); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260109T223356+08:00.MEQCIFVTrvVoTLkQgqdF+reR -// O3fqk6XmeW4hNo/bmUqCpeYFAiBpyK4W7trjpLpV07N2Xb9T+11ok+mn+9qcPV61e3IoHw== +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T225421+08:00.MEQCIByockYjDjHyRGSS4tBa +// tY2PjygZtm3vOmED9mNTJWxWAiApie4KjLckbi0LPqYXqyrBrELxAITeNS1ieW2T9IuDOQ== diff --git a/single-scripts/post-note.ts b/single-scripts/post-note.ts index 40b192c..e45ccb7 100755 --- a/single-scripts/post-note.ts +++ b/single-scripts/post-note.ts @@ -2,7 +2,7 @@ import {parseArgs} from "jsr:@std/cli/parse-args"; import {encryptEcdhP256} from "https://global.hatter.ink/script/get/@0/deno-wrapkey-mod.ts"; -import {getEnv, log,} from "https://global.hatter.ink/script/get/@18/deno-commons-mod.ts"; +import {args, exit, getEnv, log,} from "https://global.hatter.ink/script/get/@44/deno-commons-mod.ts"; import {fetchWithTimeoutAndAutoProxy} from "https://global.hatter.ink/script/get/@1/deno-fetch-auto-proxy-mod.ts"; const endpoint = getEnv("POST_ENCRYPTED_NOTE_ENDPOINT"); @@ -16,49 +16,49 @@ if (!endpoint || !publicKeyPointHex) { if (!publicKeyPointHex) { log.info("ENCRYPTION_PUBLIC_KEY_POINT_HEX must be assigned."); } - Deno.exit(1); + exit(1); } -const flags = parseArgs(Deno.args, { +const flags = parseArgs(args(), { boolean: ["help", "post-message"], string: ["title"], }); if (flags.help) { console.log("post-note.ts [--post-message] [--title ] <message>"); - Deno.exit(0); + exit(0); } if (flags._.length === 0) { log.error("Requires message."); - Deno.exit(1); + exit(1); } -const args = []; +const fetchArgs = []; if (flags.title) { const encryptedTitle = await encryptEcdhP256( "k", publicKeyPointHex, new TextEncoder().encode(flags.title), ); - args.push(`title=${encodeURIComponent(encryptedTitle.toString())}`); + fetchArgs.push(`title=${encodeURIComponent(encryptedTitle.toString())}`); } const encryptedMessage = await encryptEcdhP256( "k", publicKeyPointHex, new TextEncoder().encode(flags._.join("\n")), ); -args.push(`memo=${encodeURIComponent(encryptedMessage.toString())}`); +fetchArgs.push(`memo=${encodeURIComponent(encryptedMessage.toString())}`); if (flags["post-message"]) { - args.push("postMessage=true"); + fetchArgs.push("postMessage=true"); } const response = await fetchWithTimeoutAndAutoProxy( - `${endpoint}?${args.join("&")}`, + `${endpoint}?${fetchArgs.join("&")}`, ); console.info(response.status, await response.json()); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260127T225716+08:00.MEUCIEnxw6Q8UfPFWxfs+0Hq -// dzR+nwQoChs/xwSyAm4wpd9DAiEAnOZ70FXyf0e0QQpHiYHFLYdMdMZZWhCKjv2ShguSoPg= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T230055+08:00.MEYCIQDTM5393nrl6WXzDopn +// 9FeMIl2z7QUoQVOHP4BHZVH4OgIhANMUWUtFZDuOVH0J9e1PyS0j690Z+8AlTry7r/UHYoIu