mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-22 10:28:34 +00:00
remove path events and use function directly
also use await
This commit is contained in:
parent
b49acee143
commit
d7da38f6c4
@ -69,6 +69,7 @@ var Config = function(options) {
|
||||
});
|
||||
};
|
||||
|
||||
// TODO remove this at some point as it is now in plugin
|
||||
Config.prototype.dappPath = fs.dappPath;
|
||||
|
||||
Config.prototype.loadConfigFiles = function(options) {
|
||||
|
@ -2,7 +2,6 @@ const async = require('async');
|
||||
|
||||
const utils = require('../utils/utils');
|
||||
const IPC = require('./ipc');
|
||||
const fs = require('./fs');
|
||||
|
||||
class Engine {
|
||||
constructor(options) {
|
||||
@ -31,7 +30,6 @@ class Engine {
|
||||
|
||||
let options = _options || {};
|
||||
this.events = options.events || this.events || new Events();
|
||||
this.registerCommands();
|
||||
this.logger = options.logger || new Logger({context: this.context, logLevel: options.logLevel || this.logLevel || 'debug', events: this.events, logFile: this.logFile});
|
||||
this.config = new Config({env: this.env, logger: this.logger, events: this.events, context: this.context, webServerConfig: this.webServerConfig, version: this.version});
|
||||
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
||||
@ -55,19 +53,6 @@ class Engine {
|
||||
callback();
|
||||
}
|
||||
|
||||
registerCommands() {
|
||||
this.events.setCommandHandler('embark:path', function () {
|
||||
const cb = arguments[arguments.length - 1];
|
||||
const pathParts = Array.from(arguments).splice(0, arguments.length - 1);
|
||||
cb(fs.embarkPath(...pathParts));
|
||||
});
|
||||
this.events.setCommandHandler('dapp:path', function () {
|
||||
const cb = arguments[arguments.length - 1];
|
||||
const pathParts = Array.from(arguments).splice(0, arguments.length - 1);
|
||||
cb(fs.dappPath(...pathParts));
|
||||
});
|
||||
}
|
||||
|
||||
registerModule(moduleName, options) {
|
||||
this.plugins.loadInternalPlugin(moduleName, options || {});
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
const utils = require('../utils/utils.js');
|
||||
const constants = require('../constants');
|
||||
const fs = require('./fs.js');
|
||||
|
||||
// TODO: pass other params like blockchainConfig, contract files, etc..
|
||||
var Plugin = function(options) {
|
||||
@ -52,6 +53,9 @@ var Plugin = function(options) {
|
||||
}
|
||||
};
|
||||
|
||||
Plugin.prototype.dappPath = fs.dappPath;
|
||||
Plugin.prototype.embarkPath = fs.embarkPath;
|
||||
|
||||
Plugin.prototype._log = function(type) {
|
||||
this._loggerObject[type](this.name + ':', ...[].slice.call(arguments, 1));
|
||||
};
|
||||
|
@ -1,54 +1,68 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = (embark) => {
|
||||
embark.events.on('runcode:ready', () => {
|
||||
const pathPromise = new Promise((resolve, reject) => {
|
||||
embark.events.request("version:get:web3", (web3Version) => {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
return embark.events.request('embark:path', 'node_modules', (result) => {
|
||||
const web3Path = require.resolve("web3", {paths: [result]});
|
||||
resolve(web3Path);
|
||||
});
|
||||
function whenRuncodeReady(embark) {
|
||||
return new Promise((resolve) => {
|
||||
embark.events.on('runcode:ready', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getWeb3Location(embark) {
|
||||
return new Promise((resolve, reject) => {
|
||||
embark.events.request("version:get:web3", (web3Version) => {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
const nodePath = embark.embarkPath('node_modules');
|
||||
const web3Path = require.resolve("web3", {paths: [nodePath]});
|
||||
return resolve(web3Path);
|
||||
}
|
||||
embark.events.request("version:getPackageLocation", "web3", web3Version, (err, location) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
embark.events.request("version:getPackageLocation", "web3", web3Version, (err, location) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
embark.events.request('dapp:path', location, resolve);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
pathPromise.then((web3Location) => {
|
||||
web3Location = web3Location.replace(/\\/g, '/');
|
||||
embark.events.emit('runcode:register', 'Web3', require(web3Location), false);
|
||||
|
||||
let code = `\nconst Web3 = global.Web3 || require('${web3Location}');`;
|
||||
code += `\nglobal.Web3 = Web3;`;
|
||||
|
||||
const connectorCode = fs.readFileSync(path.join(__dirname, 'web3Connector.js'), 'utf8');
|
||||
code += connectorCode;
|
||||
|
||||
code += "\nEmbarkJS.Blockchain.registerProvider('web3', web3Connector);";
|
||||
|
||||
code += "\nEmbarkJS.Blockchain.setProvider('web3', {});";
|
||||
|
||||
embark.addCodeToEmbarkJS(code);
|
||||
|
||||
code = "EmbarkJS.Blockchain.setProvider('web3', {});";
|
||||
|
||||
const shouldInit = (_config) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
embark.addConsoleProviderInit('blockchain', code, shouldInit);
|
||||
});
|
||||
|
||||
embark.events.setCommandHandler('blockchain:connector:ready', (cb) => {
|
||||
pathPromise.then((_web3Location) => {
|
||||
cb();
|
||||
const locationPath = embark.embarkPath(location);
|
||||
resolve(locationPath);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = async (embark) => {
|
||||
await whenRuncodeReady(embark);
|
||||
|
||||
const web3LocationPromise = getWeb3Location(embark);
|
||||
|
||||
embark.events.setCommandHandler('blockchain:connector:ready', (cb) => {
|
||||
web3LocationPromise.then((_web3Location) => {
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
||||
let web3Location = await web3LocationPromise;
|
||||
|
||||
web3Location = web3Location.replace(/\\/g, '/');
|
||||
|
||||
|
||||
embark.events.emit('runcode:register', 'Web3', require(web3Location), false);
|
||||
|
||||
let code = `\nconst Web3 = global.Web3 || require('${web3Location}');`;
|
||||
code += `\nglobal.Web3 = Web3;`;
|
||||
|
||||
const connectorCode = fs.readFileSync(path.join(__dirname, 'web3Connector.js'), 'utf8');
|
||||
code += connectorCode;
|
||||
|
||||
code += "\nEmbarkJS.Blockchain.registerProvider('web3', web3Connector);";
|
||||
|
||||
code += "\nEmbarkJS.Blockchain.setProvider('web3', {});";
|
||||
|
||||
embark.addCodeToEmbarkJS(code);
|
||||
|
||||
code = "EmbarkJS.Blockchain.setProvider('web3', {});";
|
||||
|
||||
const shouldInit = (_config) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
embark.addConsoleProviderInit('blockchain', code, shouldInit);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user