99 lines
2.2 KiB
TypeScript
Executable File
99 lines
2.2 KiB
TypeScript
Executable File
#!/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";
|
|
|
|
function parseFlags(): any {
|
|
const flags = parseArgs(Deno.args, {
|
|
boolean: ["help"],
|
|
alias: {
|
|
h: "help",
|
|
},
|
|
});
|
|
if (flags.help) {
|
|
console.log(`init-tsscript.ts - Init TypeScript script file
|
|
|
|
init-tsscript.ts [SCRIPT_NAME]
|
|
`);
|
|
exit(0);
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
const flags = parseFlags();
|
|
const name = (flags._ && flags._.length > 0)
|
|
? flags._[0]
|
|
: prompt("Script name:");
|
|
if (!name) {
|
|
log.error("Script name is required");
|
|
exit(1);
|
|
}
|
|
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"],
|
|
alias: {
|
|
h: "help",
|
|
},
|
|
});
|
|
const helpMessage = \`${scriptName} - DESCRIPTION
|
|
|
|
----- TODO HELP MESSAGE DETAILS -----
|
|
\`;
|
|
if (flags.help) {
|
|
console.log(helpMessage);
|
|
exit(0);
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
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.20260416T010940+08:00.MEYCIQC1kDn6UCQqBl2YXsi1
|
|
// SLZamJIx/SGZgyMQIRWzehDFxgIhALE3TYPe5C6iDPw/RRs0tS+7HXXL/uT/6lNBuG8jsNwO
|