initial work to write pipeline files through an api

This commit is contained in:
Iuri Matias 2019-07-10 18:23:58 -04:00
parent 15c2381f26
commit a71a815035
2 changed files with 72 additions and 19 deletions

View File

@ -48,19 +48,46 @@ class Pipeline {
this.api = new PipelineAPI(embark, options); this.api = new PipelineAPI(embark, options);
this.api.registerAPIs(); this.api.registerAPIs();
this.files = {}
this.events.setCommandHandler('pipeline:register', (params) => {
this.files[dappPath(...params.path, params.file)] = params;
});
} }
generateAll(cb) { generateAll(cb) {
console.dir("generating all files"); console.dir("generating all files");
// TODO:
// placeholder: not actually needed?? it seems to be done on the server // TODO: make this async
// * create placeholder for (let fileParams of Object.values(this.files)) {
// * check registered code and generate files if (fileParams.format === 'json') {
// * remove placeholder this.writeJSONFile(fileParams)
// * placeholder can be a plugin as well or different module } else {
// TODO: other/js
}
}
cb(); cb();
} }
writeJSONFile(params) {
const self = this;
const dir = dappPath(...params.path);
const filename = dappPath(...params.path, params.file);
const content = params.content;
async.waterfall([
function makeDirectory(next) {
self.fs.mkdirp(dir, err => next(err));
},
function writeContractsJSON(next) {
self.fs.writeJson(filename, content, { spaces: 2 }, () => { next() });
}
], () => {
});
}
build({modifiedAssets}, callback) { build({modifiedAssets}, callback) {
let self = this; let self = this;
const importsList = {}; const importsList = {};
@ -72,6 +99,7 @@ class Pipeline {
} }
async.waterfall([ async.waterfall([
// TODO: doesn't seem to be actually used (it's done on the webserver itself)
function createPlaceholderPage(next) { function createPlaceholderPage(next) {
if (self.isFirstBuild) { if (self.isFirstBuild) {
self.isFirstBuild = false; self.isFirstBuild = false;

View File

@ -8,16 +8,21 @@ const Templates = {
class Web3Plugin { class Web3Plugin {
constructor(embark, options) { constructor(embark, options) {
this.embarkConfig = embark.config.embarkConfig;
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.plugins = options.plugins; this.plugins = options.plugins;
let plugin = this.plugins.createPlugin('web3plugin', {}); let plugin = this.plugins.createPlugin('web3plugin', {});
plugin.registerActionForEvent("deploy:contract:deployed", (params, cb) => { plugin.registerActionForEvent("deploy:contract:deployed", this.registerInVm.bind(this));
plugin.registerActionForEvent("deploy:contract:deployed", this.addToPipeline.bind(this));
}
registerInVm(params, cb) {
let contract = params.contract; let contract = params.contract;
let abi = JSON.stringify(contract.abiDefinition); let abi = JSON.stringify(contract.abiDefinition);
let gasLimit = 6000000; let gasLimit = 6000000;
let contractCode = Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: gasLimit}); let contractCode = Templates.vanilla_contract({ className: contract.className, abi: abi, contract: contract, gasLimit: gasLimit });
this.events.request('runcode:eval', contractCode, (err) => { this.events.request('runcode:eval', contractCode, (err) => {
if (err) { if (err) {
@ -30,7 +35,27 @@ class Web3Plugin {
this.events.emit("runcode:register", contract.className, result, () => { cb() }); this.events.emit("runcode:register", contract.className, result, () => { cb() });
}); });
}); });
}) }
addToPipeline(params, cb) {
// TODO: check if this is correct json object to generate
let contract = params.contract;
this.events.request("pipeline:register", {
path: [this.embarkConfig.buildDir, 'contracts'],
file: contract.className + '.json',
format: 'json',
content: contract
});
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'contracts'],
file: contract.className + '.js',
format: 'js',
content: contract
});
cb();
} }
} }