forked from xdevelx/muilessium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulp-dss.js
52 lines (40 loc) · 1.32 KB
/
gulp-dss.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
const fs = require('fs');
const dss = require('dss');
const pug = require('pug');
const path = require('path');
const File = require('gulp-util').File;
const through = require('through');
module.exports = function gulpDSS(options) {
const files = [];
const template = fs.readFileSync(`${options.templatePath}/index.pug`, 'utf-8');
Object.keys(options.parsers).forEach((key) => {
dss.parser(key, options.parsers[key]);
});
function process(file) {
dss.parse(file.contents.toString(), {}, (parsed) => {
parsed.file = path.relative('.', file.path);
if (parsed.blocks) {
parsed.blocks.forEach((block) => {
if (block.markup) {
block.markup.compiled = pug.render(block.markup.example, {
pretty: true
});
}
});
}
files.push(parsed);
});
}
function end() {
const html = pug.render(template, {
pkg: options.pkg,
files
});
this.emit('data', new File({
path: 'index.html',
contents: Buffer.from(html, 'utf-8')
}));
this.emit('end');
}
return through(process, end);
};