-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert-to-pdf.js
executable file
·70 lines (61 loc) · 2.08 KB
/
convert-to-pdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const convertToPDF = require('markdown-pdf');
const through2 = require('through2');
const prompt = require('prompt');
const extra = `
## The Less Quick Version
Read the full Code of Conduct at **github.com/ReactVienna/code-of-conduct**!
`
const convert = (phones) => {
console.log('Starting conversion to PDF...');
convertToPDF({
preProcessMd: () => through2(function (chunk, enc, callback) {
const string = chunk.toString();
// Cut everything after "The less quick version"
let short = string.substring(0, string.indexOf('The Less Quick Version'));
short = `${short}${extra}`
if (phones && phones.length > 0 && phones.every(data => data.name && data.phone)) {
// Insert phone numbers
const text = "There'll always be at least one of them at any ReactVienna-sponsored space.";
const index = short.indexOf(text);
const before = short.substring(0, index);
const after = short.substring(index);
const numbers = `You can also call them:\n${phones.map(data => `- ${data.name}: ${data.phone}`).join('\n')}\n\n`;
this.push(before + numbers + after);
} else {
console.warn('No phone numbers provided, please provide at least one phone number if possible.')
this.push(short);
}
callback();
}),
}).from('./readme.md').to('./readme.pdf', () => {
console.log('Conversion to PDF finished, check readme.pdf');
});
}
const schema = {
properties: {
name: {
description: 'Enter the full name of an organizer. (e.g. Max Mustermann)'
},
phone: {
description: 'Enter their phone number, including country code (e.g. +43 664 1231231).'
},
more: {
description: 'Do you want to add another phone number? ("true" or "false")',
type: 'boolean'
}
}
};
const phones = [];
const askForPhone = () => {
prompt.get(schema, (err, result) => {
if (err) return console.error('\n\nError:', err.message);
phones.push(result);
if (result.more) {
askForPhone();
} else {
convert(phones);
}
})
}
prompt.start();
askForPhone();