mirror of https://github.com/embarklabs/embark.git
make webserver module responsible for building placeholder
This commit is contained in:
parent
1d38af1f58
commit
6ee195aba9
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue