add prettier and format all

This commit is contained in:
Thomas Ruoff
2021-02-08 22:51:35 +01:00
parent d7044f5f78
commit 78af180567
24 changed files with 266 additions and 297 deletions

View File

@@ -2,50 +2,49 @@ import { mkdir, writeFile } from 'fs'
import { spawn } from 'child_process'
import { v1 as uuidv1 } from 'uuid'
import { getDirPath, getDocPath } from './utils';
import { getDirPath, getDocPath } from './utils'
function copyToTemp(id: string, texDocument: string): Promise<string> {
return new Promise((resolve, reject) => {
const dirPath = getDirPath(id);
return new Promise((resolve, reject) => {
const dirPath = getDirPath(id)
mkdir(dirPath, (err) => {
if (err) {
reject(err);
return;
}
mkdir(dirPath, (err) => {
if (err) {
reject(err)
return
}
const docPath = getDocPath(id);
writeFile(docPath, texDocument, (err) => {
if (err) {
reject(err);
}
resolve(id);
});
});
});
const docPath = getDocPath(id)
writeFile(docPath, texDocument, (err) => {
if (err) {
reject(err)
}
resolve(id)
})
})
})
}
function generateDoc(id: string) {
return new Promise((resolve, reject) => {
const pdflatex = spawn('pdflatex', ['-interaction', 'nonstopmode', getDocPath(id)], { cwd: getDirPath(id) });
pdflatex.stderr.on('data', (data) => {
console.error('onData', data);
});
return new Promise((resolve, reject) => {
const pdflatex = spawn('pdflatex', ['-interaction', 'nonstopmode', getDocPath(id)], { cwd: getDirPath(id) })
pdflatex.stderr.on('data', (data) => {
console.error('onData', data)
})
pdflatex.on('close', (code) => {
if (code > 0) {
reject(`pdflatex returned with code ${code}`);
return;
}
console.log(`PDF ${id} generated`);
resolve(id);
});
});
pdflatex.on('close', (code) => {
if (code > 0) {
reject(`pdflatex returned with code ${code}`)
return
}
console.log(`PDF ${id} generated`)
resolve(id)
})
})
}
export default function(texDocument: string) {
const id = uuidv1();
return copyToTemp(id, texDocument)
.then(generateDoc);
};
export default async function (texDocument: string) {
const id = uuidv1()
const id_2 = await copyToTemp(id, texDocument)
return generateDoc(id_2)
}

View File

@@ -1,14 +1,14 @@
const storeDir = process.env.JSON_STORE || '/tmp/pdfer-store/';
const storeDir = process.env.JSON_STORE || '/tmp/pdfer-store/'
import { promisify } from 'util';
import { promisify } from 'util'
import JsonStore from 'json-fs-store'
const store = JsonStore(storeDir);
const store = JsonStore(storeDir)
console.log(`using json-store at ${storeDir}`);
console.log(`using json-store at ${storeDir}`)
export const list = promisify(store.list);
export const load = promisify(store.load);
export const add = promisify(store.add);
export const remove = promisify(store.remove);
export const list = promisify(store.list)
export const load = promisify(store.load)
export const add = promisify(store.add)
export const remove = promisify(store.remove)

View File

@@ -1,30 +1,29 @@
function convertLineBreaks(string) {
return string.replace(/\n/g, '\\\\');
};
return string.replace(/\n/g, '\\\\')
}
export function brief(options) {
const {
template = 'brief-fam',
subject = '',
yourRef = '',
yourRefName = 'Ihr Zeichen',
yourMail = '',
myRef = '',
customer = '',
invoice = '',
date = '\\today',
signature = '',
specialMail = '',
address = 'Max Mustermann\\\\Musterstrasse\\\\12345 Musterstadt',
opening = 'Sehr geehrte Damen und Herren',
body = '',
closing = 'Mit freundlichen Grüßen',
ps = '',
enclosing = '',
} = options
const {
template = 'brief-fam',
subject = '',
yourRef = '',
yourRefName = 'Ihr Zeichen',
yourMail = '',
myRef = '',
customer = '',
invoice = '',
date = '\\today',
signature = '',
specialMail = '',
address = 'Max Mustermann\\\\Musterstrasse\\\\12345 Musterstadt',
opening = 'Sehr geehrte Damen und Herren',
body = '',
closing = 'Mit freundlichen Grüßen',
ps = '',
enclosing = '',
} = options;
return `% brief document
return `% brief document
\\documentclass{scrlttr2}
\\LoadLetterOption{${template}}
@@ -56,5 +55,5 @@ export function brief(options) {
%\\encl{${enclosing}}
\\end{letter}
\\end{document}`;
};
\\end{document}`
}

View File

@@ -1,13 +1,13 @@
import path from 'path';
import path from 'path'
export function getDirPath(id) {
return `/tmp/pdfer-${id}`;
return `/tmp/pdfer-${id}`
}
export function getDocPath(id) {
return path.join(getDirPath(id), 'doc.tex');
return path.join(getDirPath(id), 'doc.tex')
}
export function getPdfPath(id) {
return path.join(getDirPath(id), 'doc.pdf');
return path.join(getDirPath(id), 'doc.pdf')
}