Patched DB creation and added CLI toolchain base
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { Database } from "@db/sqlite";
|
import { Database } from "@db/sqlite";
|
||||||
|
|
||||||
export default async function ensureDatabases() {
|
export default async function ensureDatabases() {
|
||||||
|
await Deno.mkdir("databases/data", { recursive: true });
|
||||||
|
|
||||||
for await (const file of Deno.readDir("databases/init")) {
|
for await (const file of Deno.readDir("databases/init")) {
|
||||||
if (!file.isFile) {
|
if (!file.isFile) {
|
||||||
console.warn(`[WARN] Path ${file.name} is not a file.`);
|
console.warn(`[WARN] Path ${file.name} is not a file.`);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
"@db/sqlite": "jsr:@db/sqlite@^0.12.0",
|
"@db/sqlite": "jsr:@db/sqlite@^0.12.0",
|
||||||
"@melvdouc/xml-parser": "jsr:@melvdouc/xml-parser@^0.1.1",
|
"@melvdouc/xml-parser": "jsr:@melvdouc/xml-parser@^0.1.1",
|
||||||
"@popov/jwt": "jsr:@popov/jwt@^1.0.1",
|
"@popov/jwt": "jsr:@popov/jwt@^1.0.1",
|
||||||
|
"@std/cli": "jsr:@std/cli@^1.0.10",
|
||||||
"preact": "https://esm.sh/preact@10.22.0",
|
"preact": "https://esm.sh/preact@10.22.0",
|
||||||
"preact/": "https://esm.sh/preact@10.22.0/",
|
"preact/": "https://esm.sh/preact@10.22.0/",
|
||||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
|
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { parseArgs, type ParseOptions } from "@std/cli/parse-args";
|
||||||
|
import { createModule } from "$root/toolbox/module.ts";
|
||||||
|
|
||||||
|
interface CLI {
|
||||||
|
[command: string]: CLI | (() => void) | (() => Promise<void>);
|
||||||
|
}
|
||||||
|
|
||||||
|
const argSpec: ParseOptions = {};
|
||||||
|
|
||||||
|
const cli: CLI = {
|
||||||
|
help: () => displayHelp(cli),
|
||||||
|
module: {
|
||||||
|
create: createModule,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function displayHelp(cli: CLI, errorMessage?: string): never {
|
||||||
|
const loggingFunction = errorMessage ? console.error : console.log;
|
||||||
|
if (errorMessage) {
|
||||||
|
console.error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
loggingFunction("Commands:");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function runCommand(commands: Array<string | number>, cli: CLI): never | void | Promise<void> {
|
||||||
|
if (commands.length == 0) {
|
||||||
|
console.error(
|
||||||
|
`No command provided. Available commands are ${
|
||||||
|
JSON.stringify(Object.keys(cli))
|
||||||
|
}.`,
|
||||||
|
);
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const command = commands.shift()!.toString();
|
||||||
|
|
||||||
|
if (cli[command] == undefined) {
|
||||||
|
console.error(
|
||||||
|
`Command "${command}" doesn't exist. Available commands are ${
|
||||||
|
JSON.stringify(Object.keys(cli))
|
||||||
|
}.`,
|
||||||
|
);
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof cli[command] == "object") {
|
||||||
|
return runCommand(commands, cli[command]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cli[command]();
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
const args = parseArgs(Deno.args, argSpec);
|
||||||
|
runCommand(args._, cli);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export async function createModule() {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user