fix: local ASCII Art inclusion
This commit is contained in:
parent
90f1547e02
commit
cdeef54f68
@ -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 }}
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
|
import { log } from "./logfile.ts";
|
||||||
|
import { join } from "@std/path";
|
||||||
|
|
||||||
export async function getAsciiArt(art: string) {
|
export async function getAsciiArt(art: string) {
|
||||||
|
try {
|
||||||
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
|
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
|
||||||
getBearmetalAsciiPath();
|
join(import.meta.dirname || "", "../asciiart.txt");
|
||||||
if (!artFilePath) return art;
|
|
||||||
let artFileText: string;
|
let artFileText: string;
|
||||||
if (artFilePath.startsWith("http")) {
|
if (artFilePath?.startsWith("http")) {
|
||||||
artFileText = await fetch(artFilePath).then((res) => res.text());
|
artFileText = await fetch(artFilePath).then((res) => res.text());
|
||||||
} else {
|
} else {
|
||||||
artFileText = await Deno.readTextFile(artFilePath);
|
artFileText = await Deno.readTextFile(
|
||||||
|
artFilePath,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g;
|
const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g;
|
||||||
let result = parserRX.exec(artFileText);
|
let result = parserRX.exec(artFileText);
|
||||||
@ -16,15 +21,9 @@ export async function getAsciiArt(art: string) {
|
|||||||
if (name === art) return artText;
|
if (name === art) return artText;
|
||||||
result = parserRX.exec(artFileText);
|
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";
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user