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'),
|
define_web3_simple: require('./code_templates/define-web3-simple.js.ejs'),
|
||||||
web3_connector: require('./code_templates/web3-connector.js.ejs'),
|
web3_connector: require('./code_templates/web3-connector.js.ejs'),
|
||||||
do_when_loaded: require('./code_templates/do-when-loaded.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'),
|
exec_when_env_loaded: require('./code_templates/exec-when-env-loaded.js.ejs')
|
||||||
embark_building_placeholder: require('./code_templates/embark-building-placeholder.html.ejs')
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CodeGenerator {
|
class CodeGenerator {
|
||||||
|
@ -94,10 +93,6 @@ class CodeGenerator {
|
||||||
cb(self.generateContractCode(contract, gasLimit));
|
cb(self.generateContractCode(contract, gasLimit));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.events.setCommandHandler('embark-building-placeholder', (cb) => {
|
|
||||||
self.buildPlaceholderPage(cb);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.events.setCommandHandler('code-generator:embarkjs:provider-code', (cb) => {
|
self.events.setCommandHandler('code-generator:embarkjs:provider-code', (cb) => {
|
||||||
cb(self.getEmbarkJsProviderCode());
|
cb(self.getEmbarkJsProviderCode());
|
||||||
});
|
});
|
||||||
|
@ -379,12 +374,6 @@ class CodeGenerator {
|
||||||
}
|
}
|
||||||
], cb);
|
], cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildPlaceholderPage(cb) {
|
|
||||||
let html = Templates.embark_building_placeholder({buildingMsg: __('Embark is building, please wait...')});
|
|
||||||
cb(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = CodeGenerator;
|
module.exports = CodeGenerator;
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
|
const fs = require('../../core/fs.js');
|
||||||
var {canonicalHost} = require('../../utils/host.js');
|
var {canonicalHost} = require('../../utils/host.js');
|
||||||
var utils = require('../../utils/utils.js');
|
var utils = require('../../utils/utils.js');
|
||||||
var Server = require('./server.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) {
|
constructor(embark, options) {
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
|
@ -62,6 +67,7 @@ class WebServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
listenToCommands() {
|
listenToCommands() {
|
||||||
|
this.events.setCommandHandler('embark-building-placeholder', (cb) => this.buildPlaceholderPage(cb));
|
||||||
this.events.setCommandHandler('start-webserver', (callback) => this.server.start(callback));
|
this.events.setCommandHandler('start-webserver', (callback) => this.server.start(callback));
|
||||||
this.events.setCommandHandler('stop-webserver', (callback) => this.server.stop(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;
|
module.exports = WebServer;
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
let finalhandler = require('finalhandler');
|
let finalhandler = require('finalhandler');
|
||||||
const fs = require('../../core/fs.js');
|
|
||||||
let http = require('http');
|
let http = require('http');
|
||||||
let serveStatic = require('serve-static');
|
let serveStatic = require('serve-static');
|
||||||
const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host');
|
const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host');
|
||||||
const opn = require('opn');
|
const opn = require('opn');
|
||||||
const utils = require('../../utils/utils.js');
|
|
||||||
require('http-shutdown').extend();
|
require('http-shutdown').extend();
|
||||||
|
|
||||||
require('ejs');
|
|
||||||
const embark_building_placeholder = require('../code_generator/code_templates/embark-building-placeholder.html.ejs');
|
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
|
@ -32,12 +27,6 @@ class Server {
|
||||||
serve(req, res, finalhandler(req, res));
|
serve(req, res, finalhandler(req, res));
|
||||||
}).withShutdown();
|
}).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.server.listen(this.port, this.hostname, () => {
|
||||||
this.port = this.server.address().port;
|
this.port = this.server.address().port;
|
||||||
|
|
|
@ -29,10 +29,6 @@ class Pipeline {
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function createPlaceholderPage(next){
|
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) {
|
function buildTheContracts(next) {
|
||||||
self.buildContracts(next);
|
self.buildContracts(next);
|
||||||
|
|
Loading…
Reference in New Issue