mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-28 05:10:43 +00:00
initial work to write pipeline files through an api
This commit is contained in:
parent
15c2381f26
commit
a71a815035
@ -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;
|
||||||
|
@ -8,29 +8,54 @@ 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));
|
||||||
let contract = params.contract;
|
plugin.registerActionForEvent("deploy:contract:deployed", this.addToPipeline.bind(this));
|
||||||
let abi = JSON.stringify(contract.abiDefinition);
|
}
|
||||||
let gasLimit = 6000000;
|
|
||||||
let contractCode = Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: gasLimit});
|
|
||||||
|
|
||||||
this.events.request('runcode:eval', contractCode, (err) => {
|
registerInVm(params, cb) {
|
||||||
|
let contract = params.contract;
|
||||||
|
let abi = JSON.stringify(contract.abiDefinition);
|
||||||
|
let gasLimit = 6000000;
|
||||||
|
let contractCode = Templates.vanilla_contract({ className: contract.className, abi: abi, contract: contract, gasLimit: gasLimit });
|
||||||
|
|
||||||
|
this.events.request('runcode:eval', contractCode, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
this.events.request('runcode:eval', contract.className, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
this.events.request('runcode:eval', contract.className, (err, result) => {
|
this.events.emit("runcode:register", contract.className, result, () => { cb() });
|
||||||
if (err) {
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user