consolidate version numbers throughout all interfaces

This commit is contained in:
William Boman 2016-09-05 14:37:27 +02:00
parent 7e39ae045f
commit 99218341ec
4 changed files with 33 additions and 17 deletions

View file

@ -257,7 +257,7 @@ Client.prototype.connect = function(args) {
}); });
network.irc.connect({ network.irc.connect({
version: pkg.name + " " + pkg.version + " -- " + pkg.homepage, version: pkg.name + " " + Helper.getVersion() + " -- " + pkg.homepage,
host: network.host, host: network.host,
port: network.port, port: network.port,
nick: nick, nick: nick,

View file

@ -3,13 +3,12 @@
global.log = require("../log.js"); global.log = require("../log.js");
var program = require("commander"); var program = require("commander");
var pkg = require("../../package.json");
var fs = require("fs"); var fs = require("fs");
var fsextra = require("fs-extra"); var fsextra = require("fs-extra");
var path = require("path"); var path = require("path");
var Helper = require("../helper"); var Helper = require("../helper");
program.version(pkg.version, "-v, --version"); program.version(Helper.getVersion(), "-v, --version");
program.option(""); program.option("");
program.option(" --home <path>" , "home path"); program.option(" --home <path>" , "home path");

View file

@ -1,5 +1,6 @@
"use strict"; "use strict";
const pkg = require("../package.json");
var _ = require("lodash"); var _ = require("lodash");
var path = require("path"); var path = require("path");
var os = require("os"); var os = require("os");
@ -11,6 +12,8 @@ var Helper = {
getUserConfigPath: getUserConfigPath, getUserConfigPath: getUserConfigPath,
getUserLogsPath: getUserLogsPath, getUserLogsPath: getUserLogsPath,
setHome: setHome, setHome: setHome,
getVersion: getVersion,
getGitCommit: getGitCommit,
}; };
module.exports = Helper; module.exports = Helper;
@ -22,6 +25,29 @@ Helper.config = require(path.resolve(path.join(
"config.js" "config.js"
))); )));
function getVersion() {
const gitCommit = getGitCommit();
return gitCommit ? `source (${gitCommit})` : `v${pkg.version}`;
}
let _gitCommit;
function getGitCommit() {
if (_gitCommit !== undefined) {
return _gitCommit;
}
try {
_gitCommit = require("child_process")
.execSync("git rev-parse --short HEAD 2> /dev/null") // Returns hash of current commit
.toString()
.trim();
return _gitCommit;
} catch (e) {
// Not a git repository or git is not installed
_gitCommit = null;
return null;
}
}
function setHome(homePath) { function setHome(homePath) {
this.HOME = expandHome(homePath || "~/.lounge"); this.HOME = expandHome(homePath || "~/.lounge");
this.CONFIG_PATH = path.join(this.HOME, "config.js"); this.CONFIG_PATH = path.join(this.HOME, "config.js");

View file

@ -81,8 +81,10 @@ module.exports = function() {
manager.sockets = sockets; manager.sockets = sockets;
var protocol = config.https.enable ? "https" : "http"; let protocol = config.https.enable ? "https" : "http";
log.info("The Lounge v" + pkg.version + " is now running on", protocol + "://" + (config.host || "*") + ":" + config.port + "/", (config.public ? "in public mode" : "in private mode")); let host = config.host || "*";
log.info("The Lounge", Helper.getVersion(), "is now running");
log.info(`Available on: ${protocol}://${host}:${config.port}/ in ${config.public ? "public" : "private"} mode`);
log.info("Press ctrl-c to stop\n"); log.info("Press ctrl-c to stop\n");
if (!config.public) { if (!config.public) {
@ -110,17 +112,6 @@ function allRequests(req, res, next) {
return next(); return next();
} }
// Information to populate the About section in UI, either from npm or from git
var gitCommit = null;
try {
gitCommit = require("child_process")
.execSync("git rev-parse --short HEAD 2> /dev/null") // Returns hash of current commit
.toString()
.trim();
} catch (e) {
// Not a git repository or git is not installed: treat it as npm release
}
function index(req, res, next) { function index(req, res, next) {
if (req.url.split("?")[0] !== "/") { if (req.url.split("?")[0] !== "/") {
return next(); return next();
@ -135,7 +126,7 @@ function index(req, res, next) {
pkg, pkg,
Helper.config Helper.config
); );
data.gitCommit = gitCommit; data.gitCommit = Helper.getGitCommit();
data.themes = fs.readdirSync("client/themes/").filter(function(themeFile) { data.themes = fs.readdirSync("client/themes/").filter(function(themeFile) {
return themeFile.endsWith(".css"); return themeFile.endsWith(".css");
}).map(function(css) { }).map(function(css) {