mirror of https://github.com/embarklabs/embark.git
support directories in pipeline
This commit is contained in:
parent
eb7970a6f4
commit
4e026fb6e7
|
@ -24,12 +24,12 @@ Config.prototype.loadConfigFiles = function(options) {
|
||||||
this.embarkConfig = JSON.parse(fs.readFileSync(options.embarkConfig));
|
this.embarkConfig = JSON.parse(fs.readFileSync(options.embarkConfig));
|
||||||
this.embarkConfig.plugins = this.embarkConfig.plugins || {};
|
this.embarkConfig.plugins = this.embarkConfig.plugins || {};
|
||||||
|
|
||||||
this.loadPipelineConfigFile();
|
|
||||||
this.loadBlockchainConfigFile();
|
|
||||||
|
|
||||||
this.plugins = new Plugins({plugins: this.embarkConfig.plugins, logger: this.logger});
|
this.plugins = new Plugins({plugins: this.embarkConfig.plugins, logger: this.logger});
|
||||||
this.plugins.loadPlugins();
|
this.plugins.loadPlugins();
|
||||||
|
|
||||||
|
this.loadPipelineConfigFile();
|
||||||
|
this.loadBlockchainConfigFile();
|
||||||
|
|
||||||
this.loadContractsConfigFile();
|
this.loadContractsConfigFile();
|
||||||
this.loadChainTrackerFile();
|
this.loadChainTrackerFile();
|
||||||
this.loadPluginContractFiles();
|
this.loadPluginContractFiles();
|
||||||
|
@ -98,9 +98,11 @@ Config.prototype.loadChainTrackerFile = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadFiles = function(files) {
|
Config.prototype.loadFiles = function(files) {
|
||||||
|
var self = this;
|
||||||
var originalFiles = grunt.file.expand({nonull: true}, files);
|
var originalFiles = grunt.file.expand({nonull: true}, files);
|
||||||
var readFiles = [];
|
var readFiles = [];
|
||||||
|
|
||||||
|
// get embark.js object first
|
||||||
originalFiles.filter(function(file) {
|
originalFiles.filter(function(file) {
|
||||||
return file.indexOf('.') >= 0;
|
return file.indexOf('.') >= 0;
|
||||||
}).filter(function(file) {
|
}).filter(function(file) {
|
||||||
|
@ -111,12 +113,45 @@ Config.prototype.loadFiles = function(files) {
|
||||||
readFiles.push({filename: 'ipfs-api.js', content: fs.readFileSync(path.join(__dirname, "/../js/ipfs-api.min.js")).toString(), path: path.join(__dirname, "/../js/ipfs-api.min.js")});
|
readFiles.push({filename: 'ipfs-api.js', content: fs.readFileSync(path.join(__dirname, "/../js/ipfs-api.min.js")).toString(), path: path.join(__dirname, "/../js/ipfs-api.min.js")});
|
||||||
readFiles.push({filename: 'orbit.js', content: fs.readFileSync(path.join(__dirname, "/../js/orbit.min.js")).toString(), path: path.join(__dirname, "/../js/orbit.min.js")});
|
readFiles.push({filename: 'orbit.js', content: fs.readFileSync(path.join(__dirname, "/../js/orbit.min.js")).toString(), path: path.join(__dirname, "/../js/orbit.min.js")});
|
||||||
readFiles.push({filename: 'embark.js', content: fs.readFileSync(path.join(__dirname, "/../js/build/embark.bundle.js")).toString(), path: path.join(__dirname, "/../js/build/embark.bundle.js")});
|
readFiles.push({filename: 'embark.js', content: fs.readFileSync(path.join(__dirname, "/../js/build/embark.bundle.js")).toString(), path: path.join(__dirname, "/../js/build/embark.bundle.js")});
|
||||||
readFiles.push({filename: 'embark-plugins.js', content: "", path: ""});
|
|
||||||
} else {
|
|
||||||
readFiles.push({filename: file, content: fs.readFileSync(file).toString(), path: file});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// get plugins
|
||||||
|
var filesFromPlugins = [];
|
||||||
|
|
||||||
|
var filePlugins = self.plugins.getPluginsFor('pipelineFiles');
|
||||||
|
|
||||||
|
if (filePlugins.length > 0) {
|
||||||
|
filePlugins.forEach(function(plugin) {
|
||||||
|
try {
|
||||||
|
var fileObjects = plugin.runFilePipeline();
|
||||||
|
for (var i=0; i < fileObjects.length; i++) {
|
||||||
|
var fileObject = fileObjects[i];
|
||||||
|
filesFromPlugins.push(fileObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
self.logger.error(err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
filesFromPlugins.filter(function(file) {
|
||||||
|
if (grunt.file.isMatch(files, file.intendedPath)) {
|
||||||
|
readFiles.push(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// get user files
|
||||||
|
originalFiles.filter(function(file) {
|
||||||
|
return file.indexOf('.') >= 0;
|
||||||
|
}).filter(function(file) {
|
||||||
|
if (file === 'embark.js') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
readFiles.push({filename: file, content: fs.readFileSync(file).toString(), path: file});
|
||||||
|
});
|
||||||
|
|
||||||
return readFiles;
|
return readFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,50 +23,6 @@ Pipeline.prototype.build = function(abi) {
|
||||||
|
|
||||||
if (file.filename === 'embark.js') {
|
if (file.filename === 'embark.js') {
|
||||||
return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true};
|
return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true};
|
||||||
} else if (file.filename === 'embark-plugins.js') {
|
|
||||||
|
|
||||||
var filesFromPlugins = [];
|
|
||||||
|
|
||||||
var filePlugins = self.plugins.getPluginsFor('pipelineFiles');
|
|
||||||
|
|
||||||
if (filePlugins.length > 0) {
|
|
||||||
filePlugins.forEach(function(plugin) {
|
|
||||||
try {
|
|
||||||
var fileObjects = plugin.runFilePipeline();
|
|
||||||
for (var i=0; i < fileObjects.length; i++) {
|
|
||||||
var fileObject = fileObjects[i];
|
|
||||||
//console.debug(JSON.stringify(fileObject));
|
|
||||||
filesFromPlugins.push(fileObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
self.logger.error(err.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileContents = filesFromPlugins.map(function(file) {
|
|
||||||
if (pipelinePlugins.length > 0) {
|
|
||||||
pipelinePlugins.forEach(function(plugin) {
|
|
||||||
console.log(plugin.name + ": trying " + file.filename);
|
|
||||||
try {
|
|
||||||
if (file.options && file.options.skipPipeline) {
|
|
||||||
console.log("skipping");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
file.content = plugin.runPipeline({targetFile: file.filename, source: file.content, modified: true});
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
self.logger.error(err.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return file.content;
|
|
||||||
});
|
|
||||||
|
|
||||||
//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;
|
file.modified = true;
|
||||||
|
@ -76,6 +32,10 @@ Pipeline.prototype.build = function(abi) {
|
||||||
if (pipelinePlugins.length > 0) {
|
if (pipelinePlugins.length > 0) {
|
||||||
pipelinePlugins.forEach(function(plugin) {
|
pipelinePlugins.forEach(function(plugin) {
|
||||||
try {
|
try {
|
||||||
|
if (file.options && file.options.skipPipeline) {
|
||||||
|
console.log("skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
file.content = plugin.runPipeline({targetFile: file.filename, source: file.content});
|
file.content = plugin.runPipeline({targetFile: file.filename, source: file.content});
|
||||||
file.modified = true;
|
file.modified = true;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +67,7 @@ Pipeline.prototype.build = function(abi) {
|
||||||
filename = filename.replace(targetDir, '');
|
filename = filename.replace(targetDir, '');
|
||||||
self.logger.info("writing file " + self.buildDir + targetDir + filename);
|
self.logger.info("writing file " + self.buildDir + targetDir + filename);
|
||||||
|
|
||||||
fs.writeFileSync(self.buildDir + targetDir + filename, fs.readFileSync(file.filename));
|
fs.writeFileSync(self.buildDir + targetDir + filename, fs.readFileSync(file.path));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var content = contentFiles.map(function(file) {
|
var content = contentFiles.map(function(file) {
|
||||||
|
|
|
@ -77,8 +77,8 @@ Plugin.prototype.registerPipeline = function(matcthingFiles, cb) {
|
||||||
this.pluginTypes.push('pipeline');
|
this.pluginTypes.push('pipeline');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.addFileToPipeline = function(file, options) {
|
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
|
||||||
this.pipelineFiles.push({file: file, options: options});
|
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});
|
||||||
this.pluginTypes.push('pipelineFiles');
|
this.pluginTypes.push('pipelineFiles');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,7 +131,9 @@ Plugin.prototype.runFilePipeline = function() {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj.filename = file.file.replace('./','');
|
obj.filename = file.file.replace('./','');
|
||||||
obj.content = self.loadPluginFile(file.file).toString();
|
obj.content = self.loadPluginFile(file.file).toString();
|
||||||
|
obj.intendedPath = file.intendedPath;
|
||||||
obj.options = file.options;
|
obj.options = file.options;
|
||||||
|
obj.path = self.pathToFile(obj.filename);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
});
|
});
|
||||||
|
|
33
lib/test.js
33
lib/test.js
|
@ -10,17 +10,17 @@ var ABIGenerator = require('./abi.js');
|
||||||
// TODO: load config file
|
// TODO: load config file
|
||||||
// TODO: include plugins
|
// TODO: include plugins
|
||||||
var Test = function(options) {
|
var Test = function(options) {
|
||||||
try {
|
//try {
|
||||||
this.sim = require('ethereumjs-testrpc');
|
this.sim = require('ethereumjs-testrpc');
|
||||||
} catch(e) {
|
//} catch(e) {
|
||||||
this.sim = false;
|
// this.sim = false;
|
||||||
}
|
//}
|
||||||
|
|
||||||
if (this.sim === false) {
|
//if (this.sim === false) {
|
||||||
console.log('Simulator not found; Please install it with "npm install -g ethereumjs-testrpc');
|
// console.log('Simulator not found; Please install it with "npm install -g ethereumjs-testrpc');
|
||||||
console.log('For more information see https://github.com/ethereumjs/testrpc');
|
// console.log('For more information see https://github.com/ethereumjs/testrpc');
|
||||||
exit();
|
// exit();
|
||||||
}
|
//}
|
||||||
|
|
||||||
this.web3 = new Web3();
|
this.web3 = new Web3();
|
||||||
this.web3.setProvider(this.sim.provider(options));
|
this.web3.setProvider(this.sim.provider(options));
|
||||||
|
@ -31,15 +31,21 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||||
var logger = new TestLogger({logLevel: 'debug'});
|
var logger = new TestLogger({logLevel: 'debug'});
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
function getConfig(callback) {
|
||||||
|
var config = new Config({env: 'test', logger: logger});
|
||||||
|
config.loadConfigFiles({embarkConfig: 'embark.json'});
|
||||||
|
callback(null, config);
|
||||||
|
},
|
||||||
function buildContracts(callback) {
|
function buildContracts(callback) {
|
||||||
var config = new Config({env: 'test'});
|
//var config = new Config({env: 'test'});
|
||||||
config.contractsFiles = config.loadFiles(["app/contracts/**"]);
|
//config.contractsFiles = config.loadFiles(["app/contracts/**"]);
|
||||||
config.contractsConfig = {contracts: contractsConfig} ;
|
config.contractsConfig = {contracts: contractsConfig} ;
|
||||||
|
|
||||||
var contractsManager = new ContractsManager({
|
var contractsManager = new ContractsManager({
|
||||||
contractFiles: config.contractsFiles,
|
contractFiles: config.contractsFiles,
|
||||||
contractsConfig: config.contractsConfig,
|
contractsConfig: config.contractsConfig,
|
||||||
logger: logger
|
logger: logger,
|
||||||
|
plugins: config.plugins
|
||||||
});
|
});
|
||||||
contractsManager.build(callback);
|
contractsManager.build(callback);
|
||||||
},
|
},
|
||||||
|
@ -70,9 +76,10 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||||
}
|
}
|
||||||
var web3 = self.web3;
|
var web3 = self.web3;
|
||||||
web3.eth.defaultAccount = accounts[0];
|
web3.eth.defaultAccount = accounts[0];
|
||||||
|
console.log("hello!");
|
||||||
// TODO: replace evals with separate process so it's isolated and with
|
// TODO: replace evals with separate process so it's isolated and with
|
||||||
// a callback
|
// a callback
|
||||||
eval(result); // jshint ignore:line
|
//eval(result); // jshint ignore:line
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue