mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
extract tex cmd
to make it configurable at a later point in time
This commit is contained in:
@@ -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) => {
|
||||||
|
|||||||
@@ -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) }]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user