v1 ready for publish

This commit is contained in:
2025-05-06 17:53:17 -06:00
parent 03a1e3ed21
commit 6346b28581
11 changed files with 53 additions and 28 deletions

View File

@@ -5,6 +5,16 @@ import { colorize } from "./style.ts";
import { selectMenuInteractive } from "./selectMenu.ts";
import { TerminalBlock, TerminalLayout } from "./TerminalLayout.ts";
import { cliAlert, cliLog } from "./prompts.ts";
import type { ITool } from "../types.ts";
import { join, toFileUrl } from "@std/path";
import { log } from "util/logfile.ts";
// Register tools here (filename, no extension)
const toolRegistry: [string, Promise<{ default: ITool }>][] = [
["checkCode", import("../tools/checkCode.ts")],
["fieldRename", import("../tools/fieldRename.ts")],
["listFormFields", import("../tools/listFormFields.ts")],
];
export class PdfToolsCli {
private tools: Map<string, ITool> = new Map();
@@ -15,19 +25,18 @@ export class PdfToolsCli {
help: ["-h", "--help"],
});
async importTools(tools?: string) {
tools = tools?.replace(/\/$/, "").replace(/^\.?\//, "") || "tools";
for (const toolfile of Deno.readDirSync(tools)) {
if (toolfile.isFile) {
const tool = await import(
Deno.cwd() + "/" + tools + "/" + toolfile.name
);
if (tool.default) {
async importTools() {
for (const [name, toolfile] of toolRegistry) {
const t = await toolfile;
try {
if (t.default) {
this.tools.set(
toCase(toolfile.name.replace(".ts", ""), "title"),
tool.default,
toCase(name, "title"),
t.default,
);
}
} catch (e) {
cliLog(e + "\n", this.terminalLayout.getBlock("body"));
}
}
}
@@ -50,6 +59,7 @@ export class PdfToolsCli {
public async run() {
try {
await this.importTools();
const titleBlock = new TerminalBlock();
this.terminalLayout.register("title", titleBlock);
const bodyBlock = new TerminalBlock();
@@ -59,10 +69,8 @@ export class PdfToolsCli {
return;
} else if (this.args.nonFlags.length === 0 || !this.args.task) {
this.embiggenHeader();
await this.importTools();
await this.toolMenu();
} else {
await this.importTools();
const task = this.args.task;
await this.runTool(toCase(task, "title"));
}

View File

@@ -1,3 +1,4 @@
import type { callback } from "../types.ts";
import { colorize } from "./style.ts";
import { TerminalBlock } from "./TerminalLayout.ts";