craydent-cli
Version:
Node module to manage command line execution and arguments
93 lines (92 loc) • 3.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.info = exports.scope = exports.$c = exports._craydent_version = exports.CraydentInstance = void 0;
const craydent_globalize_1 = require("craydent.globalize");
const craydent_include_1 = require("craydent.include");
const __isNewer_1 = require("../private/__isNewer");
// @ts-ignore
class CraydentInstance {
constructor() {
this.VERSION = "";
this.DEBUG_MODE = false;
this.ERROR_TYPES = [];
this.MODULES_LOADED = {};
this.CONSOLE_COLORS = {
RED: "",
GREEN: "",
YELLOW: ""
};
this.LOCAL_IP = "";
this.PUBLIC_IP = "";
this.TEMPLATE_VARS = [];
this.TEMPLATE_TAG_CONFIG = {};
this.RESPONSES = {};
this.HTTP_STATUS_TEMPLATE = {};
this.REST_API_TEMPLATE = "";
this.ROUTE_API_PATH = "";
this.ROUTE_LOGO_URL = "";
this.EXPOSE_ROUTE_API = false;
this.VERBOSE_LOGS = false;
this.globalize = () => undefined;
this.name = "";
this.navigator = {};
return this;
}
}
exports.CraydentInstance = CraydentInstance;
/* istanbul ignore next */
if (typeof (global) == 'undefined') {
window.global = window;
}
global.$g = global;
let info = require('../package.json'), _craydent_version = info.version, scope = { eval: eval }, $c = $g.$c;
exports.info = info;
exports._craydent_version = _craydent_version;
exports.scope = scope;
exports.$c = $c;
const navigator = Object.getOwnPropertyDescriptor($g, 'navigator');
if (navigator && typeof navigator.set === 'function') {
$g.navigator = $g.navigator || {};
}
/* istanbul ignore next */
if (!$g.$c || (0, __isNewer_1.default)($g.$c.VERSION.split('.'), _craydent_version.split('.'))) {
$g.$c = exports.$c = $c = $g.$c || {};
$c.VERSION = _craydent_version;
$c.MODULES_LOADED && delete $c.MODULES_LOADED[info.name];
$c.DEBUG_MODE = $c.DEBUG_MODE || false;
$c.ERROR_TYPES = $c.ERROR_TYPES || [];
$c.MODULES_LOADED = $c.MODULES_LOADED || {};
$c.CONSOLE_COLORS = $c.CONSOLE_COLORS || {
RED: '\x1b[31m%s\x1b[0m',
GREEN: '\x1b[32m%s\x1b[0m',
YELLOW: '\x1b[33m%s\x1b[0m'
};
$c.globalize = craydent_globalize_1.default;
try {
// retrieve public and local IP Addresses
const nics = (0, craydent_include_1.default)('os').networkInterfaces();
for (let nic in nics) {
if (!nics.hasOwnProperty(nic)) {
/* istanbul ignore next */
continue;
}
// filter for address that is IPv4
let iface = nics[nic].filter(function (ic) {
return ic.family == 'IPv4';
})[0];
if (iface) {
if (nic.startsWith('lo')) {
$c.LOCAL_IP = iface.address;
}
else if (nic.startsWith('eth') || nic.startsWith('en')) {
$c.PUBLIC_IP = iface.address;
}
}
// break if local and public ips are found
if ($c.LOCAL_IP && $c.PUBLIC_IP) {
break;
}
}
}
catch (e) { }
}