2015-03-26 05:23:14 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2017-07-23 19:03:47 +00:00
|
|
|
const paths = require('path');
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2017-07-23 19:03:47 +00:00
|
|
|
const os = require('os');
|
|
|
|
const packageJson = require('../package.json');
|
|
|
|
|
|
|
|
exports.isProduction = isProduction;
|
|
|
|
exports.isDevelopment = isDevelopment;
|
|
|
|
exports.valueWithDefault = valueWithDefault;
|
|
|
|
exports.resolvePath = resolvePath;
|
|
|
|
exports.getCleanEnigmaVersion = getCleanEnigmaVersion;
|
|
|
|
exports.getEnigmaUserAgent = getEnigmaUserAgent;
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
function isProduction() {
|
2018-06-22 05:15:04 +00:00
|
|
|
var env = process.env.NODE_ENV || 'dev';
|
|
|
|
return 'production' === env;
|
2015-03-26 05:23:14 +00:00
|
|
|
}
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
function isDevelopment() {
|
2018-06-22 05:15:04 +00:00
|
|
|
return (!(isProduction()));
|
2015-03-26 05:23:14 +00:00
|
|
|
}
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
function valueWithDefault(val, defVal) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return (typeof val !== 'undefined' ? val : defVal);
|
2015-03-26 05:23:14 +00:00
|
|
|
}
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
function resolvePath(path) {
|
2018-06-22 05:15:04 +00:00
|
|
|
if(path.substr(0, 2) === '~/') {
|
|
|
|
var mswCombined = process.env.HOMEDRIVE + process.env.HOMEPATH;
|
|
|
|
path = (process.env.HOME || mswCombined || process.env.HOMEPATH || process.env.HOMEDIR || process.cwd()) + path.substr(1);
|
|
|
|
}
|
|
|
|
return paths.resolve(path);
|
2017-07-23 19:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCleanEnigmaVersion() {
|
2018-06-22 05:15:04 +00:00
|
|
|
return packageJson.version
|
|
|
|
.replace(/-/g, '.')
|
|
|
|
.replace(/alpha/,'a')
|
|
|
|
.replace(/beta/,'b')
|
|
|
|
;
|
2017-07-23 19:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// See also ftn_util.js getTearLine() & getProductIdentifier()
|
|
|
|
function getEnigmaUserAgent() {
|
2018-06-22 05:15:04 +00:00
|
|
|
// can't have 1/2 or ½ in User-Agent according to RFC 1945 :(
|
|
|
|
const version = getCleanEnigmaVersion();
|
|
|
|
const nodeVer = process.version.substr(1); // remove 'v' prefix
|
2017-07-23 19:03:47 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return `ENiGMA-BBS/${version} (${os.platform()}; ${os.arch()}; ${nodeVer})`;
|
2015-03-26 05:23:14 +00:00
|
|
|
}
|