diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 776a15c..dd090c0 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -30,7 +30,7 @@ jobs: uses: https://git.cyborggrizzly.com/bearmetal/ci-actions/deno-release@main with: entrypoint: main.ts - compile-flags: "--allow-read --allow-write --allow-env --allow-net" + compile-flags: "--allow-read --allow-write --allow-env --allow-net --include asciiart.txt" env: GITEA_TOKEN: ${{ secrets.GIT_PAT }} diff --git a/deno.json b/deno.json index c371ac4..b1961f9 100644 --- a/deno.json +++ b/deno.json @@ -1,10 +1,10 @@ { "name": "@bearmetal/pdf-tools", - "version": "1.0.1", + "version": "1.0.2", "license": "GPL 3.0", "tasks": { "dev": "deno run -A --env-file=.env main.ts", - "compile": "deno compile -o compare-form-fields.exe --target x86_64-pc-windows-msvc -R ./main.ts", + "compile": "deno compile -o pdf-tools.exe --target x86_64-pc-windows-msvc --include ./asciiart.txt -A ./main.ts", "install": "deno install -fgq --import-map ./deno.json -n checkfields -R ./main.ts", "debug": "deno run -A --env-file=.env --inspect-wait --watch main.ts" }, @@ -12,7 +12,8 @@ "@std/assert": "jsr:@std/assert@1", "@std/path": "jsr:@std/path@^1.0.9", "pdf-lib": "npm:pdf-lib@^1.17.1", - "util/": "./util/" + "util/": "./util/", + "@/": "./" }, "exports": { ".": "./main.ts" diff --git a/util/asciiArt.ts b/util/asciiArt.ts index 2c0a590..aaaacc6 100644 --- a/util/asciiArt.ts +++ b/util/asciiArt.ts @@ -1,30 +1,29 @@ -export async function getAsciiArt(art: string) { - const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") || - getBearmetalAsciiPath(); - if (!artFilePath) return art; - let artFileText: string; - if (artFilePath.startsWith("http")) { - artFileText = await fetch(artFilePath).then((res) => res.text()); - } else { - artFileText = await Deno.readTextFile(artFilePath); - } - const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g; - let result = parserRX.exec(artFileText); +import { log } from "./logfile.ts"; +import { join } from "@std/path"; - while (result !== null) { - const [_, name, artText] = result; - if (name === art) return artText; - result = parserRX.exec(artFileText); +export async function getAsciiArt(art: string) { + try { + const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") || + join(import.meta.dirname || "", "../asciiart.txt"); + let artFileText: string; + if (artFilePath?.startsWith("http")) { + artFileText = await fetch(artFilePath).then((res) => res.text()); + } else { + artFileText = await Deno.readTextFile( + artFilePath, + ); + } + const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g; + let result = parserRX.exec(artFileText); + + while (result !== null) { + const [_, name, artText] = result; + if (name === art) return artText; + result = parserRX.exec(artFileText); + } + } catch (e) { + console.log(e); + alert(); } return art; } - -function getBearmetalAsciiPath() { - const filenameRX = /asciiarts?\.txt$/; - for (const filename of Deno.readDirSync(".")) { - if (filename.isFile && filenameRX.test(filename.name)) { - return filename.name; - } - } - return "https://git.cyborggrizzly.com/BearMetal/pdf-tools/raw/branch/main/asciiart.txt"; -}