Added a build runner in line with starting the service.

This commit is contained in:
Chris Kleeschulte 2017-09-26 17:13:22 -04:00
parent e94154ba4b
commit 7155ff0b91
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F
3 changed files with 42 additions and 30 deletions

View File

@ -3,15 +3,13 @@
var BaseService = require('./service');
var inherits = require('util').inherits;
var fs = require('fs');
var pkg = require('../package');
var exec = require('child_process').exec;
var pkg = require('../package.json');
var InsightUI = function(options) {
BaseService.call(this, options);
// we don't use the options object for routePrefix and apiPrefix, since the
// client must be rebuilt with the proper options. A future version of
// Bitcore should allow for a service "build" step to make this better.
this.apiPrefix = pkg.insightConfig.apiPrefix;
this.routePrefix = pkg.insightConfig.routePrefix;
this.apiPrefix = options.apiPrefix || 'api';
this.routePrefix = options.routePrefix || '';
};
InsightUI.dependencies = ['insight-api'];
@ -19,8 +17,21 @@ InsightUI.dependencies = ['insight-api'];
inherits(InsightUI, BaseService);
InsightUI.prototype.start = function(callback) {
this.indexFile = this.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index-template.html', {encoding: 'utf8'}));
setImmediate(callback);
var self = this;
pkg.insightConfig.apiPrefix = self.apiPrefix;
pkg.insightConfig.routePrefix = self.routePrefix;
fs.writeFileSync(__dirname + '/../package.json', JSON.stringify(pkg, null, 2));
exec('pushd ' + __dirname + '/../;' +
' npm run install-and-build; popd', function(err) {
if (err) {
return callback(err);
}
self.indexFile = self.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index-template.html', {encoding: 'utf8'}));
callback();
});
};
InsightUI.prototype.getRoutePrefix = function() {
@ -31,7 +42,7 @@ InsightUI.prototype.setupRoutes = function(app, express) {
var self = this;
app.use(express.static(__dirname + '/../public'));
// if not in found, fall back to indexFile (404 is handled client-side)
app.use(function(req, res, next) {
app.use(function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.send(self.indexFile);
});

34
package-lock.json generated
View File

@ -1,9 +1,25 @@
{
"name": "insight-ui",
"version": "5.0.0-beta.1",
"version": "5.0.0-beta.12",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"CSSselect": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/CSSselect/-/CSSselect-0.4.1.tgz",
"integrity": "sha1-+Kt+H4QYzmPNput713ioXX7EkrI=",
"dev": true,
"requires": {
"CSSwhat": "0.4.7",
"domutils": "1.4.3"
}
},
"CSSwhat": {
"version": "0.4.7",
"resolved": "https://registry.npmjs.org/CSSwhat/-/CSSwhat-0.4.7.tgz",
"integrity": "sha1-hn2g/zn3eGEyQsRM/qg/CqTr35s=",
"dev": true
},
"abbrev": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.0.tgz",
@ -303,22 +319,6 @@
"integrity": "sha1-xBuptrn+x3vKhxEuces6Ig71m8Q=",
"dev": true
},
"CSSselect": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/CSSselect/-/CSSselect-0.4.1.tgz",
"integrity": "sha1-+Kt+H4QYzmPNput713ioXX7EkrI=",
"dev": true,
"requires": {
"CSSwhat": "0.4.7",
"domutils": "1.4.3"
}
},
"CSSwhat": {
"version": "0.4.7",
"resolved": "https://registry.npmjs.org/CSSwhat/-/CSSwhat-0.4.7.tgz",
"integrity": "sha1-hn2g/zn3eGEyQsRM/qg/CqTr35s=",
"dev": true
},
"dateformat": {
"version": "1.0.2-1.2.3",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.2-1.2.3.tgz",

View File

@ -1,7 +1,7 @@
{
"name": "insight-ui",
"description": "An open-source frontend for the Insight API. The Insight API provides you with a convenient, powerful and simple way to query and broadcast data on the bitcoin network and build your own services with it.",
"version": "5.0.0-beta.1",
"version": "5.0.0-beta.12",
"repository": "git://github.com/bitpay/insight-ui.git",
"bugs": {
"url": "https://github.com/bitpay/insight-ui/issues"
@ -18,12 +18,13 @@
],
"bitcoreNode": "bitcore-node",
"insightConfig": {
"apiPrefix": "insight-api",
"routePrefix": "insight"
"apiPrefix": "api",
"routePrefix": ""
},
"scripts": {
"build": "bower install && grunt compile",
"watch": "grunt"
"watch": "grunt",
"install-and-build": "npm install && npm run build"
},
"dependencies": {},
"devDependencies": {