-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 1.18 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
var through = require('through2');
module.exports = function () {
return through.obj(function (file, encoding, callback) {
var context = this;
var jsonVariables = {};
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream(file.path)
});
lineReader.on('line', function (line) {
var regex = /^\$(.*)\: +(.*);/g;
var match = regex.exec(line);
if (match !== null && match.length === 3) {
var field = match[1];
var val = match[2];
jsonVariables[field] = val;
}
else
{
console.log("Error parsing line: " + line);
}
});
lineReader.on('close', function (params) {
// done parsing
//console.log(JSON.stringify(jsonVariables));
file.contents = Buffer.from(JSON.stringify(jsonVariables, null, 2));
file.path = file.path.replace(".scss", ".json").replace(".sass", ".json");
context.push(file);
callback();
});
});
};