diff --git a/lib/project.js b/lib/project.js index 4df85d3..ecfb55d 100644 --- a/lib/project.js +++ b/lib/project.js @@ -66,33 +66,33 @@ class Project { console.log(`${chalk.green.bold('project > zip')} - ${chalk.cyan('from cache')}`) } - - return this.zipBuffer } - - // Search files with glob - const globPattern = ['**', ...this.exclude.map((item) => `!${item}`)] - const files = globby.sync(globPattern, { dot: true }) - - // Create a zip file - const zip = new JSZip() - - // Add files to zip - for(const _file of files) + else { - const stats = fs.lstatSync(_file) + // Search files with glob + const globPattern = ['**', ...this.exclude.map((item) => `!${item}`)] + const files = globby.sync(globPattern, { dot: true }) - // Ignore if folder or exluded - if(stats.isFile()) + // Create a zip file + this.zip = new JSZip() + + // Add files to zip + for(const _file of files) { - const basename = path.basename(_file) - const relativePath = _file.replace(basename, '').replace(this.path, '') - zip.file(`${relativePath}${basename}`, fs.readFileSync(_file)) + const stats = fs.lstatSync(_file) + + // Ignore if folder or exluded + if(stats.isFile()) + { + const basename = path.basename(_file) + const relativePath = _file.replace(basename, '').replace(this.path, '') + this.zip.file(`${relativePath}${basename}`, fs.readFileSync(_file)) + } } } // Create and return zip buffer - this.zipBuffer = zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true }) + const zipBuffer = this.zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true }) this.zipNeedsUpdate = false // Debug @@ -101,7 +101,7 @@ class Project console.log(`${chalk.green.bold('project > zip')} - ${chalk.cyan('create')}`) } - return this.zipBuffer + return zipBuffer } /** * Add Test contents