mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-22 12:08:14 +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
|
||||
var RunCode = require('./runCode.js');
|
||||
|
||||
const RunCode = require('./runCode.js');
|
||||
const EmbarkJS = require('embarkjs');
|
||||
class CodeRunner {
|
||||
constructor(options) {
|
||||
this.plugins = options.plugins;
|
||||
@ -26,6 +25,13 @@ class CodeRunner {
|
||||
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) => {
|
||||
|
@ -6,7 +6,11 @@ class RunCode {
|
||||
}
|
||||
|
||||
doEval(code) {
|
||||
return vm.runInNewContext(code, this.context);
|
||||
try {
|
||||
return vm.runInNewContext(code, this.context);
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
registerVar(varName, code) {
|
||||
|
@ -99,6 +99,10 @@ class CodeGenerator {
|
||||
self.buildPlaceholderPage(cb);
|
||||
});
|
||||
|
||||
self.events.setCommandHandler('code-generator:embarkjs:initialization-code', (cb) => {
|
||||
console.log("command")
|
||||
cb(self.getEmbarkJsInitializationCode());
|
||||
});
|
||||
}
|
||||
|
||||
generateContext() {
|
||||
@ -117,7 +121,7 @@ class CodeGenerator {
|
||||
result += Templates.main_context();
|
||||
result += Templates.load_manager();
|
||||
result += Templates.define_when_env_loaded();
|
||||
|
||||
|
||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||
return result;
|
||||
}
|
||||
@ -216,7 +220,6 @@ class CodeGenerator {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
generateStorageInitialization(useEmbarkJS) {
|
||||
if (!useEmbarkJS || this.storageConfig === {}) return "";
|
||||
|
||||
@ -313,6 +316,8 @@ class CodeGenerator {
|
||||
web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes
|
||||
code += "\nimport Web3 from '" + web3Location + "';\n";
|
||||
code += "\nimport web3 from 'Embark/web3';\n";
|
||||
code += "\nimport IpfsApi from 'ipfs-api';\n";
|
||||
|
||||
next();
|
||||
},
|
||||
function getJSCode(next) {
|
||||
@ -325,6 +330,7 @@ class CodeGenerator {
|
||||
code += self.generateCommunicationInitialization(true);
|
||||
code += self.generateStorageInitialization(true);
|
||||
code += self.generateNamesInitialization(true);
|
||||
|
||||
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) {
|
||||
let contractCode = "";
|
||||
contractCode += "import web3 from 'Embark/web3';\n";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import IpfsApi from 'ipfs-api';
|
||||
/*global IpfsApi*/
|
||||
|
||||
let __embarkIPFS = {};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user