-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocessHtml.js
41 lines (32 loc) · 1.02 KB
/
preprocessHtml.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
const fs = require('fs');
const chokidar = require('chokidar');
const path = require('path');
const stylup = require('./index.js');
let options = {
processBlockStyles: true
}
var watching = /--watch|-w/.test(process.argv[2])
function processPHTML(event, filepath) {
if (/.phtml|.html$/.test(filepath)) {
let dirname = path.dirname(filepath)
let basename = path.basename(filepath, '.html')
let output = path.join(dirname, basename + '.manual-result.html');
fs.readFile(filepath, 'utf8', (err, html) => {
stylup.process(html, null, options).then((result) => {
// console.log(result.html)
fs.writeFile(output, result.html, () => true);
console.log("HTML file rebuilt")
// if (result.map) {
// fs.writeFile(output + '.map', result.map, () => true);
// }
});
});
}
}
if (watching) {
console.log("Watching for changes to phtml files...")
chokidar.watch('test/example.html').on('all', processPHTML)
}
else {
chokidar.watch('test/example.html', { persistent: false }).on('all', processPHTML)
}