-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile
85 lines (77 loc) · 2.43 KB
/
Jakefile
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { task, file, directory } = require("jake");
const { promisify } = require("util");
const fs = require("fs");
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
const rimraf = promisify(require("rimraf"));
const marked = require("marked");
const Mustache = require("mustache");
const sass = require("sass");
const puppeteer = require("puppeteer");
const nodemon = require("nodemon");
const PATH_DIR = "build";
const PATH_PHONE = ".phone";
const PATH_MARKDOWN = "README.md";
const PATH_SASS = "stylesheet.scss";
const PATH_TEMPLATE = "template.html";
const PATH_HTML = `${PATH_DIR}/resume.html`;
const PATH_CSS_BASE = "stylesheet.css";
const PATH_CSS = `${PATH_DIR}/${PATH_CSS_BASE}`;
const PATH_PDF = `${PATH_DIR}/resume.pdf`;
directory(PATH_DIR);
file(PATH_HTML, [PATH_DIR, PATH_MARKDOWN, PATH_TEMPLATE], async () => {
let phone;
try {
phone = await readFile(PATH_PHONE, { encoding: "utf8" });
} catch (e) {
throw new Error(`
Cannot read file "${PATH_PHONE}".
The repository does not include a phone number.
Please create a "${PATH_PHONE}" file containing a phone number.
`);
}
let markdown = await readFile(PATH_MARKDOWN, { encoding: "utf8" });
markdown = Mustache.render(markdown, { phone });
const rawHtml = marked.parse(markdown);
const template = await readFile(PATH_TEMPLATE, { encoding: "utf8" });
const finalHtml = Mustache.render(template, {
body: rawHtml,
stylesheet: PATH_CSS_BASE,
});
await writeFile(PATH_HTML, finalHtml, { encoding: "utf8" });
});
file(PATH_CSS, [PATH_DIR, PATH_SASS], async () => {
const result = sass.renderSync({ file: PATH_SASS });
if (result.css) {
await writeFile(PATH_CSS, result.css);
} else {
throw result;
}
});
file(PATH_PDF, [PATH_HTML, PATH_CSS], async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(`file:///${__dirname}/${PATH_HTML}`, {
waitUntil: "networkidle0",
});
await page.pdf({ format: "Letter", path: PATH_PDF });
await browser.close();
});
task("default", [PATH_PDF]);
task("watch", () => {
nodemon({
ext: "md html scss",
ignore: ["build"],
exec: "jake",
execMap: {
sh: "/bin/sh",
bat: "cmd.exe /c",
cmd: "cmd.exe /c",
},
}).on("restart", (files) => {
console.log("*** Restarting due to", files);
});
});
task("clean", [], async () => {
await rimraf(PATH_DIR);
});