mirror of https://github.com/embarklabs/embark.git
Merge pull request #477 from embark-framework/reduce_loading_time
improve loading time by only doing require when needed
This commit is contained in:
commit
521a2e5c19
|
@ -1,19 +1,5 @@
|
|||
const async = require('async');
|
||||
|
||||
const Events = require('./events.js');
|
||||
const Logger = require('./logger.js');
|
||||
const Config = require('./config.js');
|
||||
const Blockchain = require('../contracts/blockchain.js');
|
||||
const Compiler = require('../contracts/compiler.js');
|
||||
const ContractsManager = require('../contracts/contracts.js');
|
||||
const ContractDeployer = require('../contracts/contract_deployer.js');
|
||||
const DeployManager = require('../contracts/deploy_manager.js');
|
||||
const CodeGenerator = require('../contracts/code_generator.js');
|
||||
const ServicesMonitor = require('./services_monitor.js');
|
||||
const Pipeline = require('../pipeline/pipeline.js');
|
||||
const Watch = require('../pipeline/watch.js');
|
||||
const LibraryManager = require('../versions/library_manager.js');
|
||||
const CodeRunner = require('../coderunner/codeRunner.js');
|
||||
const utils = require('../utils/utils');
|
||||
|
||||
class Engine {
|
||||
|
@ -32,6 +18,10 @@ class Engine {
|
|||
}
|
||||
|
||||
init(_options) {
|
||||
const Events = require('./events.js');
|
||||
const Logger = require('./logger.js');
|
||||
const Config = require('./config.js');
|
||||
|
||||
let options = _options || {};
|
||||
this.events = options.events || this.events || new Events();
|
||||
this.logger = options.logger || new Logger({logLevel: options.logLevel || this.logLevel || 'debug', events: this.events, logFile: this.logFile});
|
||||
|
@ -105,6 +95,7 @@ class Engine {
|
|||
pipelineService(_options) {
|
||||
const self = this;
|
||||
this.events.emit("status", "Building Assets");
|
||||
const Pipeline = require('../pipeline/pipeline.js');
|
||||
const pipeline = new Pipeline({
|
||||
buildDir: this.config.buildDir,
|
||||
contractsFiles: this.config.contractsFiles,
|
||||
|
@ -127,6 +118,7 @@ class Engine {
|
|||
|
||||
serviceMonitor() {
|
||||
const self = this;
|
||||
const ServicesMonitor = require('./services_monitor.js');
|
||||
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger, plugins: this.plugins});
|
||||
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
|
||||
return cb({name: 'Embark ' + self.version, status: 'on'});
|
||||
|
@ -139,6 +131,7 @@ class Engine {
|
|||
}
|
||||
|
||||
codeRunnerService(_options) {
|
||||
const CodeRunner = require('../coderunner/codeRunner.js');
|
||||
this.codeRunner = new CodeRunner({
|
||||
plugins: this.plugins,
|
||||
events: this.events,
|
||||
|
@ -149,6 +142,7 @@ class Engine {
|
|||
codeGeneratorService(_options) {
|
||||
let self = this;
|
||||
|
||||
const CodeGenerator = require('../contracts/code_generator.js');
|
||||
this.codeGenerator = new CodeGenerator({
|
||||
blockchainConfig: self.config.blockchainConfig,
|
||||
contractsConfig: self.config.contractsConfig,
|
||||
|
@ -182,6 +176,7 @@ class Engine {
|
|||
deploymentService(options) {
|
||||
let self = this;
|
||||
|
||||
const Compiler = require('../contracts/compiler.js');
|
||||
let compiler = new Compiler({plugins: self.plugins, logger: self.logger});
|
||||
this.events.setCommandHandler("compiler:contracts", function(contractFiles, cb) {
|
||||
compiler.compile_contracts(contractFiles, cb);
|
||||
|
@ -193,6 +188,7 @@ class Engine {
|
|||
this.registerModule('deploytracker');
|
||||
this.registerModule('specialconfigs');
|
||||
|
||||
const ContractsManager = require('../contracts/contracts.js');
|
||||
this.contractsManager = new ContractsManager({
|
||||
contractFiles: this.config.contractsFiles,
|
||||
contractsConfig: this.config.contractsConfig,
|
||||
|
@ -202,6 +198,7 @@ class Engine {
|
|||
events: this.events
|
||||
});
|
||||
|
||||
const DeployManager = require('../contracts/deploy_manager.js');
|
||||
this.deployManager = new DeployManager({
|
||||
blockchain: this.blockchain,
|
||||
config: this.config,
|
||||
|
@ -211,6 +208,7 @@ class Engine {
|
|||
onlyCompile: options.onlyCompile
|
||||
});
|
||||
|
||||
const ContractDeployer = require('../contracts/contract_deployer.js');
|
||||
this.contractDeployer = new ContractDeployer({
|
||||
blockchain: this.blockchain,
|
||||
logger: this.logger,
|
||||
|
@ -240,6 +238,7 @@ class Engine {
|
|||
|
||||
fileWatchService(_options) {
|
||||
this.events.emit("status", "Watching for changes");
|
||||
const Watch = require('../pipeline/watch.js');
|
||||
this.watch = new Watch({logger: this.logger, events: this.events});
|
||||
this.watch.start();
|
||||
}
|
||||
|
@ -264,6 +263,7 @@ class Engine {
|
|||
}
|
||||
|
||||
web3Service(options) {
|
||||
const Blockchain = require('../contracts/blockchain.js');
|
||||
this.blockchain = new Blockchain({
|
||||
contractsConfig: this.config.contractsConfig,
|
||||
blockchainConfig: this.config.blockchainConfig,
|
||||
|
@ -282,6 +282,7 @@ class Engine {
|
|||
}
|
||||
|
||||
libraryManagerService(_options) {
|
||||
const LibraryManager = require('../versions/library_manager.js');
|
||||
this.libraryManager = new LibraryManager({
|
||||
plugins: this.plugins,
|
||||
config: this.config
|
||||
|
|
14
lib/index.js
14
lib/index.js
|
@ -12,8 +12,6 @@ process.chdir = (...args) => {
|
|||
realChdir(...args);
|
||||
};
|
||||
|
||||
let Engine = require('./core/engine.js');
|
||||
|
||||
let version = require('../package.json').version;
|
||||
|
||||
class Embark {
|
||||
|
@ -69,7 +67,8 @@ class Embark {
|
|||
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
||||
let Dashboard = require('./dashboard/dashboard.js');
|
||||
|
||||
let engine = new Engine({
|
||||
const Engine = require('./core/engine.js');
|
||||
const engine = new Engine({
|
||||
env: options.env,
|
||||
client: options.client,
|
||||
locale: options.locale,
|
||||
|
@ -159,7 +158,8 @@ class Embark {
|
|||
build(options) {
|
||||
this.context = options.context || [constants.contexts.build];
|
||||
|
||||
let engine = new Engine({
|
||||
const Engine = require('./core/engine.js');
|
||||
const engine = new Engine({
|
||||
env: options.env,
|
||||
client: options.client,
|
||||
locale: options.locale,
|
||||
|
@ -214,7 +214,8 @@ class Embark {
|
|||
this.context = options.context || [constants.contexts.graph];
|
||||
options.onlyCompile = true;
|
||||
|
||||
let engine = new Engine({
|
||||
const Engine = require('./core/engine.js');
|
||||
const engine = new Engine({
|
||||
env: options.env,
|
||||
isDev: this.isDev(options.env),
|
||||
version: this.version,
|
||||
|
@ -269,7 +270,8 @@ class Embark {
|
|||
upload(options) {
|
||||
this.context = options.context || [constants.contexts.upload, constants.contexts.build];
|
||||
|
||||
let engine = new Engine({
|
||||
const Engine = require('./core/engine.js');
|
||||
const engine = new Engine({
|
||||
env: options.env,
|
||||
client: options.client,
|
||||
locale: options.locale,
|
||||
|
|
Loading…
Reference in New Issue