| 
									
										
										
										
											2015-11-30 19:58:35 +01:00
										 |  |  | /// <reference path="index.ts" />
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Deals with the environment the current JS script is running in. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | module SmartenvEnvironment { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 15:23:48 +01:00
										 |  |  |     var environment:Environment; | 
					
						
							|  |  |  |     var envDetermined:boolean = false; | 
					
						
							| 
									
										
										
										
											2015-11-30 19:58:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 15:23:48 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * 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'; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 environment = new Environment(localRunTimeEnv,localUserAgent); | 
					
						
							|  |  |  |             })(); | 
					
						
							| 
									
										
										
										
											2015-11-30 19:58:35 +01:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2015-12-02 15:23:48 +01:00
										 |  |  |         return environment; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * prints the environment to console | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     var  printEnv = function() { | 
					
						
							|  |  |  |         if (this.getEnv().isNode) { | 
					
						
							|  |  |  |             var smartenvVersion = require("./package.json").version; | 
					
						
							|  |  |  |             plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             plugins.beautylog.log("browser is " + this.getEnv().userAgent) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         plugins.beautylog.log("the smartenv registration store currently holds the following properties:"); | 
					
						
							|  |  |  |         console.log(Object.getOwnPropertyNames(smartenv.obs.getComplete())); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     export var init = function(objectArg) { | 
					
						
							|  |  |  |         objectArg.getEnv = getEnv; | 
					
						
							|  |  |  |         objectArg.printEnv = printEnv; | 
					
						
							| 
									
										
										
										
											2015-11-30 19:58:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } |