diff --git a/script-meta-v2.json b/script-meta-v2.json index 72f457f..d84b2be 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -169,6 +169,15 @@ "publish_time": 1775929369681, "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": { "script_name": "ip.ts", "script_length": 653, diff --git a/single-scripts/init-tsscript.ts b/single-scripts/init-tsscript.ts new file mode 100755 index 0000000..9604ea5 --- /dev/null +++ b/single-scripts/init-tsscript.ts @@ -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 { + 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 { + 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=