diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..ac72573
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+; EditorConfig file: http://EditorConfig.org
+; Install the "EditorConfig" plugin into Sublime Text to use
+
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 0000000..a680367
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1 @@
+.next
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..23b8710
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,7 @@
+{
+ "trailingComma": "es5",
+ "tabWidth": 2,
+ "semi": false,
+ "singleQuote": true,
+ "printWidth": 120
+}
diff --git a/components/App.test.tsx b/components/App.test.tsx
index b84af98..76d121e 100644
--- a/components/App.test.tsx
+++ b/components/App.test.tsx
@@ -1,8 +1,8 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import App from './App';
+import React from 'react'
+import ReactDOM from 'react-dom'
+import App from './App'
it('renders without crashing', () => {
- const div = document.createElement('div');
- ReactDOM.render(, div);
-});
+ const div = document.createElement('div')
+ ReactDOM.render(, div)
+})
diff --git a/components/App.tsx b/components/App.tsx
index a5b7434..ead8169 100644
--- a/components/App.tsx
+++ b/components/App.tsx
@@ -1,25 +1,27 @@
-import React, { Component } from 'react';
-import LetterOptions from './LetterOptions';
-import Button from './Button';
-import Preview from './Preview';
-import LatestList from './LatestList';
-import {generatePdf, getLatest, removeLatest} from './apiHelper';
+import React, { Component } from 'react'
+import LetterOptions from './LetterOptions'
+import Button from './Button'
+import Preview from './Preview'
+import LatestList from './LatestList'
+import { generatePdf, getLatest, removeLatest } from './apiHelper'
//import './App.css';
class App extends Component {
componentDidMount() {
- this._getLatest();
+ this._getLatest()
}
render() {
- const state = this.state || {};
+ const state = this.state || {}
return (
-
-
+
@@ -28,73 +30,67 @@ class App extends Component {
-
+
- );
+ )
}
_onSelectLatest(selectedOptions) {
- this.setState({options: Object.assign({}, selectedOptions)});
+ this.setState({ options: Object.assign({}, selectedOptions) })
}
_onRemoveLatest(item) {
- removeLatest(item)
- .then(() => {
- const latest = this.state.latest
- .filter(curr => curr.id !== item.id);
+ removeLatest(item).then(() => {
+ const latest = this.state.latest.filter((curr) => curr.id !== item.id)
- this.setState({ latest });
- });
+ this.setState({ latest })
+ })
}
_onClear() {
- window.location.reload();
+ window.location.reload()
}
_onGenerate() {
- const state = this.state || {};
+ const state = this.state || {}
this.setState({
pdfIsLoading: true,
- pdfError: null
+ pdfError: null,
})
generatePdf(state.options)
.then((data) => {
- const {id} = data;
+ const { id } = data
this.setState({
pdfIsLoading: false,
- pdfUrl: `/api/pdf/${id}`
- });
+ pdfUrl: `/api/pdf/${id}`,
+ })
})
.catch((error) => {
this.setState({
pdfIsLoading: false,
pdfError: error.message,
- pdfUrl: null
- });
+ pdfUrl: null,
+ })
})
.then(() => this._getLatest())
}
_getLatest() {
getLatest()
- .then(latest => this.setState({latest}))
- .catch(err => console.error('Unable to get latest:', err));
+ .then((latest) => this.setState({ latest }))
+ .catch((err) => console.error('Unable to get latest:', err))
}
_onChange(name, event) {
if (!name) {
- return;
+ return
}
- const value = event && event.target && event.target.value;
- const options = Object.assign({}, this.state.options, {[name]: value || undefined});
- this.setState({options});
+ const value = event && event.target && event.target.value
+ const options = Object.assign({}, this.state.options, { [name]: value || undefined })
+ this.setState({ options })
}
}
-export default App;
+export default App
diff --git a/components/Button.tsx b/components/Button.tsx
index 045e509..1e42435 100644
--- a/components/Button.tsx
+++ b/components/Button.tsx
@@ -1,7 +1,9 @@
-import React from 'react';
+import React from 'react'
-export default function(props) {
+export default function (props) {
return (
-
- );
+
+ )
}
diff --git a/components/Header.tsx b/components/Header.tsx
index e98ad00..0bbadb6 100644
--- a/components/Header.tsx
+++ b/components/Header.tsx
@@ -1,6 +1,6 @@
-import React from 'react';
+import React from 'react'
-export default function() {
+export default function () {
return (
PDFer
diff --git a/components/Input.tsx b/components/Input.tsx
index ae674cd..5002eae 100644
--- a/components/Input.tsx
+++ b/components/Input.tsx
@@ -1,6 +1,6 @@
-import React from 'react';
+import React from 'react'
-export default function(props) {
+export default function (props) {
return (
- );
+ )
}
diff --git a/components/LatestList.tsx b/components/LatestList.tsx
index c6ef828..09cacb6 100644
--- a/components/LatestList.tsx
+++ b/components/LatestList.tsx
@@ -1,24 +1,26 @@
-import React from 'react';
-import Button from './Button';
+import React from 'react'
+import Button from './Button'
-export default function(props) {
- const latest = props.latest || [];
- const latestElements = latest.map(item => {
- const created = new Date(item.created);
- const hrefId = `#item-${item.id}`;
+export default function (props) {
+ const latest = props.latest || []
+ const latestElements = latest.map((item) => {
+ const created = new Date(item.created)
+ const hrefId = `#item-${item.id}`
return (
- props.onSelect(item)}>{created.toLocaleString()}
-
+ props.onSelect(item)}>
+ {created.toLocaleString()}
+
+
- );
- });
+ )
+ })
return (
- );
+ )
}
diff --git a/components/Layout.tsx b/components/Layout.tsx
index 8e23c8e..c1318b5 100644
--- a/components/Layout.tsx
+++ b/components/Layout.tsx
@@ -1,14 +1,12 @@
-import React from 'react';
+import React from 'react'
-import Header from './Header';
+import Header from './Header'
-export default function(props) {
+export default function (props) {
return (
-
- { props.children }
-
+
{props.children}
- );
+ )
}
diff --git a/components/LetterOptions.tsx b/components/LetterOptions.tsx
index be7d465..eec156f 100644
--- a/components/LetterOptions.tsx
+++ b/components/LetterOptions.tsx
@@ -1,33 +1,33 @@
-import React from 'react';
+import React from 'react'
-import Collapsible from 'react-collapsible';
-import Input from './Input';
-import TextAreaInput from './TextAreaInput';
-import Select from './Select';
+import Collapsible from 'react-collapsible'
+import Input from './Input'
+import TextAreaInput from './TextAreaInput'
+import Select from './Select'
//import './LetterOptions.css';
-const EXAMPLE_ADDRESS = 'Max Mustermann\nMusterstr. 73\n12345 Musterstadt';
+const EXAMPLE_ADDRESS = 'Max Mustermann\nMusterstr. 73\n12345 Musterstadt'
-export default function(props) {
+export default function (props) {
const templateTypeOptions = [
{
value: 'brief-fam',
- name: 'Familie'
+ name: 'Familie',
},
{
value: 'brief-valerie',
- name: 'Valerie'
+ name: 'Valerie',
},
{
value: 'brief-rain',
- name: 'Rain Baumeister'
+ name: 'Rain Baumeister',
},
{
value: 'brief-thomas',
- name: 'Thomas'
- }
- ];
+ name: 'Thomas',
+ },
+ ]
return (
@@ -46,53 +46,16 @@ export default function(props) {
onchange={props.onChange}
value={props.address}
/>
-
+
-
-
-
-
-
+
+
+
+
+
-
+
-
+
- );
-};
+ )
+}
diff --git a/components/Preview.tsx b/components/Preview.tsx
index 6c80c44..8e0cced 100644
--- a/components/Preview.tsx
+++ b/components/Preview.tsx
@@ -1,10 +1,8 @@
-import React from 'react';
+import React from 'react'
-export default props => {
+export default (props) => {
if (props.pdfIsLoading) {
- return (
- Lade…
- );
+ return Lade…
}
const errorStyles = {
@@ -12,26 +10,27 @@ export default props => {
color: 'white',
backgroundColor: '#d81e1e',
borderRadius: '3px',
- };
+ }
if (props.pdfError) {
return (
- 😢 {props.pdfError}
- );
+
+
+ 😢
+ {' '}
+ {props.pdfError}
+
+ )
}
if (!props.pdfUrl) {
- return (
- Knopf drücken dann gibts hier was zu sehen!
- );
+ return Knopf drücken dann gibts hier was zu sehen!
}
const styles = {
width: '700px',
- height: '1050px'
- };
+ height: '1050px',
+ }
- return (
-
- );
-};
+ return
+}
diff --git a/components/Select.tsx b/components/Select.tsx
index da5180d..f14c694 100644
--- a/components/Select.tsx
+++ b/components/Select.tsx
@@ -1,18 +1,18 @@
-import React from 'react';
+import React from 'react'
export default (props) => {
- const { options = [] } = props;
+ const { options = [] } = props
return (
- );
+ )
}
diff --git a/components/TextAreaInput.tsx b/components/TextAreaInput.tsx
index 451416a..782ce82 100644
--- a/components/TextAreaInput.tsx
+++ b/components/TextAreaInput.tsx
@@ -1,6 +1,6 @@
-import React from 'react';
+import React from 'react'
-export default function(props) {
+export default function (props) {
return (
- );
+ )
}
diff --git a/components/apiHelper.tsx b/components/apiHelper.tsx
index 45d3214..c74f127 100644
--- a/components/apiHelper.tsx
+++ b/components/apiHelper.tsx
@@ -1,32 +1,31 @@
function checkStatus(res) {
- if (res.status < 200 || res.status >= 400) {
- throw new Error(`Something went wrong (Status ${res.status}) - I do feel very sorry!`);
- }
+ if (res.status < 200 || res.status >= 400) {
+ throw new Error(`Something went wrong (Status ${res.status}) - I do feel very sorry!`)
+ }
- return res;
+ return res
}
-export function generatePdf(state){
- const options = {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(state)
- };
+export function generatePdf(state) {
+ const options = {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(state),
+ }
- return fetch('/api/pdf/generate/brief', options)
- .then(checkStatus)
- .then(res => res.json());
+ return fetch('/api/pdf/generate/brief', options)
+ .then(checkStatus)
+ .then((res) => res.json())
}
export function getLatest() {
- return fetch('/api/pdf/latest')
- .then(checkStatus)
- .then(res => res.json());
+ return fetch('/api/pdf/latest')
+ .then(checkStatus)
+ .then((res) => res.json())
}
export function removeLatest(item) {
- return fetch(`/api/pdf/latest/${item.id}`, {method: 'DELETE'})
- .then(checkStatus);
+ return fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' }).then(checkStatus)
}
diff --git a/components/index.tsx b/components/index.tsx
index 54c5ef1..fde0d67 100644
--- a/components/index.tsx
+++ b/components/index.tsx
@@ -1,9 +1,6 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import App from './App';
-import './index.css';
+import React from 'react'
+import ReactDOM from 'react-dom'
+import App from './App'
+import './index.css'
-ReactDOM.render(
- ,
- document.getElementById('root')
-);
+ReactDOM.render(, document.getElementById('root'))
diff --git a/lib/renderer.ts b/lib/renderer.ts
index 84e87e0..9d7e631 100644
--- a/lib/renderer.ts
+++ b/lib/renderer.ts
@@ -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 {
- 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)
+}
diff --git a/lib/store.ts b/lib/store.ts
index 227c922..da0b46b 100644
--- a/lib/store.ts
+++ b/lib/store.ts
@@ -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)
diff --git a/lib/templates.ts b/lib/templates.ts
index 0e230ca..6e7d5e3 100644
--- a/lib/templates.ts
+++ b/lib/templates.ts
@@ -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}`
+}
diff --git a/lib/utils.ts b/lib/utils.ts
index b5ee686..fc4cc52 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -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')
}
diff --git a/package-lock.json b/package-lock.json
index 1ba739a..68e0048 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
- "name": "with-typescript",
- "version": "1.0.0",
+ "name": "pdfer",
+ "version": "2.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 58e8a7b..f714834 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,8 @@
"dev": "next",
"build": "next build",
"start": "next start",
- "type-check": "tsc"
+ "type-check": "tsc",
+ "format": "prettier --write **/*.{ts,tsx,json}"
},
"dependencies": {
"json-fs-store": "^1.0.1",
diff --git a/pages/index.tsx b/pages/index.tsx
index 48a4a9d..dd896ab 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -3,7 +3,7 @@ import App from '../components/App'
const IndexPage = () => (
-
+
)
diff --git a/templates/brief.js b/templates/brief.ts
similarity index 51%
rename from templates/brief.js
rename to templates/brief.ts
index 3448c6c..2b6ac43 100644
--- a/templates/brief.js
+++ b/templates/brief.ts
@@ -1,30 +1,29 @@
function convertLineBreaks(string) {
- return string.replace(/\n/g, '\\\\');
-};
+ return string.replace(/\n/g, '\\\\')
+}
export default (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 default (options) => {
%\\encl{${enclosing}}
\\end{letter}
-\\end{document}`;
-};
+\\end{document}`
+}