extract tex cmd

to make it configurable at a later point in time
This commit is contained in:
Thomas Ruoff
2021-03-02 00:36:08 +01:00
parent 0aaccf6966
commit e601971a50
2 changed files with 15 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import { mkdir, writeFile } from 'fs'
import { spawn } from 'child_process' import { spawn } from 'child_process'
import { v1 as uuidv1 } from 'uuid' import { v1 as uuidv1 } from 'uuid'
import { getDirPath, getDocPath } from './utils' import { getDirPath, getDocPath, getTexCmd } from './utils'
function copyToTemp(id: string, texDocument: string): Promise<string> { function copyToTemp(id: string, texDocument: string): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -26,10 +26,15 @@ function copyToTemp(id: string, texDocument: string): Promise<string> {
} }
function generateDoc(id: string) { function generateDoc(id: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject): void => {
const pdflatex = spawn('pdflatex', ['-interaction', 'nonstopmode', getDocPath(id)], { cwd: getDirPath(id) }) const pdflatex = spawn(...getTexCmd(id))
pdflatex.stderr.on('data', (data) => { pdflatex.stderr?.on('data', (data: string) => {
console.error('onData', data) console.error('error: ', data)
reject()
})
pdflatex.on('error', (error) => {
console.error('error', error)
reject()
}) })
pdflatex.on('close', (code) => { pdflatex.on('close', (code) => {

View File

@@ -1,3 +1,4 @@
import { CommonSpawnOptions } from 'node:child_process'
import path from 'path' import path from 'path'
export function getDirPath(id: string) { export function getDirPath(id: string) {
@@ -11,3 +12,7 @@ export function getDocPath(id: string) {
export function getPdfPath(id: string) { export function getPdfPath(id: string) {
return path.join(getDirPath(id), 'doc.pdf') return path.join(getDirPath(id), 'doc.pdf')
} }
export function getTexCmd(id: string): [command: string, args: ReadonlyArray<string>, options: CommonSpawnOptions] {
return ['pdflatex', ['-interaction', 'nonstopmode', getDocPath(id)], { cwd: getDirPath(id) }]
}