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.registerAPIs();
this.files = {}
this.events.setCommandHandler('pipeline:register', (params) => {
this.files[dappPath(...params.path, params.file)] = params;
});
}
generateAll(cb) {
console.dir("generating all files");
// TODO:
// placeholder: not actually needed?? it seems to be done on the server
// * create placeholder
// * check registered code and generate files
// * remove placeholder
// * placeholder can be a plugin as well or different module
// TODO: make this async
for (let fileParams of Object.values(this.files)) {
if (fileParams.format === 'json') {
this.writeJSONFile(fileParams)
} else {
// TODO: other/js
}
}
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) {
let self = this;
const importsList = {};
@ -72,6 +99,7 @@ class Pipeline {
}
async.waterfall([
// TODO: doesn't seem to be actually used (it's done on the webserver itself)
function createPlaceholderPage(next) {
if (self.isFirstBuild) {
self.isFirstBuild = false;

View File

@ -8,12 +8,17 @@ const Templates = {
class Web3Plugin {
constructor(embark, options) {
this.embarkConfig = embark.config.embarkConfig;
this.logger = embark.logger;
this.events = embark.events;
this.plugins = options.plugins;
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 abi = JSON.stringify(contract.abiDefinition);
let gasLimit = 6000000;
@ -30,7 +35,27 @@ class Web3Plugin {
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();
}
}