Browse Source

Server will now generate version for each request (showing a -X if the current commit is dirty)

dev
Bryan Miller 5 years ago
parent
commit
8587a63df9
1 changed files with 13 additions and 4 deletions
  1. +13
    -4
      server.js

+ 13
- 4
server.js View File

@@ -56,8 +56,18 @@ var generateCSS = debounce(function(src, cb){

// -------------------------------------------------------
// Configuring the current version of the application.

function GitClean(){
try {
exec("git diff --quiet HEAD");
} catch(e) {
return false;
}
return true;
}
function GenVersion(){
var v = package.version;
var clean = GitClean();
// Testing for a GIT repo... if not in a production environment.
if (production === false){
try{
@@ -65,7 +75,7 @@ function GenVersion(){
v += "-[" + res.trim();

res = exec("git rev-parse HEAD").toString();
v += ":" + res.substring(0, 5) + "]";
v += ":" + res.substring(0, 5) + ((clean) ? "" : "-X") + "]";
} catch(e) {
if (v !== package.version){
v += "]"; // If v doesn't match package.version, then assume that the first git call worked.
@@ -75,7 +85,6 @@ function GenVersion(){

return v;
}
var version = GenVersion();


// ---------------------------------------------------
@@ -89,7 +98,7 @@ app.use("/app/css/nespaint.css", function(req, res){
res.send(new Buffer.from(css_output));
});
app.get('/', function(req, res){
res.render('index.html', {version:version, author:package.author});
res.render('index.html', {version:GenVersion(), author:package.author});
});


@@ -116,7 +125,7 @@ watcher.on('change', (fpath) => {

// --------------------------------------------------
// Announce app version!
console.log("NESPaint (v" + version + ") Server");
console.log("NESPaint (v" + GenVersion() + ") Server");


// --------------------------------------------------

Loading…
Cancel
Save