-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (37 loc) · 1.19 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
import { obj } from "through2";
import heml from "@dragonzap/heml";
import path from "path";
var ext = ".html";
export default (options) => {
return obj((file, enc, cb) => {
console.log("Gulp-HEML: starting to process file: " + file.path);
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
console.log("Gulp-HEML: Streaming not supported");
return;
}
if (file.isBuffer()) {
const content = String(file.contents);
return heml.default(content, options).then((hemlResp) => {
file.contents = Buffer.from(hemlResp.html);
var replaceExt = replaceExt || false;
if (typeof ext === "string" && ext.length > 0) {
ext = ext.indexOf(".") === 0 ? ext : "." + ext;
let filePath = path.parse(file.path);
filePath.base = filePath.base.replace(
replaceExt ? replaceExt : path.extname(file.path),
ext,
);
// format the path back into an absolute
file.path = path.format(filePath);
}
console.log("Gulp-HEML: finished processing file: " + file.path);
return cb(null, file);
});
}
return;
});
};
export { heml };