-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (28 loc) · 906 Bytes
/
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
'use strict';
const {parseDir} = require('sass-graph');
const gulpFlatmap = require('gulp-flatmap');
const {src} = require('vinyl-fs');
const PluginError = require('plugin-error');
const PLUGIN_NAME = 'gulp-cached-sass';
const plugin = function (baseDir) {
if (!baseDir) {
throw new PluginError(PLUGIN_NAME, 'Missing baseDir!');
}
const graph = parseDir(baseDir);
const getUpdateFile = (currentStream, file) => {
let files = [file.path];
const addParent = (childPath) =>
graph.visitAncestors(childPath, (parent) => {
if (!files.includes(parent)) {
files.push(parent);
}
return addParent(parent);
});
addParent(file.path);
return src(files, {
base: baseDir
});
};
return gulpFlatmap(getUpdateFile);
};
module.exports = plugin;