-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (43 loc) · 1.57 KB
/
index.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
const { lstatSync, readdirSync, watch, writeFileSync } = require('fs');
const { join } = require('path');
const inquirer = require('inquirer');
const isDirectory = source => lstatSync(source).isDirectory();
const isCourse = dir => !['node_modules', 'slides-src', '.git', 'ignore'].includes(dir);
const getDirectories = source =>
readdirSync(source).map(name => join(source, name)).filter(isDirectory).filter(isCourse);
const pug = require('pug');
const browserSync = require("browser-sync").create();
const directories = getDirectories('.');
async function start () {
const answers = await inquirer.prompt([{
type: 'list',
name: 'coursePath',
choices: directories,
message: 'Seleccione la capacitación:'
}]);
const { coursePath: slidesFolder } = answers;
const slidesFile = join(__dirname, slidesFolder, 'diapositivas.pug');
const slidesFileDist = join(slidesFolder, 'index.html');
compileSlides({ slidesFile, slidesFileDist, slidesFolder });
watch(slidesFile, () => compileSlides({ slidesFile, slidesFileDist, slidesFolder }));
browserSync.init({
server: {
baseDir: join(__dirname, slidesFolder),
index: `index.html`
},
serveStatic: [{
route: '/slides-src',
dir: join(__dirname, 'slides-src/')
}]
});
browserSync.reload('*.html');
browserSync.watch(slidesFileDist).on('change', browserSync.reload);
}
function compileSlides({ slidesFile, slidesFileDist, slidesFolder }) {
const options = {
pretty: true
};
const slidesHTML = pug.compileFile(slidesFile, options)();
writeFileSync(slidesFileDist, slidesHTML, () => null);
}
start();