From 7155ff0b9129afed75b3183cea766f3667e273c9 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Tue, 26 Sep 2017 17:13:22 -0400 Subject: [PATCH] Added a build runner in line with starting the service. --- bitcore-node/index.js | 29 ++++++++++++++++++++--------- package-lock.json | 34 +++++++++++++++++----------------- package.json | 9 +++++---- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/bitcore-node/index.js b/bitcore-node/index.js index a013267..42fdb47 100644 --- a/bitcore-node/index.js +++ b/bitcore-node/index.js @@ -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); }); diff --git a/package-lock.json b/package-lock.json index 9ede67a..3b92d54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 55fe65e..c1860f5 100644 --- a/package.json +++ b/package.json @@ -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": {