-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 1.12 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
'use strict';
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const parse = require('./parseSCSS');
module.exports = (params) => {
const workingDir = params.cwd || 'src/scss/';
const base = path.join(workingDir, params.base);
return new Promise((resolve, reject) => {
let promises = [];
const content = fs.readFileSync(base).toString();
const rl = readline.createInterface({
input: fs.createReadStream(base),
});
rl.on('line', (line) => {
const match = line.match(/@import "(.*)"/);
if (match) {
const name = path.join(workingDir, `_${match[1]}.scss`);
const file = fs.readFileSync(name).toString();
promises.push(parse({
css: file,
keyword: params.keyword || null,
}));
}
});
rl.on('close', () => {
Promise.all(promises).then((data) => {
const global = data.map(x => x.css);
const splits = data.map(x => x.splits.join(''));
fs.writeFileSync(path.join(workingDir, params.partial), splits.join(''))
resolve(global.join(''));
});
});
})
};