From 0ec3fba352d4a93def312389bcd3d77344826ad6 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 29 Jan 2017 00:58:06 -0500 Subject: [PATCH] if target is directory then copy files --- lib/pipeline.js | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/lib/pipeline.js b/lib/pipeline.js index 8fa40d933..50c0dd526 100644 --- a/lib/pipeline.js +++ b/lib/pipeline.js @@ -16,13 +16,13 @@ Pipeline.prototype.build = function(abi) { // TODO: run the plugin here instead, for each file - var content = this.assetFiles[targetFile].map(file => { + var contentFiles = this.assetFiles[targetFile].map(file => { self.logger.info("reading " + file.filename); var pipelinePlugins = this.plugins.getPluginsFor('pipeline'); if (file.filename === 'embark.js') { - return file.content + "\n" + abi; + return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true}; } else if (file.filename === 'embark-plugins.js') { var filesFromPlugins = []; @@ -35,7 +35,7 @@ Pipeline.prototype.build = function(abi) { var fileObjects = plugin.runFilePipeline(); for (var i=0; i < fileObjects.length; i++) { var fileObject = fileObjects[i]; - console.debug(JSON.stringify(fileObject)); + //console.debug(JSON.stringify(fileObject)); filesFromPlugins.push(fileObject); } } @@ -54,7 +54,7 @@ Pipeline.prototype.build = function(abi) { console.log("skipping"); return; } - file.content = plugin.runPipeline({targetFile: file.filename, source: file.content}); + file.content = plugin.runPipeline({targetFile: file.filename, source: file.content, modified: true}); } catch(err) { self.logger.error(err.message); @@ -64,16 +64,20 @@ Pipeline.prototype.build = function(abi) { return file.content; }); - return fileContents.join('\n'); + //return fileContents.join('\n'); + return {content: fileContents.join('\n'), filename: "embark-plugins.js", path: "", modified: true}; } else if (['web3.js', 'ipfs.js', 'ipfs-api.js', 'orbit.js'].indexOf(file.filename) >= 0) { - return file.content; + //return file.content; + file.modified = true; + return file; } else { if (pipelinePlugins.length > 0) { pipelinePlugins.forEach(function(plugin) { try { file.content = plugin.runPipeline({targetFile: file.filename, source: file.content}); + file.modified = true; } catch(err) { self.logger.error(err.message); @@ -81,16 +85,38 @@ Pipeline.prototype.build = function(abi) { }); } - return file.content; + //return file.content; + return file; } - }).join("\n"); + }); var dir = targetFile.split('/').slice(0, -1).join('/'); self.logger.info("creating dir " + this.buildDir + dir); mkdirp.sync(this.buildDir + dir); - self.logger.info("writing file " + this.buildDir + targetFile); - fs.writeFileSync(this.buildDir + targetFile, content); + // if it's a directory + if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) { + var targetDir = targetFile; + + if (targetDir.slice(-1) !== '/') { + targetDir = targetDir + '/'; + } + + contentFiles.map(function(file) { + var filename = file.filename.replace('app/', ''); + filename = filename.replace(targetDir, ''); + self.logger.info("writing file " + self.buildDir + targetDir + filename); + + fs.writeFileSync(self.buildDir + targetDir + filename, fs.readFileSync(file.filename)); + }); + } else { + var content = contentFiles.map(function(file) { + return file.content; + }).join("\n"); + + self.logger.info("writing file " + this.buildDir + targetFile); + fs.writeFileSync(this.buildDir + targetFile, content); + } } };