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



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

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


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


return v; return v;
} }
var version = GenVersion();




// --------------------------------------------------- // ---------------------------------------------------
res.send(new Buffer.from(css_output)); res.send(new Buffer.from(css_output));
}); });
app.get('/', function(req, res){ app.get('/', function(req, res){
res.render('index.html', {version:version, author:package.author});
res.render('index.html', {version:GenVersion(), author:package.author});
}); });






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




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

Loading…
Cancel
Save