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
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 }}

View File

@ -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"

View File

@ -1,12 +1,17 @@
import { log } from "./logfile.ts";
import { join } from "@std/path";
export async function getAsciiArt(art: string) {
try {
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
getBearmetalAsciiPath();
if (!artFilePath) return art;
join(import.meta.dirname || "", "../asciiart.txt");
let artFileText: string;
if (artFilePath.startsWith("http")) {
if (artFilePath?.startsWith("http")) {
artFileText = await fetch(artFilePath).then((res) => res.text());
} else {
artFileText = await Deno.readTextFile(artFilePath);
artFileText = await Deno.readTextFile(
artFilePath,
);
}
const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g;
let result = parserRX.exec(artFileText);
@ -16,15 +21,9 @@ export async function getAsciiArt(art: string) {
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";
}