mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-27 12:50: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.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;
|
||||
|
@ -8,29 +8,54 @@ 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) => {
|
||||
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});
|
||||
plugin.registerActionForEvent("deploy:contract:deployed", this.registerInVm.bind(this));
|
||||
plugin.registerActionForEvent("deploy:contract:deployed", this.addToPipeline.bind(this));
|
||||
}
|
||||
|
||||
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) {
|
||||
return cb(err);
|
||||
}
|
||||
this.events.request('runcode:eval', contract.className, (err, result) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user