-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-slides.js
76 lines (66 loc) · 1.96 KB
/
generate-slides.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
71
72
73
74
75
76
const util = require("util");
const fs = require("fs");
const rimraf = require("rimraf");
const ncp = require("ncp").ncp;
const chokidar = require("chokidar");
const ncpPromise = util.promisify(ncp);
const args = process.argv.slice(2);
// Configuration
const isWatching = args.includes("watch");
const mainSlideLocation = "./slides/asciidoc/index.adoc";
const outputDir = "./docs/slides/";
const directoryToCopy = ["theme", "fonts", "images", "screencasts"];
if (isWatching) {
chokidar
.watch(".", {
ignored: /(^|[\/\\])\../,
persistent: true
})
.on("all", (event, path) => {
runWorkFlow();
});
} else {
workflow();
}
const runWorkFlow = debounce(function() {
console.log("📏 👀 change detected !");
workflow();
}, 2000);
function workflow() {
console.log("🏗 👷 start build slides ... 📺");
// Clean
if (fs.existsSync(outputDir)) {
rimraf.sync(outputDir);
}
// Create slides directory
fs.mkdirSync(outputDir);
Promise.all(
directoryToCopy.map(path => {
ncpPromise(`./slides/${path}`, `${outputDir}${path}`);
})
).then(() => {
// Load asciidoctor.js and asciidoctor-reveal.js
const asciidoctor = require("asciidoctor.js")();
const asciidoctorRevealjs = require("asciidoctor-reveal.js");
asciidoctorRevealjs.register();
// Convert the document 'index.adoc' using the reveal.js converter
const options = { safe: "safe", backend: "revealjs", to_dir: outputDir };
asciidoctor.convertFile(mainSlideLocation, options);
console.log("🎉 👌 slides successfully generated");
});
}
function debounce(func, wait, immediate) {
let timeout;
return function() {
const context = this,
args = arguments;
const later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}