fix: local ASCII Art inclusion

This commit is contained in:
Emmaline Autumn 2025-05-20 13:45:27 -06:00
parent 90f1547e02
commit cdeef54f68
3 changed files with 30 additions and 30 deletions

View File

@ -30,7 +30,7 @@ jobs:
uses: https://git.cyborggrizzly.com/bearmetal/ci-actions/deno-release@main uses: https://git.cyborggrizzly.com/bearmetal/ci-actions/deno-release@main
with: with:
entrypoint: main.ts 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: env:
GITEA_TOKEN: ${{ secrets.GIT_PAT }} GITEA_TOKEN: ${{ secrets.GIT_PAT }}

View File

@ -1,10 +1,10 @@
{ {
"name": "@bearmetal/pdf-tools", "name": "@bearmetal/pdf-tools",
"version": "1.0.1", "version": "1.0.2",
"license": "GPL 3.0", "license": "GPL 3.0",
"tasks": { "tasks": {
"dev": "deno run -A --env-file=.env main.ts", "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", "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" "debug": "deno run -A --env-file=.env --inspect-wait --watch main.ts"
}, },
@ -12,7 +12,8 @@
"@std/assert": "jsr:@std/assert@1", "@std/assert": "jsr:@std/assert@1",
"@std/path": "jsr:@std/path@^1.0.9", "@std/path": "jsr:@std/path@^1.0.9",
"pdf-lib": "npm:pdf-lib@^1.17.1", "pdf-lib": "npm:pdf-lib@^1.17.1",
"util/": "./util/" "util/": "./util/",
"@/": "./"
}, },
"exports": { "exports": {
".": "./main.ts" ".": "./main.ts"

View File

@ -1,30 +1,29 @@
export async function getAsciiArt(art: string) { import { log } from "./logfile.ts";
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") || import { join } from "@std/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);
while (result !== null) { export async function getAsciiArt(art: string) {
const [_, name, artText] = result; try {
if (name === art) return artText; const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
result = parserRX.exec(artFileText); 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; 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";
}