lib/utils.js
function copyUsingMatcher(src, dest, excludeMatcher) {

    var filenames,
        basedir,
        i,
        name,
        file,
        newdest,
        type;

    //console.log('copying ' + src + ' to ' + dest);
    /* check if source path exists */

    if (!exists(src)) {
        throw new Error(src + ' does not exist');
    }

    /* check if source is a directory */

    if (!fs.statSync(src).isDirectory()) {
        throw new Error(src + ' must be a directory');
    }

    /* get the names of all files and directories under source in an array */

    filenames = fs.readdirSync(src);
    basedir = src;

    /* check if destination directory exists */

    if (!exists(dest)) {
        fs.mkdirSync(dest, parseInt('755', 8));
    }

    for (i = 0; i < filenames.length; i += 1) {

        name = filenames[i];
        file = basedir + '/' + name;
        type = fs.statSync(file).isDirectory() ? 'dir' : 'file';
        newdest = dest + '/' + name;

        if (!excludeMatcher(file, type)) {
            //console.log('Copy ' + file + ' as ' + newdest);
            if (type === 'dir') {
                copyUsingMatcher(file, newdest, excludeMatcher);
            } else {
                copyFile(file, newdest);
            }
        }
    }
}
function copyUsingMatcher(src, dest, excludeMatcher) {

    var filenames,
        basedir,
        i,
        name,
        file,
        newdest,
        type;

    //console.log('copying ' + src + ' to ' + dest);
    /* check if source path exists */

    if (!exists(src)) {
        throw new Error(src + ' does not exist');
    }

    /* check if source is a directory */

    if (!fs.statSync(src).isDirectory()) {
        throw new Error(src + ' must be a directory');
    }

    /* get the names of all files and directories under source in an array */

    filenames = fs.readdirSync(src);
    basedir = src;

    /* check if destination directory exists */

    if (!exists(dest)) {
        fs.mkdirSync(dest, parseInt('755', 8));
    }

    for (i = 0; i < filenames.length; i += 1) {

        name = filenames[i];
        file = basedir + '/' + name;
        type = fs.statSync(file).isDirectory() ? 'dir' : 'file';
        newdest = dest + '/' + name;

        if (!excludeMatcher(file, type)) {
            //console.log('Copy ' + file + ' as ' + newdest);
            if (type === 'dir') {
                copyUsingMatcher(file, newdest, excludeMatcher);
            } else {
                copyFile(file, newdest);
            }
        }
    }
}
function copyUsingMatcher ( src , dest , excludeMatcher ) { var filenames , basedir , i , name , file , newdest , type ; //console.log('copying ' + src + ' to ' + dest); /* check if source path exists */ if ( ! exists ( src ) ) { throw new Error ( src + ' does not exist' ) ; } /* check if source is a directory */ if ( ! fs . statSync ( src ) . isDirectory ( ) ) { throw new Error ( src + ' must be a directory' ) ; } /* get the names of all files and directories under source in an array */ filenames = fs . readdirSync ( src ) ; basedir = src ; /* check if destination directory exists */ if ( ! exists ( dest ) ) { fs . mkdirSync ( dest , parseInt ( '755' , 8 ) ) ; } for ( i = 0 ; i < filenames . length ; i += 1 ) { name = filenames [ i ] ; file = basedir + '/' + name ; type = fs . statSync ( file ) . isDirectory ( ) ? 'dir' : 'file' ; newdest = dest + '/' + name ; if ( ! excludeMatcher ( file , type ) ) { //console.log('Copy ' + file + ' as ' + newdest); if ( type === 'dir' ) { copyUsingMatcher ( file , newdest , excludeMatcher ) ; } else { copyFile ( file , newdest ) ; } } } }
recursively copies the source to destination directory based on a matcher
that returns whether a file is to be excluded.
@param {string} src source dir.
@param {string} dest destination dir.
@param {function} excludeMatcher the matcher that determines if a given file
is to be excluded.
recursively copies the source to destination directory based on a matcher that returns whether a file is to be excluded .