10000 nested included · Issue #5 · berstend/gulp-sass-inheritance · GitHub
[go: up one dir, main page]

Skip to content

nested included #5

@brnpimentel

Description

@brnpimentel

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0