Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested included #5

Closed
brnpimentel opened this issue Nov 12, 2015 · 1 comment
Closed

nested included #5

brnpimentel opened this issue Nov 12, 2015 · 1 comment

Comments

@brnpimentel
Copy link

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;
@berstend
Copy link
Owner

berstend commented May 12, 2017

Hi @brnmonteiro - thanks a lot!

This feature has been added in the v1.1.0 release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants