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
+82
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=