revert some of the recent changes
This commit is contained in:
parent
f5cfcae3dd
commit
faf0e1ff48
|
@ -1,21 +1,12 @@
|
||||||
let colors = require('colors');
|
var colors = require('colors');
|
||||||
let shelljs = require('shelljs');
|
var shelljs = require('shelljs');
|
||||||
|
|
||||||
let fs = require('../../core/fs.js');
|
var fs = require('../../core/fs.js');
|
||||||
|
|
||||||
let GethCommands = require('./geth_commands.js');
|
var GethCommands = require('./geth_commands.js');
|
||||||
|
|
||||||
let BlockchainClient = function(blockchainConfig, client, env) {
|
|
||||||
if (client === 'geth') {
|
|
||||||
return new Blockchain({blockchainConfig: blockchainConfig, client: new GethCommands(), env: env});
|
|
||||||
} else {
|
|
||||||
throw new Error('unknown client');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*eslint complexity: ["error", 22]*/
|
/*eslint complexity: ["error", 22]*/
|
||||||
class Blockchain {
|
var Blockchain = function(options) {
|
||||||
constructor(options) {
|
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
this.env = options.env || 'development';
|
this.env = options.env || 'development';
|
||||||
this.client = options.client;
|
this.client = options.client;
|
||||||
|
@ -40,28 +31,30 @@ class Blockchain {
|
||||||
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']),
|
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']),
|
||||||
vmdebug: this.blockchainConfig.vmdebug || false
|
vmdebug: this.blockchainConfig.vmdebug || false
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
runCommand(cmd) {
|
this.client = new options.client({config: this.config, env: this.env});
|
||||||
|
};
|
||||||
|
|
||||||
|
Blockchain.prototype.runCommand = function(cmd) {
|
||||||
console.log(("running: " + cmd.underline).green);
|
console.log(("running: " + cmd.underline).green);
|
||||||
return shelljs.exec(cmd);
|
return shelljs.exec(cmd);
|
||||||
}
|
};
|
||||||
|
|
||||||
run () {
|
Blockchain.prototype.run = function() {
|
||||||
let self = this;
|
var self = this;
|
||||||
console.log("===============================================================================".magenta);
|
console.log("===============================================================================".magenta);
|
||||||
console.log("===============================================================================".magenta);
|
console.log("===============================================================================".magenta);
|
||||||
console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta);
|
console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta);
|
||||||
console.log("===============================================================================".magenta);
|
console.log("===============================================================================".magenta);
|
||||||
console.log("===============================================================================".magenta);
|
console.log("===============================================================================".magenta);
|
||||||
let address = this.initChainAndGetAddress();
|
var address = this.initChainAndGetAddress();
|
||||||
this.client.mainCommand(address, function(cmd) {
|
this.client.mainCommand(address, function(cmd) {
|
||||||
shelljs.exec(cmd, {async : true});
|
self.runCommand(cmd);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
initChainAndGetAddress() {
|
Blockchain.prototype.initChainAndGetAddress = function() {
|
||||||
let address = null, result;
|
var address = null, result;
|
||||||
|
|
||||||
// ensure datadir exists, bypassing the interactive liabilities prompt.
|
// ensure datadir exists, bypassing the interactive liabilities prompt.
|
||||||
this.datadir = '.embark/' + this.env + '/datadir';
|
this.datadir = '.embark/' + this.env + '/datadir';
|
||||||
|
@ -87,8 +80,15 @@ class Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
|
};
|
||||||
|
|
||||||
|
var BlockchainClient = function(blockchainConfig, client, env) {
|
||||||
|
if (client === 'geth') {
|
||||||
|
return new Blockchain({blockchainConfig: blockchainConfig, client: GethCommands, env: env});
|
||||||
|
} else {
|
||||||
|
throw new Error('unknown client');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = BlockchainClient;
|
module.exports = BlockchainClient;
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
let async = require('async');
|
let async = require('async');
|
||||||
let Deploy = require('./deploy.js');
|
let Deploy = require('./deploy.js');
|
||||||
let ContractsManager = require('./contracts.js');
|
let ContractsManager = require('./contracts.js');
|
||||||
let EventEmitter = require('events');
|
|
||||||
|
|
||||||
class DeployManager {
|
class DeployManager {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.blockchainConfig = this.config.blockchainConfig;
|
this.blockchainConfig = this.config.blockchainConfig;
|
||||||
|
this.events = options.events;
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
this.web3 = options.web3;
|
this.web3 = options.web3;
|
||||||
this.chainConfig = (options.trackContracts !== false) ? this.config.chainTracker : false;
|
this.chainConfig = (options.trackContracts !== false) ? this.config.chainTracker : false;
|
||||||
Object.create(EventEmitter.prototype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deployContracts(done) {
|
deployContracts(done) {
|
||||||
|
@ -19,7 +18,7 @@ class DeployManager {
|
||||||
|
|
||||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
self.logger.info("Blockchain component is disabled in the config".underline);
|
self.logger.info("Blockchain component is disabled in the config".underline);
|
||||||
this.emit('blockchainDisabled', {});
|
this.events.emit('blockchainDisabled', {});
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ class DeployManager {
|
||||||
env: self.config.env
|
env: self.config.env
|
||||||
});
|
});
|
||||||
deploy.deployAll(function () {
|
deploy.deployAll(function () {
|
||||||
self.emit('contractsDeployed', contractsManager);
|
self.events.emit('contractsDeployed', contractsManager);
|
||||||
callback(null, contractsManager);
|
callback(null, contractsManager);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ Config.prototype.loadContractsConfigFile = function () {
|
||||||
|
|
||||||
let configObject = {};
|
let configObject = {};
|
||||||
let configPlugins = [];
|
let configPlugins = [];
|
||||||
this.plugins.emit('get', 'contractsConfig', (kinds) => {
|
this.events.emit('get', 'contractsConfig', (kinds) => {
|
||||||
configPlugins = kinds;
|
configPlugins = kinds;
|
||||||
});
|
});
|
||||||
if (configPlugins.length > 0) {
|
if (configPlugins.length > 0) {
|
||||||
|
|
|
@ -10,14 +10,13 @@ let ServicesMonitor = require('./services_monitor.js');
|
||||||
let Pipeline = require('../pipeline/pipeline.js');
|
let Pipeline = require('../pipeline/pipeline.js');
|
||||||
let Server = require('../pipeline/server.js');
|
let Server = require('../pipeline/server.js');
|
||||||
let Watch = require('../pipeline/watch.js');
|
let Watch = require('../pipeline/watch.js');
|
||||||
let version = require('../../package.json');
|
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
this.embarkConfig = options.embarkConfig;
|
this.embarkConfig = options.embarkConfig;
|
||||||
this.interceptLogs = options.interceptLogs;
|
this.interceptLogs = options.interceptLogs;
|
||||||
this.version = version;
|
this.version = options.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_options) {
|
init(_options) {
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
//TODO: This is deprecated because Embark extends EventEmitter now
|
var EventEmitter = require('events');
|
||||||
let events = require('events');
|
|
||||||
|
|
||||||
class EventEmitter {
|
|
||||||
constructor(options) {
|
|
||||||
this.options = options;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EventEmitter.prototype = Object.create(events.EventEmitter.prototype);
|
|
||||||
|
|
||||||
module.exports = EventEmitter;
|
module.exports = EventEmitter;
|
||||||
|
|
|
@ -1,24 +1,14 @@
|
||||||
/*jshint esversion: 6, loopfunc: true */
|
/*jshint esversion: 6, loopfunc: true */
|
||||||
let fs = require('./fs.js');
|
var fs = require('./fs.js');
|
||||||
let utils = require('../utils/utils.js');
|
var utils = require('../utils/utils.js');
|
||||||
let camelcase = require("underscore.string").camelcase;
|
|
||||||
|
|
||||||
class Plugin {
|
|
||||||
constructor(options) {
|
|
||||||
this.config = {};
|
|
||||||
for (let opt in options) {
|
|
||||||
if (options.hasOwnProperty(opt)) {
|
|
||||||
this.config[opt] = options[opt];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let requiredOptions = ['name', 'pluginModule', 'pluginPath', 'config', 'interceptLogs', 'logger'];
|
|
||||||
|
|
||||||
for (let i = 0; requiredOptions.length > i; i++) {
|
|
||||||
if (!(utils.contains(Object.keys(this.config), requiredOptions[i]))) {
|
|
||||||
throw new Error('Missing required plugin configuration key: ' + requiredOptions[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// TODO: pass other params like blockchainConfig, contract files, etc..
|
||||||
|
var Plugin = function(options) {
|
||||||
|
this.name = options.name;
|
||||||
|
this.pluginModule = options.pluginModule;
|
||||||
|
this.pluginPath = options.pluginPath;
|
||||||
|
this.pluginConfig = options.pluginConfig;
|
||||||
|
this.shouldInterceptLogs = options.interceptLogs;
|
||||||
this.clientWeb3Providers = [];
|
this.clientWeb3Providers = [];
|
||||||
this.contractsGenerators = [];
|
this.contractsGenerators = [];
|
||||||
this.pipeline = [];
|
this.pipeline = [];
|
||||||
|
@ -29,19 +19,16 @@ class Plugin {
|
||||||
this.compilers = [];
|
this.compilers = [];
|
||||||
this.serviceChecks = [];
|
this.serviceChecks = [];
|
||||||
this.pluginTypes = [];
|
this.pluginTypes = [];
|
||||||
|
this.logger = options.logger;
|
||||||
|
this.events = options.events;
|
||||||
|
this.config = options.config;
|
||||||
|
};
|
||||||
|
|
||||||
if (!(this instanceof Plugin)) {
|
Plugin.prototype.loadPlugin = function() {
|
||||||
return new Plugin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugin.prototype.runPlugin = Plugin.prototype.run = function () {
|
|
||||||
if (this.shouldInterceptLogs) {
|
if (this.shouldInterceptLogs) {
|
||||||
this.interceptLogs(this.pluginModule);
|
this.interceptLogs(this.pluginModule);
|
||||||
}
|
}
|
||||||
let fullyQualifiedPath = this.pathToFile(this.config.pluginModule);
|
(this.pluginModule.call(this, this));
|
||||||
this.call(this.loadPluginFile(fullyQualifiedPath), this);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.loadPluginFile = function(filename) {
|
Plugin.prototype.loadPluginFile = function(filename) {
|
||||||
|
@ -53,7 +40,7 @@ Plugin.prototype.pathToFile = function (filename) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.interceptLogs = function(context) {
|
Plugin.prototype.interceptLogs = function(context) {
|
||||||
let self = this;
|
var self = this;
|
||||||
// TODO: this is a bit nasty, figure out a better way
|
// TODO: this is a bit nasty, figure out a better way
|
||||||
context.console = context.console || console;
|
context.console = context.console || console;
|
||||||
|
|
||||||
|
@ -80,19 +67,6 @@ Plugin.prototype.interceptLogs = function (context) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.register = function (classname, cb) {
|
|
||||||
let camelCasedClassname = camelcase(classname);
|
|
||||||
this[camelCasedClassname].push(cb);
|
|
||||||
this.pluginTypes.push({class: classname, call: cb});
|
|
||||||
};
|
|
||||||
|
|
||||||
["ClientWeb3Provider", "ContractsGeneration", "Pipeline", "Deployer",
|
|
||||||
"ConsoleCommand", "ServiceCheck", "ContractConfiguration", "Compiler"].forEach(function (name) {
|
|
||||||
Plugin.prototype["register" + name] = function (cb) {
|
|
||||||
Plugin.prototype.register.call(name, cb);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: add deploy provider
|
// TODO: add deploy provider
|
||||||
Plugin.prototype.registerClientWeb3Provider = function(cb) {
|
Plugin.prototype.registerClientWeb3Provider = function(cb) {
|
||||||
this.clientWeb3Providers.push(cb);
|
this.clientWeb3Providers.push(cb);
|
||||||
|
@ -163,10 +137,10 @@ Plugin.prototype.runCommands = function (cmd, options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.runFilePipeline = function() {
|
Plugin.prototype.runFilePipeline = function() {
|
||||||
let self = this;
|
var self = this;
|
||||||
|
|
||||||
return this.pipelineFiles.map(function(file) {
|
return this.pipelineFiles.map(function(file) {
|
||||||
let obj = {};
|
var obj = {};
|
||||||
obj.filename = file.file.replace('./','');
|
obj.filename = file.file.replace('./','');
|
||||||
obj.content = self.loadPluginFile(file.file).toString();
|
obj.content = self.loadPluginFile(file.file).toString();
|
||||||
obj.intendedPath = file.intendedPath;
|
obj.intendedPath = file.intendedPath;
|
||||||
|
@ -179,8 +153,8 @@ Plugin.prototype.runFilePipeline = function () {
|
||||||
|
|
||||||
Plugin.prototype.runPipeline = function(args) {
|
Plugin.prototype.runPipeline = function(args) {
|
||||||
// TODO: should iterate the pipelines
|
// TODO: should iterate the pipelines
|
||||||
let pipeline = this.pipeline[0];
|
var pipeline = this.pipeline[0];
|
||||||
let shouldRunPipeline = utils.fileMatchesPattern(pipeline.matcthingFiles, args.targetFile);
|
var shouldRunPipeline = utils.fileMatchesPattern(pipeline.matcthingFiles, args.targetFile);
|
||||||
if (shouldRunPipeline) {
|
if (shouldRunPipeline) {
|
||||||
return pipeline.cb.call(this, args);
|
return pipeline.cb.call(this, args);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,60 +1,45 @@
|
||||||
const _ = require('underscore');
|
var Plugin = require('./plugin.js');
|
||||||
const EventEmitter = require('events').EventEmitter;
|
var utils = require('../utils/utils.js');
|
||||||
|
|
||||||
const getPluginsFor = function (pluginType, plugins) {
|
var Plugins = function(options) {
|
||||||
return _.filter(plugins, pluginType);
|
this.pluginList = options.plugins || [];
|
||||||
|
this.interceptLogs = options.interceptLogs;
|
||||||
|
this.plugins = [];
|
||||||
|
// TODO: need backup 'NullLogger'
|
||||||
|
this.logger = options.logger;
|
||||||
|
this.events = options.events;
|
||||||
|
this.config = options.config;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Plugins extends EventEmitter {
|
Plugins.prototype.loadPlugins = function() {
|
||||||
constructor(options) {
|
var pluginConfig;
|
||||||
super();
|
for (var pluginName in this.pluginList) {
|
||||||
//TODO: put an observer on this.plugins and call loadPlugin when a new item is added
|
pluginConfig = this.pluginList[pluginName];
|
||||||
this.config = {};
|
this.loadPlugin(pluginName, pluginConfig);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for (let opt in options) {
|
Plugins.prototype.listPlugins = function() {
|
||||||
if (options.hasOwnProperty(opt)) {
|
var list = [];
|
||||||
this.config[opt] = options[opt];
|
for (var className in this.pluginList) {
|
||||||
}
|
list.push(className);
|
||||||
}
|
}
|
||||||
|
return list;
|
||||||
|
};
|
||||||
|
|
||||||
let requiredOptions = ['interceptLogs', 'plugins', 'logger'];
|
Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
|
||||||
for (let i = 0; requiredOptions.length > i; i++) {
|
var pluginPath = utils.joinPath(process.env.PWD, 'node_modules', pluginName);
|
||||||
if (!(_.contains(Object.keys(this.config), requiredOptions[i]))) {
|
var plugin = require(pluginPath);
|
||||||
console.log('Warning: missing required plugin configuration key: ' + requiredOptions[i]);
|
|
||||||
}
|
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config});
|
||||||
}
|
pluginWrapper.loadPlugin();
|
||||||
this.on('load', () => {
|
this.plugins.push(pluginWrapper);
|
||||||
this.load();
|
};
|
||||||
|
|
||||||
|
Plugins.prototype.getPluginsFor = function(pluginType) {
|
||||||
|
return this.plugins.filter(function(plugin) {
|
||||||
|
return plugin.has(pluginType);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
this.on('get', (pluginType, cb) => {
|
|
||||||
let pluginTypes = getPluginsFor(pluginType, this.config.plugins);
|
|
||||||
return cb(pluginTypes);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
load() {
|
|
||||||
let pluginConfig;
|
|
||||||
for (let i = 0; this.config.plugins.length > i; i++) {
|
|
||||||
pluginConfig = this.config.plugins[i].config;
|
|
||||||
let Plugin = require('./plugin');
|
|
||||||
let plugin = new Plugin(pluginConfig);
|
|
||||||
plugin.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPlugins () {
|
|
||||||
return this.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
listPlugins() {
|
|
||||||
return this.config.plugins.join(', ');
|
|
||||||
}
|
|
||||||
|
|
||||||
getPluginsFor(pluginType, plugins) {
|
|
||||||
return getPluginsFor(pluginType, plugins);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Plugins;
|
module.exports = Plugins;
|
|
@ -32,12 +32,9 @@ class Console {
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCmd(cmd, callback) {
|
executeCmd(cmd, callback) {
|
||||||
let plugin, pluginOutput;
|
var plugin, pluginOutput;
|
||||||
let plugins = [];
|
var plugins = this.plugins.getPluginsFor('console');
|
||||||
this.plugins.emit('get', 'console', (list) => {
|
for (var i = 0; i < plugins.length; i++) {
|
||||||
plugins = list;
|
|
||||||
});
|
|
||||||
for (let i = 0; i < plugins.length; i++) {
|
|
||||||
plugin = plugins[i];
|
plugin = plugins[i];
|
||||||
pluginOutput = plugin.runCommands(cmd, {});
|
pluginOutput = plugin.runCommands(cmd, {});
|
||||||
if (pluginOutput !== false && pluginOutput !== 'false') return callback(pluginOutput);
|
if (pluginOutput !== false && pluginOutput !== 'false') return callback(pluginOutput);
|
||||||
|
|
12
lib/index.js
12
lib/index.js
|
@ -11,12 +11,11 @@ let Swarm = require('./upload/swarm.js');
|
||||||
|
|
||||||
let version = require('../package.json').version;
|
let version = require('../package.json').version;
|
||||||
|
|
||||||
const EventEmitter = require('events').EventEmitter;
|
let Events = require('events');
|
||||||
|
|
||||||
class Embark extends EventEmitter {
|
class Embark {
|
||||||
|
|
||||||
constructor (options) {
|
constructor (options) {
|
||||||
super();
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
}
|
}
|
||||||
|
@ -51,19 +50,21 @@ class Embark extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
run(options) {
|
run(options) {
|
||||||
|
let self = this;
|
||||||
let Dashboard = require('./dashboard/dashboard.js');
|
let Dashboard = require('./dashboard/dashboard.js');
|
||||||
|
|
||||||
let env = options.env;
|
let env = options.env;
|
||||||
|
|
||||||
let engine = new Engine({
|
let engine = new Engine({
|
||||||
env: options.env,
|
env: options.env,
|
||||||
|
version: this.version,
|
||||||
embarkConfig: options.embarkConfig || 'embark.json'
|
embarkConfig: options.embarkConfig || 'embark.json'
|
||||||
});
|
});
|
||||||
engine.init();
|
engine.init();
|
||||||
|
|
||||||
if (!options.useDashboard) {
|
if (!options.useDashboard) {
|
||||||
console.log('========================'.bold.green);
|
console.log('========================'.bold.green);
|
||||||
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
|
console.log(('Welcome to Embark ' + this.version).yellow.bold);
|
||||||
console.log('========================'.bold.green);
|
console.log('========================'.bold.green);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +77,7 @@ class Embark extends EventEmitter {
|
||||||
let dashboard = new Dashboard({
|
let dashboard = new Dashboard({
|
||||||
logger: engine.logger,
|
logger: engine.logger,
|
||||||
plugins: engine.plugins,
|
plugins: engine.plugins,
|
||||||
version: engine.version,
|
version: self.version,
|
||||||
env: engine.env
|
env: engine.env
|
||||||
});
|
});
|
||||||
dashboard.start(function () {
|
dashboard.start(function () {
|
||||||
|
@ -141,6 +142,7 @@ class Embark extends EventEmitter {
|
||||||
|
|
||||||
let engine = new Engine({
|
let engine = new Engine({
|
||||||
env: options.env,
|
env: options.env,
|
||||||
|
version: this.version,
|
||||||
embarkConfig: 'embark.json',
|
embarkConfig: 'embark.json',
|
||||||
interceptLogs: false
|
interceptLogs: false
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue