2015-11-30 18:58:35 +00:00
|
|
|
/// <reference path="index.ts" />
|
|
|
|
/**
|
|
|
|
* Deals with the environment the current JS script is running in.
|
|
|
|
*/
|
|
|
|
module SmartenvEnvironment {
|
|
|
|
|
2015-12-02 14:23:48 +00:00
|
|
|
var environment:Environment;
|
|
|
|
var envDetermined:boolean = false;
|
2015-11-30 18:58:35 +00:00
|
|
|
|
2015-12-02 14:23:48 +00:00
|
|
|
/**
|
|
|
|
* 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-11-30 18:58:35 +00:00
|
|
|
};
|
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");
|
|
|
|
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
|
2015-12-02 14:23:48 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export var init = function(objectArg) {
|
|
|
|
objectArg.getEnv = getEnv;
|
|
|
|
objectArg.printEnv = printEnv;
|
2015-11-30 18:58:35 +00:00
|
|
|
}
|
|
|
|
}
|