-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.js
36 lines (28 loc) · 856 Bytes
/
preprocess.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
const fs = require('fs');
const chokidar = require('chokidar');
const path = require('path');
const stylup = require('stylup');
let options = {
processBlockStyles: true
}
// A script to manually preprocess HTML
function process(dir) {
// var dir = path.dirname(input);
chokidar.watch(dir).on('all', (event, filepath) => {
if (/.phtml$/.test(filepath)) {
let dirname = path.dirname(filepath)
let basename = path.basename(filepath, '.phtml')
let output = path.join(dirname, basename + '.html');
fs.readFile(filepath, 'utf8', (err, html) => {
stylup.process(html, null, options).then((result) => {
// console.log(result.html)
fs.writeFile(output, result.html, () => true);
// if (result.map) {
// fs.writeFile(output + '.map', result.map, () => true);
// }
});
});
}
});
}
process('examples/')