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
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,17 +85,39 @@ 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);
// 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);
}
}
};
module.exports = Pipeline;