Add metadata entry for init-tsscript.ts in script-meta-v2.json and introduce new untracked script file init-tsscript.ts

This commit is contained in:
2026-04-12 23:36:27 +08:00
parent e9fb460715
commit 96ed7af5fe
2 changed files with 91 additions and 0 deletions

View File

@@ -169,6 +169,15 @@
"publish_time": 1775929369681, "publish_time": 1775929369681,
"update_time": 1776006975912 "update_time": 1776006975912
}, },
"init-tsscript.ts": {
"script_name": "init-tsscript.ts",
"script_length": 1992,
"script_sha256": "96d48a09b9cea9944fabea51aacdac1c8abbff9c29e7d343bfcc279abb1a8480",
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/init-tsscript.ts",
"single_script_file": true,
"publish_time": 1776008182540,
"update_time": 1776008182540
},
"ip.ts": { "ip.ts": {
"script_name": "ip.ts", "script_name": "ip.ts",
"script_length": 653, "script_length": 653,

82
single-scripts/init-tsscript.ts Executable file
View File

@@ -0,0 +1,82 @@
#!/usr/bin/env runts -- --allow-all
import {parseArgs} from "jsr:@std/cli/parse-args";
import {existsPath, exit, log, writeStringToFile,} from "https://script.hatter.ink/@70/deno-commons-mod.ts";
async function main(): Promise<void> {
const flags = parseArgs(Deno.args, {
boolean: ["help"],
});
if (flags.help) {
console.log(`init-tsscript.ts - Init TypeScript script file
init-tsscript.ts [SCRIPT_NAME]
`);
exit(0);
}
const name = (flags._ && flags._.length > 0)
? flags._[0]
: prompt("Script name:");
if (!name) {
log.error("Script name is required");
return;
}
let scriptFile = name;
if (!name.endsWith(".ts")) {
scriptFile = `${name}.ts`;
}
const scriptName = scriptFile;
if (await existsPath("single-scripts/")) {
scriptFile = "single-scripts/" + scriptFile;
}
if (await existsPath(scriptFile)) {
log.error(`Script ${scriptFile} already exists`);
exit(1);
}
const script = `#!/usr/bin/env runts -- --allow-all
import {parseArgs} from "jsr:@std/cli/parse-args";
import {exit, log, } from "../libraries/deno-commons-mod.ts";
function parseFlags(): any {
const flags = parseArgs(Deno.args, {
boolean: ["help"]
});
const helpMessage = \`${scriptName} - DESCRIPTION
HELP MESSAGE DETAILS
\`;
if (flags.help) {
console.log(helpMessage);
exit(0);
}
}
async function main(): Promise<void> {
const flags = parseFlags();
// TODO code here
return;
}
main().catch((err) => {
log.error(err);
exit(1);
}).then(() => exit(0));
`;
await writeStringToFile(scriptFile, script);
log.success(`Init ${scriptFile} successfully.`);
}
main().catch((err) => {
log.error(err);
exit(1);
}).then(() => exit(0));
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T233613+08:00.MEUCIQD3Rqq2Owkh/5me60Zf
// VS+LqBwz6gOkpHPIWyHJsbBkMAIgd68qrBPr9Dro9p9WUv5GvZ2+7LZTdA/Ub2cTh5MhRxc=