lib/functions/downloadIncludedFiles.js
function downloadIncludedFiles(included, dir) {
    return new Promise((resolve, reject) => {
        const includeDir = dir ? path.join('.', dir, constants.INCLUDE_DIR) : path.join('.', constants.INCLUDE_DIR);

        // Create include folder if it doesn't exist yet
        try {
            if (!fs.existsSync(includeDir)) {
                fs.mkdirSync(includeDir);
            }

            // Create list of filenames
            const filenames = [];
            for (const includeFile of included) {
                filenames.push(includeFile[0]);
            }

            // Remove all files in includeDir not in includeFile
            const allFiles = fs.readdirSync(includeDir);
            const filesToDelete = [];
            for (const file of allFiles) {
                if (filenames.indexOf(file) < 0) {
                    filesToDelete.push(path.join(includeDir, file));
                }
            }
            for (const fileToDelete of filesToDelete) {
                fs.removeSync(fileToDelete);
            }

            // Download all the files
            const promises = [];
            for (const file of included) {
                promises.push(getAndWriteIncludedFile(file, includeDir));
            }
            Promise.all(promises).then((values) => {
                const failed = [];
                const successful = [];
                for (const value of values) {
                    if (value.successful) {
                        successful.push(value.fileName);
                    } else {
                        failed.push(value.fileName);
                    }
                }
                resolve({
                    failed,
                    successful,
                });
            });
        } catch (err) {
            reject(err);
            return;
        }
    });
}
function downloadIncludedFiles(included, dir) {
    return new Promise((resolve, reject) => {
        const includeDir = dir ? path.join('.', dir, constants.INCLUDE_DIR) : path.join('.', constants.INCLUDE_DIR);

        // Create include folder if it doesn't exist yet
        try {
            if (!fs.existsSync(includeDir)) {
                fs.mkdirSync(includeDir);
            }

            // Create list of filenames
            const filenames = [];
            for (const includeFile of included) {
                filenames.push(includeFile[0]);
            }

            // Remove all files in includeDir not in includeFile
            const allFiles = fs.readdirSync(includeDir);
            const filesToDelete = [];
            for (const file of allFiles) {
                if (filenames.indexOf(file) < 0) {
                    filesToDelete.push(path.join(includeDir, file));
                }
            }
            for (const fileToDelete of filesToDelete) {
                fs.removeSync(fileToDelete);
            }

            // Download all the files
            const promises = [];
            for (const file of included) {
                promises.push(getAndWriteIncludedFile(file, includeDir));
            }
            Promise.all(promises).then((values) => {
                const failed = [];
                const successful = [];
                for (const value of values) {
                    if (value.successful) {
                        successful.push(value.fileName);
                    } else {
                        failed.push(value.fileName);
                    }
                }
                resolve({
                    failed,
                    successful,
                });
            });
        } catch (err) {
            reject(err);
            return;
        }
    });
}
function downloadIncludedFiles ( included , dir ) { return new Promise ( ( resolve , reject ) => { const includeDir = dir ? path . join ( '.' , dir , constants . INCLUDE_DIR ) : path . join ( '.' , constants . INCLUDE_DIR ) ; // Create include folder if it doesn't exist yet try { if ( ! fs . existsSync ( includeDir ) ) { fs . mkdirSync ( includeDir ) ; } // Create list of filenames const filenames = [ ] ; for ( const includeFile of included ) { filenames . push ( includeFile [ 0 ] ) ; } // Remove all files in includeDir not in includeFile const allFiles = fs . readdirSync ( includeDir ) ; const filesToDelete = [ ] ; for ( const file of allFiles ) { if ( filenames . indexOf ( file ) < 0 ) { filesToDelete . push ( path . join ( includeDir , file ) ) ; } } for ( const fileToDelete of filesToDelete ) { fs . removeSync ( fileToDelete ) ; } // Download all the files const promises = [ ] ; for ( const file of included ) { promises . push ( getAndWriteIncludedFile ( file , includeDir ) ) ; } Promise . all ( promises ) . then ( ( values ) => { const failed = [ ] ; const successful = [ ] ; for ( const value of values ) { if ( value . successful ) { successful . push ( value . fileName ) ; } else { failed . push ( value . fileName ) ; } } resolve ( { failed , successful , } ) ; } ) ; } catch ( err ) { reject ( err ) ; return ; } } ) ; }
Download files specified by include file

@param {array} included - An authorized OAuth2 client.
@param {String} dir - Directory in which the project is located.
@returns {Promise} - Promise resolving
Download files specified by include file