refactor: rename doerg-tex → doerg-temml-worker

This commit is contained in:
2026-02-28 21:38:23 -07:00
parent 6ef81a4a45
commit 8b2fb7a010
13 changed files with 17 additions and 22 deletions

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env node
const commandLineArgs = require ("command-line-args")
const temml = require ("temml")
const fs = require ("node:fs")
const path = require ("node:path")
const { DecoderStream, EncoderStream } = require ("cbor-x")
const { Transform } = require('node:stream')
const cli_spec =
[ { name: "preamble" }
]
function load_preambles (preamble) {
const data = fs.readFileSync (preamble, "utf8") .toString ()
return temml.definePreamble (data)
}
let macros = {}
function is_render_command (cmd) {
return cmd instanceof Array
&& cmd.length === 1
&& typeof cmd[0] === "string"
}
function do_command (cmd) {
try {
if (typeof cmd === "string") {
return temml.renderToString (cmd, {macros})
} else if (is_render_command (cmd)) {
return temml.renderToString (cmd[0], {displayMode: true,macros})
} else {
return null
}
} catch (e) {
console.error (e)
return {type: "error", error: e}
}
}
function main () {
const options = commandLineArgs (cli_spec)
macros = load_preambles (options.preamble)
const decoder = new DecoderStream ()
const encoder = new EncoderStream ()
process.stdin.pipe (decoder)
const command_responses = decoder.map (do_command)
decoder
.map (do_command)
.pipe (encoder)
.pipe (process.stdout)
}
main ()