-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (30 loc) · 1 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
var mapStream = require("map-stream");
var path = require("path");
var fs = require("fs");
function processTemplates(options) {
options = options || {};
function doubleQuote(string) {
return '"' + string + '"';
}
function notBlank(string) {
return string.trim() != "";
}
return mapStream(function(file, callback) {
if (file.isNull()) return callback(null, file);
var includePath = options.includePath || path.dirname(file.path);
var content = file.contents.toString("utf-8");
content = content.replace(/\/\*\s*@include\s+([^\*]+)\*\//g, function(match, fileName) {
var filePath = path.join(includePath, fileName.trim());
return fs.readFileSync(filePath)
.toString("utf-8")
.replace(/"/g, "\\\"")
.split("\n")
.filter(notBlank)
.map(doubleQuote)
.join(" + ");
});
file.contents = new Buffer(content);
callback(null, file);
});
}
module.exports = processTemplates;