From 6ee195aba917ad23c0fa6cb8abca33fd878c73b4 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 31 Aug 2018 14:59:54 -0500 Subject: [PATCH] make webserver module responsible for building placeholder --- lib/modules/code_generator/index.js | 13 +------------ lib/modules/webserver/index.js | 14 +++++++++++++- lib/modules/webserver/server.js | 11 ----------- .../embark-building-placeholder.html.ejs | 0 lib/pipeline/pipeline.js | 4 ---- 5 files changed, 14 insertions(+), 28 deletions(-) rename lib/modules/{code_generator/code_templates => webserver/templates}/embark-building-placeholder.html.ejs (100%) diff --git a/lib/modules/code_generator/index.js b/lib/modules/code_generator/index.js index ecc1aee5e..371f69682 100644 --- a/lib/modules/code_generator/index.js +++ b/lib/modules/code_generator/index.js @@ -13,8 +13,7 @@ const Templates = { define_web3_simple: require('./code_templates/define-web3-simple.js.ejs'), web3_connector: require('./code_templates/web3-connector.js.ejs'), do_when_loaded: require('./code_templates/do-when-loaded.js.ejs'), - exec_when_env_loaded: require('./code_templates/exec-when-env-loaded.js.ejs'), - embark_building_placeholder: require('./code_templates/embark-building-placeholder.html.ejs') + exec_when_env_loaded: require('./code_templates/exec-when-env-loaded.js.ejs') }; class CodeGenerator { @@ -94,10 +93,6 @@ class CodeGenerator { cb(self.generateContractCode(contract, gasLimit)); }); - this.events.setCommandHandler('embark-building-placeholder', (cb) => { - self.buildPlaceholderPage(cb); - }); - self.events.setCommandHandler('code-generator:embarkjs:provider-code', (cb) => { cb(self.getEmbarkJsProviderCode()); }); @@ -379,12 +374,6 @@ class CodeGenerator { } ], cb); } - - buildPlaceholderPage(cb) { - let html = Templates.embark_building_placeholder({buildingMsg: __('Embark is building, please wait...')}); - cb(html); - } - } module.exports = CodeGenerator; diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index 3f335ea8c..61c36eef6 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -1,9 +1,14 @@ +const fs = require('../../core/fs.js'); var {canonicalHost} = require('../../utils/host.js'); var utils = require('../../utils/utils.js'); var Server = require('./server.js'); -class WebServer { +require('ejs'); +const Templates = { + embark_building_placeholder: require('./templates/embark-building-placeholder.html.ejs') +}; +class WebServer { constructor(embark, options) { this.embark = embark; this.logger = embark.logger; @@ -62,6 +67,7 @@ class WebServer { } listenToCommands() { + this.events.setCommandHandler('embark-building-placeholder', (cb) => this.buildPlaceholderPage(cb)); this.events.setCommandHandler('start-webserver', (callback) => this.server.start(callback)); this.events.setCommandHandler('stop-webserver', (callback) => this.server.stop(callback)); } @@ -82,6 +88,12 @@ class WebServer { }; }); } + + buildPlaceholderPage(cb) { + let html = Templates.embark_building_placeholder({buildingMsg: __('Embark is building, please wait...')}); + fs.mkdirpSync(this.buildDir); // create buildDir/ folder if not already exists + fs.writeFile(utils.joinPath(this.buildDir, 'index.html'), html, cb); + } } module.exports = WebServer; diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 73ba07a75..7294bf031 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -1,15 +1,10 @@ let finalhandler = require('finalhandler'); -const fs = require('../../core/fs.js'); let http = require('http'); let serveStatic = require('serve-static'); const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host'); const opn = require('opn'); -const utils = require('../../utils/utils.js'); require('http-shutdown').extend(); -require('ejs'); -const embark_building_placeholder = require('../code_generator/code_templates/embark-building-placeholder.html.ejs'); - class Server { constructor(options) { this.buildDir = options.buildDir; @@ -32,12 +27,6 @@ class Server { serve(req, res, finalhandler(req, res)); }).withShutdown(); - if (this.isFirstStart) { - const html = embark_building_placeholder({buildingMsg: __('Embark is building, please wait...')}); - fs.mkdirpSync(this.dist); // create dist/ folder if not already exists - fs.writeFileSync(utils.joinPath(this.dist, 'index.html'), html); - this.isFirstStart = false; - } this.server.listen(this.port, this.hostname, () => { this.port = this.server.address().port; diff --git a/lib/modules/code_generator/code_templates/embark-building-placeholder.html.ejs b/lib/modules/webserver/templates/embark-building-placeholder.html.ejs similarity index 100% rename from lib/modules/code_generator/code_templates/embark-building-placeholder.html.ejs rename to lib/modules/webserver/templates/embark-building-placeholder.html.ejs diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 1f0a742be..7d2b7538a 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -29,10 +29,6 @@ class Pipeline { async.waterfall([ function createPlaceholderPage(next){ - self.events.request('embark-building-placeholder', (html) => { - fs.mkdirpSync(self.buildDir); // create dist/ folder if not already exists - fs.writeFile(utils.joinPath(self.buildDir, 'index.html'), html, next); - }); }, function buildTheContracts(next) { self.buildContracts(next);