forked from juanfran/gulp-jade-inheritance
-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Description
Hi,
how about a feature to pipe files with nested included with check()? In this case if the parent file is included in another, perform again the function and return to stream all these files.
var es = require('event-stream');
var _ = require("lodash");
var vfs = require('vinyl-fs');
var through2 = require('through2');
var gutil = require('gulp-util');
var sassGraph = require('sass-graph');
var PLUGIN_NAME = 'gulp-sass-inheritance';
var stream;
function gulpSassInheritance(options) {
options = options || {};
var files = [];
var filesPaths = [];
var graph;
function writeStream(currentFile) {
if (currentFile && currentFile.contents.length) {
files.push(currentFile);
}
}
function check(_filePaths) {
_.forEach(_filePaths, function(filePath) {
filesPaths = _.union(filesPaths, [filePath]);
if (graph.index && graph.index[filePath]) {
var fullpaths = graph.index[filePath].importedBy;
if (options.debug) {
console.log('File', filePath);
console.log(' - importedBy', fullpaths);
}
filesPaths = _.union(filesPaths, fullpaths);
}
if(fullpaths)
return check(fullpaths);
});
return true;
}
function endStream() {
if (files.length) {
graph = sassGraph.parseDir(options.dir, options);
check(_.pluck(files, 'path'));
vfs.src(filesPaths)
.pipe(es.through(
function(f) {
stream.emit('data', f);
},
function() {
stream.emit('end');
}
));
} else {
stream.emit('end');
}
}
stream = es.through(writeStream, endStream);
return stream;
};
module.exports = gulpSassInheritance;
Metadata
Metadata
Assignees
Labels
No labels