2016-02-17 20:44:40 +00:00
|
|
|
/// <reference path="typings/main.d.ts" />
|
2015-11-30 18:58:35 +00:00
|
|
|
/**
|
|
|
|
* Deals with the environment the current JS script is running in.
|
|
|
|
*/
|
2016-02-17 20:44:40 +00:00
|
|
|
import plugins = require("./smartenv.plugins");
|
2016-02-18 12:27:45 +00:00
|
|
|
import classes = require("./smartenv.classes");
|
|
|
|
import objectStorage = require("./smartenv.objectstorage");
|
2015-11-30 18:58:35 +00:00
|
|
|
|
|
|
|
|
2016-02-18 12:27:45 +00:00
|
|
|
var environment:classes.Environment;
|
2016-02-17 20:44:40 +00:00
|
|
|
var envDetermined:boolean = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns the environment
|
|
|
|
* @returns {Environment}
|
|
|
|
*/
|
|
|
|
var getEnv = function(){
|
|
|
|
if (!envDetermined) {
|
|
|
|
(function() {
|
|
|
|
var localRunTimeEnv = "undefined";
|
|
|
|
var localUserAgent = "undefined";
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
localRunTimeEnv = 'browser';
|
|
|
|
localUserAgent = navigator.userAgent;
|
|
|
|
} else if (typeof process !== "undefined") {
|
|
|
|
localRunTimeEnv = 'node';
|
|
|
|
}
|
2016-02-18 12:27:45 +00:00
|
|
|
environment = new classes.Environment(localRunTimeEnv,localUserAgent);
|
2016-02-17 20:44:40 +00:00
|
|
|
})();
|
|
|
|
envDetermined = true; // ensure code above only runs once
|
2015-12-02 14:23:48 +00:00
|
|
|
};
|
2016-02-17 20:44:40 +00:00
|
|
|
return environment;
|
|
|
|
};
|
2015-12-02 14:23:48 +00:00
|
|
|
|
2016-02-17 20:44:40 +00:00
|
|
|
/**
|
|
|
|
* prints the environment to console
|
|
|
|
*/
|
|
|
|
var printEnv = function() {
|
|
|
|
if (this.getEnv().isNode) {
|
|
|
|
plugins.beautylog.ok("running on NODE");
|
|
|
|
var smartenvVersion = require("../package.json").version;
|
|
|
|
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.ok("running on BROWSER");
|
|
|
|
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
|
2015-12-02 14:23:48 +00:00
|
|
|
}
|
2016-02-17 20:44:40 +00:00
|
|
|
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
|
2016-02-18 12:27:45 +00:00
|
|
|
console.log(Object.getOwnPropertyNames(objectStorage.obs.getAll()));
|
2016-02-17 20:44:40 +00:00
|
|
|
};
|
2015-12-02 14:23:48 +00:00
|
|
|
|
2016-02-17 20:44:40 +00:00
|
|
|
export var init = function(objectArg) {
|
|
|
|
objectArg.getEnv = getEnv;
|
|
|
|
objectArg.printEnv = printEnv;
|
|
|
|
};
|