Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gulp-recursive-folder with all npm packages installed. Try it out:

var gulpRecursiveFolder = require("gulp-recursive-folder")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gulp-recursive-folder v0.9.4

Gulp plugin to work with folders reading recursively

gulp-recursive-folder

Gulp plugin that work with folders treat them recursively

Inspired of Amazing packages:

Example

Given the follow tree:

src
    modules
        debug-modules
            submodules1.js
            submodules2.js
        submodules
            submodules1.js
            submodules2.js
        modules1.js
        modules2.js
            subsubmodules
                subsubmodules1.js
                subsubmodules2.js
    src1.js
    src2.js

generates:

src
    modules
        submodules
            submodules.js
            subsubmodules
                subsubmodules.js
        modules.js
    src.js

or

src
    debug-modules.js
    modules.js
    submodules.js
    subsubmodules.js
    src.js

Depends the usage, You can use the output object folderFound like the usage section

Usage

var gulp = require('gulp'),
    path = require('path'),
    concat = require('gulp-concat'),
    recursiveFolder = require('gulp-recursive-folder'),
    pathToFolder = 'path/to/folder';
    options = {
        readFolder: 'path/to/folder',
        target: 'path/to/generate'
    }

gulp.task('generateTree', recursivefolder({
        base: options.pathToFolder,
        exclude: [    // exclude the debug modules from thus build
            'debug-modules'
        ] 
    }, function(folderFound){
    //This will loop over all folders inside pathToFolder main and recursively on the children folders, secondary
    //With folderFound.name gets the folderName
    //With folderFound.path gets all folder path found
    //With folderFound.pathTarget gets the relative path beginning from options.pathFolder
    return gulp.src(folderFound.path + "/*.js")
        .pipe(concat(folderFound.name + ".js"))
        .pipe(gulp.dest(options.target + "/" + folderFound.pathTarget));
}));

//or
gulp.task('generateConcatOfFolders', recursivefolder({
        base: options.pathToFolder // don't exclude anything
    }, function(folderFound){
        return gulp.src(folderFound.path + "/*.js")
            .pipe(concat(folderFound.name + ".js"))
            .pipe(gulp.dest(options.target));
}));

//to use it inside the task, or pipe it further
gulp.task('generateConcatOfFolders', function(){
    return recursivefolder({
        base: options.pathToFolder,
        exclude: [] // optional array of folders to exclude
    }, function(folderFound){
        return gulp.src(folderFound.path + "/*.js")
            .pipe(concat(folderFound.name + ".js"));
    })()
        .pipe(concat("bundle.js"))
        .pipe(gulp.dest(options.target));
});
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free