lib/gulp-copy.js
function gulpCopy(destination, opts) {
    const throughOptions = { objectMode: true };

    // Make sure a destination was verified
    if (typeof destination !== 'string') {
        throw new PluginError('gulp-copy', 'No valid destination specified');
    }

    // Default options
    if (opts === undefined) {
        opts = opts || {};
    } else if (typeof opts !== 'object' || opts === null) {
        throw new PluginError('gulp-copy', 'No valid options specified');
    }

    return through(throughOptions, transform);

    /**
     * Transform method, copies the file to its new destination
     * @param {object} file
     * @param {string} encoding
     * @param {function} cb
     */
    function transform(file, encoding, cb) {
        let rel = null;
        let fileDestination = null;

        if (file.isStream()) {
            cb(new PluginError('gulp-copy', 'Streaming not supported'));
        }

        if (file.isNull()) {
            cb(null, file);
        } else {
            rel = path.relative(file.cwd, file.path).replace(/\\/g, separator);

            // Strip path prefixes
            if (opts.prefix) {
                let p = opts.prefix;
                while (p-- > 0) {
                    rel = rel.substring(rel.indexOf(separator) + 1);
                }
            }

            fileDestination = path.join(destination, rel);

            // Make sure destination exists
            if (!doesPathExist(fileDestination)) {
                createDestination(fileDestination.substr(0, fileDestination.lastIndexOf(separator)));
            }

            // Copy the file
            copyFile(file.path, fileDestination, function copyFileCallback(error) {
                if (error) {
                    throw new PluginError('gulp-copy', `Could not copy file <${file.path}>: ${error.message}`);
                }

                // Update path for file so this path is used later on
                file.path = fileDestination;
                cb(null, file);
            });
        }
    }
}
function gulpCopy(destination, opts) {
    const throughOptions = { objectMode: true };

    // Make sure a destination was verified
    if (typeof destination !== 'string') {
        throw new PluginError('gulp-copy', 'No valid destination specified');
    }

    // Default options
    if (opts === undefined) {
        opts = opts || {};
    } else if (typeof opts !== 'object' || opts === null) {
        throw new PluginError('gulp-copy', 'No valid options specified');
    }

    return through(throughOptions, transform);

    /**
     * Transform method, copies the file to its new destination
     * @param {object} file
     * @param {string} encoding
     * @param {function} cb
     */
    function transform(file, encoding, cb) {
        let rel = null;
        let fileDestination = null;

        if (file.isStream()) {
            cb(new PluginError('gulp-copy', 'Streaming not supported'));
        }

        if (file.isNull()) {
            cb(null, file);
        } else {
            rel = path.relative(file.cwd, file.path).replace(/\\/g, separator);

            // Strip path prefixes
            if (opts.prefix) {
                let p = opts.prefix;
                while (p-- > 0) {
                    rel = rel.substring(rel.indexOf(separator) + 1);
                }
            }

            fileDestination = path.join(destination, rel);

            // Make sure destination exists
            if (!doesPathExist(fileDestination)) {
                createDestination(fileDestination.substr(0, fileDestination.lastIndexOf(separator)));
            }

            // Copy the file
            copyFile(file.path, fileDestination, function copyFileCallback(error) {
                if (error) {
                    throw new PluginError('gulp-copy', `Could not copy file <${file.path}>: ${error.message}`);
                }

                // Update path for file so this path is used later on
                file.path = fileDestination;
                cb(null, file);
            });
        }
    }
}
function gulpCopy ( destination , opts ) { const throughOptions = { objectMode : true } ; // Make sure a destination was verified if ( typeof destination !== 'string' ) { throw new PluginError ( 'gulp-copy' , 'No valid destination specified' ) ; } // Default options if ( opts === undefined ) { opts = opts || { } ; } else if ( typeof opts !== 'object' || opts === null ) { throw new PluginError ( 'gulp-copy' , 'No valid options specified' ) ; } return through ( throughOptions , transform ) ; /**
     * Transform method, copies the file to its new destination
     * @param {object} file
     * @param {string} encoding
     * @param {function} cb
     */ function transform ( file , encoding , cb ) { let rel = null ; let fileDestination = null ; if ( file . isStream ( ) ) { cb ( new PluginError ( 'gulp-copy' , 'Streaming not supported' ) ) ; } if ( file . isNull ( ) ) { cb ( null , file ) ; } else { rel = path . relative ( file . cwd , file . path ) . replace ( / \\ / g , separator ) ; // Strip path prefixes if ( opts . prefix ) { let p = opts . prefix ; while ( p -- > 0 ) { rel = rel . substring ( rel . indexOf ( separator ) + 1 ) ; } } fileDestination = path . join ( destination , rel ) ; // Make sure destination exists if ( ! doesPathExist ( fileDestination ) ) { createDestination ( fileDestination . substr ( 0 , fileDestination . lastIndexOf ( separator ) ) ) ; } // Copy the file copyFile ( file . path , fileDestination , function copyFileCallback ( error ) { if ( error ) { throw new PluginError ( 'gulp-copy' , ` ${ file . path } ${ error . message } ` ) ; } // Update path for file so this path is used later on file . path = fileDestination ; cb ( null , file ) ; } ) ; } } }
gulp copy method
@param {string} destination
@param {object} opts
@returns {object}
gulp copy method