2015-11-30 14:04:04 +00:00
|
|
|
/// <reference path="index.ts" />
|
|
|
|
var Environment = (function () {
|
|
|
|
function Environment(runtimeEnvArg, userAgentArg) {
|
|
|
|
if (userAgentArg === void 0) { userAgentArg = "undefined"; }
|
|
|
|
this.runtimeEnv = runtimeEnvArg;
|
|
|
|
this.userAgent = userAgentArg;
|
|
|
|
if (runtimeEnvArg == "node") {
|
|
|
|
this.isBrowser = false;
|
|
|
|
this.isNode = true;
|
|
|
|
this.nodeVersion = process.version;
|
|
|
|
}
|
2015-12-24 23:22:28 +00:00
|
|
|
else if (runtimeEnvArg == "browser") {
|
2015-11-30 14:04:04 +00:00
|
|
|
this.isBrowser = true;
|
2015-12-24 23:22:28 +00:00
|
|
|
this.isNode = false;
|
2015-11-30 14:04:04 +00:00
|
|
|
this.nodeVersion = "undefined";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
return Environment;
|
|
|
|
})();
|
2015-11-30 18:58:35 +00:00
|
|
|
/// <reference path="index.ts" />
|
|
|
|
/**
|
|
|
|
* Deals with the environment the current JS script is running in.
|
|
|
|
*/
|
|
|
|
var SmartenvEnvironment;
|
|
|
|
(function (SmartenvEnvironment) {
|
2015-12-02 14:23:48 +00:00
|
|
|
var environment;
|
|
|
|
var envDetermined = false;
|
|
|
|
/**
|
|
|
|
* returns the environment
|
|
|
|
* @returns {Environment}
|
|
|
|
*/
|
|
|
|
var getEnv = function () {
|
|
|
|
if (!envDetermined) {
|
|
|
|
(function () {
|
|
|
|
var localRunTimeEnv = "undefined";
|
|
|
|
var localUserAgent = "undefined";
|
2015-12-24 23:22:28 +00:00
|
|
|
if (typeof window !== "undefined") {
|
2015-12-02 14:23:48 +00:00
|
|
|
localRunTimeEnv = 'browser';
|
|
|
|
localUserAgent = navigator.userAgent;
|
|
|
|
}
|
2015-12-24 23:22:28 +00:00
|
|
|
else if (typeof process !== "undefined") {
|
2015-12-02 14:23:48 +00:00
|
|
|
localRunTimeEnv = 'node';
|
|
|
|
}
|
|
|
|
environment = new Environment(localRunTimeEnv, localUserAgent);
|
|
|
|
})();
|
2015-12-24 23:22:28 +00:00
|
|
|
envDetermined = true; // ensure code above only runs once
|
2015-12-02 14:23:48 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
return environment;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* prints the environment to console
|
|
|
|
*/
|
|
|
|
var printEnv = function () {
|
|
|
|
if (this.getEnv().isNode) {
|
2015-12-24 23:22:28 +00:00
|
|
|
plugins.beautylog.ok("running on NODE");
|
2015-12-02 14:23:48 +00:00
|
|
|
var smartenvVersion = require("./package.json").version;
|
|
|
|
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
|
|
|
|
}
|
|
|
|
else {
|
2015-12-24 23:22:28 +00:00
|
|
|
plugins.beautylog.ok("running on BROWSER");
|
2015-12-02 14:23:48 +00:00
|
|
|
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
|
|
|
|
}
|
|
|
|
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
|
2015-12-02 14:32:58 +00:00
|
|
|
console.log(Object.getOwnPropertyNames(smartenv.obs.getAll()));
|
2015-12-02 14:23:48 +00:00
|
|
|
};
|
|
|
|
SmartenvEnvironment.init = function (objectArg) {
|
|
|
|
objectArg.getEnv = getEnv;
|
|
|
|
objectArg.printEnv = printEnv;
|
|
|
|
};
|
2015-11-30 18:58:35 +00:00
|
|
|
})(SmartenvEnvironment || (SmartenvEnvironment = {}));
|
|
|
|
/// <reference path="index.ts" />
|
|
|
|
var SmartenvObjectStorage;
|
|
|
|
(function (SmartenvObjectStorage) {
|
|
|
|
function init() {
|
2015-12-10 14:52:14 +00:00
|
|
|
var obs = {
|
|
|
|
add: function (paramNameArg, objectArg) {
|
|
|
|
if (paramNameArg === void 0) { paramNameArg = "undefined"; }
|
|
|
|
if (objectArg === void 0) { objectArg = "undefined"; }
|
|
|
|
if (paramNameArg == "undefined") {
|
|
|
|
plugins.beautylog.error("paramName is undefined");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (objectArg == "undefined") {
|
|
|
|
plugins.beautylog.error("objectArg is undefined");
|
|
|
|
}
|
|
|
|
if (typeof obsItems[paramNameArg] === "undefined") {
|
|
|
|
obsItems[paramNameArg] = objectArg;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plugins.beautylog.error("object is already present, so add operation has failed.");
|
|
|
|
}
|
|
|
|
return obsItems[paramNameArg];
|
|
|
|
},
|
|
|
|
replace: function (paramNameArg, objectArg) {
|
|
|
|
obsItems[paramNameArg] = objectArg;
|
|
|
|
},
|
|
|
|
merge: function (paramNameArg, objectArg) {
|
|
|
|
if (!(typeof obsItems[paramNameArg] === "undefined")) {
|
|
|
|
obsItems[paramNameArg] = plugins._.assign(obsItems[paramNameArg], objectArg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plugins.beautylog.error("object is not present, so there is nothing to merge");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
get: function (keyName) {
|
|
|
|
return obsItems[keyName];
|
|
|
|
},
|
|
|
|
getAll: function () {
|
|
|
|
return obsItems;
|
|
|
|
},
|
|
|
|
addComplete: function (itemsArg) {
|
|
|
|
obsItems = plugins._.assign(obsItems, itemsArg);
|
|
|
|
return obsItems;
|
2015-12-06 20:49:57 +00:00
|
|
|
}
|
2015-11-30 18:58:35 +00:00
|
|
|
};
|
2015-12-10 14:52:14 +00:00
|
|
|
var obsItems = {};
|
2015-11-30 18:58:35 +00:00
|
|
|
return obs;
|
2015-11-30 14:04:04 +00:00
|
|
|
}
|
2015-11-30 18:58:35 +00:00
|
|
|
SmartenvObjectStorage.init = init;
|
|
|
|
})(SmartenvObjectStorage || (SmartenvObjectStorage = {}));
|
|
|
|
/// <reference path="typings/tsd.d.ts" />
|
|
|
|
/// <reference path="smartenv.classes.ts" />
|
|
|
|
/// <reference path="smartenv.environment.ts" />
|
|
|
|
/// <reference path="smartenv.objectstorage.ts" />
|
|
|
|
var plugins = {
|
|
|
|
beautylog: require("beautylog")("os"),
|
|
|
|
_: require("lodash")
|
2015-11-26 05:31:31 +00:00
|
|
|
};
|
2015-11-30 18:58:35 +00:00
|
|
|
var smartenv = {}; //create smartenv object
|
2015-12-02 14:23:48 +00:00
|
|
|
SmartenvEnvironment.init(smartenv);
|
2015-11-30 18:58:35 +00:00
|
|
|
smartenv.obs = SmartenvObjectStorage.init();
|
2015-11-26 05:31:31 +00:00
|
|
|
module.exports = smartenv;
|