if target is directory then copy files

This commit is contained in:
Iuri Matias 2017-01-29 00:58:06 -05:00
parent 61f8f4159e
commit 0ec3fba352
1 changed files with 36 additions and 10 deletions

View File

@ -16,13 +16,13 @@ Pipeline.prototype.build = function(abi) {
// TODO: run the plugin here instead, for each file // 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); self.logger.info("reading " + file.filename);
var pipelinePlugins = this.plugins.getPluginsFor('pipeline'); var pipelinePlugins = this.plugins.getPluginsFor('pipeline');
if (file.filename === 'embark.js') { 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') { } else if (file.filename === 'embark-plugins.js') {
var filesFromPlugins = []; var filesFromPlugins = [];
@ -35,7 +35,7 @@ Pipeline.prototype.build = function(abi) {
var fileObjects = plugin.runFilePipeline(); var fileObjects = plugin.runFilePipeline();
for (var i=0; i < fileObjects.length; i++) { for (var i=0; i < fileObjects.length; i++) {
var fileObject = fileObjects[i]; var fileObject = fileObjects[i];
console.debug(JSON.stringify(fileObject)); //console.debug(JSON.stringify(fileObject));
filesFromPlugins.push(fileObject); filesFromPlugins.push(fileObject);
} }
} }
@ -54,7 +54,7 @@ Pipeline.prototype.build = function(abi) {
console.log("skipping"); console.log("skipping");
return; 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) { catch(err) {
self.logger.error(err.message); self.logger.error(err.message);
@ -64,16 +64,20 @@ Pipeline.prototype.build = function(abi) {
return file.content; 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) { } 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 { } else {
if (pipelinePlugins.length > 0) { if (pipelinePlugins.length > 0) {
pipelinePlugins.forEach(function(plugin) { pipelinePlugins.forEach(function(plugin) {
try { try {
file.content = plugin.runPipeline({targetFile: file.filename, source: file.content}); file.content = plugin.runPipeline({targetFile: file.filename, source: file.content});
file.modified = true;
} }
catch(err) { catch(err) {
self.logger.error(err.message); 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('/'); var dir = targetFile.split('/').slice(0, -1).join('/');
self.logger.info("creating dir " + this.buildDir + dir); self.logger.info("creating dir " + this.buildDir + dir);
mkdirp.sync(this.buildDir + dir); mkdirp.sync(this.buildDir + dir);
self.logger.info("writing file " + this.buildDir + targetFile); // if it's a directory
fs.writeFileSync(this.buildDir + targetFile, content); 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);
}
} }
}; };