mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-23 04:28:19 +00:00
Add embarkjs to console
This commit is contained in:
parent
bd49e3672c
commit
d772b4fdaf
@ -1,6 +1,5 @@
|
|||||||
// still needs to be run on a separate file due to the global context
|
const RunCode = require('./runCode.js');
|
||||||
var RunCode = require('./runCode.js');
|
const EmbarkJS = require('embarkjs');
|
||||||
|
|
||||||
class CodeRunner {
|
class CodeRunner {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
@ -26,6 +25,13 @@ class CodeRunner {
|
|||||||
self.events.request("runcode:eval", command.code);
|
self.events.request("runcode:eval", command.code);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.runCode.registerVar('EmbarkJS', EmbarkJS);
|
||||||
|
this.events.on('code-generator-ready', () => {
|
||||||
|
this.events.request('code-generator:embarkjs:initialization-code', (code) => {
|
||||||
|
this.runCode.doEval(code);
|
||||||
|
});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.events.on("runcode:register", (varName, code) => {
|
this.events.on("runcode:register", (varName, code) => {
|
||||||
|
@ -6,7 +6,11 @@ class RunCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doEval(code) {
|
doEval(code) {
|
||||||
return vm.runInNewContext(code, this.context);
|
try {
|
||||||
|
return vm.runInNewContext(code, this.context);
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerVar(varName, code) {
|
registerVar(varName, code) {
|
||||||
|
@ -99,6 +99,10 @@ class CodeGenerator {
|
|||||||
self.buildPlaceholderPage(cb);
|
self.buildPlaceholderPage(cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.events.setCommandHandler('code-generator:embarkjs:initialization-code', (cb) => {
|
||||||
|
console.log("command")
|
||||||
|
cb(self.getEmbarkJsInitializationCode());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generateContext() {
|
generateContext() {
|
||||||
@ -216,7 +220,6 @@ class CodeGenerator {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
generateStorageInitialization(useEmbarkJS) {
|
generateStorageInitialization(useEmbarkJS) {
|
||||||
if (!useEmbarkJS || this.storageConfig === {}) return "";
|
if (!useEmbarkJS || this.storageConfig === {}) return "";
|
||||||
|
|
||||||
@ -313,6 +316,8 @@ class CodeGenerator {
|
|||||||
web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes
|
web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes
|
||||||
code += "\nimport Web3 from '" + web3Location + "';\n";
|
code += "\nimport Web3 from '" + web3Location + "';\n";
|
||||||
code += "\nimport web3 from 'Embark/web3';\n";
|
code += "\nimport web3 from 'Embark/web3';\n";
|
||||||
|
code += "\nimport IpfsApi from 'ipfs-api';\n";
|
||||||
|
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
function getJSCode(next) {
|
function getJSCode(next) {
|
||||||
@ -325,6 +330,7 @@ class CodeGenerator {
|
|||||||
code += self.generateCommunicationInitialization(true);
|
code += self.generateCommunicationInitialization(true);
|
||||||
code += self.generateStorageInitialization(true);
|
code += self.generateStorageInitialization(true);
|
||||||
code += self.generateNamesInitialization(true);
|
code += self.generateNamesInitialization(true);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
function writeFile(next) {
|
function writeFile(next) {
|
||||||
@ -337,6 +343,27 @@ class CodeGenerator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getEmbarkJsInitializationCode() {
|
||||||
|
let code = '';
|
||||||
|
let embarkjsCodes = this.plugins.getPluginsFor('embarkjsCode');
|
||||||
|
for (let plugin of embarkjsCodes) {
|
||||||
|
code += plugin.embarkjs_code.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
let initCodes = this.plugins.getPluginsFor('initCode');
|
||||||
|
for (let plugin of initCodes) {
|
||||||
|
let initCodes = plugin.embarkjs_init_code['communication'] || [];
|
||||||
|
for (let initCode of initCodes) {
|
||||||
|
let [block, shouldInit] = initCode;
|
||||||
|
if (shouldInit.call(plugin, this.communicationConfig)) {
|
||||||
|
code += block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
buildContractJS(contractName, contractJSON, cb) {
|
buildContractJS(contractName, contractJSON, cb) {
|
||||||
let contractCode = "";
|
let contractCode = "";
|
||||||
contractCode += "import web3 from 'Embark/web3';\n";
|
contractCode += "import web3 from 'Embark/web3';\n";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import IpfsApi from 'ipfs-api';
|
/*global IpfsApi*/
|
||||||
|
|
||||||
let __embarkIPFS = {};
|
let __embarkIPFS = {};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user