smartenv/ts/smartenv.environment.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2015-11-30 18:58:35 +00:00
/**
* Deals with the environment the current JS script is running in.
*/
2016-11-21 10:58:37 +00:00
import * as plugins from './smartenv.plugins'
import * as classes from './smartenv.classes'
import * as objectStorage from './smartenv.objectstorage'
2015-11-30 18:58:35 +00:00
2016-11-21 10:58:37 +00:00
let environment: classes.Environment
let envDetermined: boolean = false
2016-02-17 20:44:40 +00:00
/**
* returns the environment
* @returns {Environment}
*/
2016-02-20 09:50:32 +00:00
export var getEnv = function(){
2016-02-17 20:44:40 +00:00
if (!envDetermined) {
2016-11-21 10:58:37 +00:00
environment = new classes.Environment()
envDetermined = true // ensure code above only runs once
2015-12-02 14:23:48 +00:00
};
2016-11-21 10:58:37 +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
*/
2016-02-20 09:50:32 +00:00
export var printEnv = function() {
2016-02-17 20:44:40 +00:00
if (this.getEnv().isNode) {
2016-11-21 10:58:37 +00:00
console.log('running on NODE')
let smartenvVersion = require('../package.json').version
console.log('node version is ' + this.getEnv().nodeVersion + ' and smartenv version is ' + smartenvVersion)
2016-02-17 20:44:40 +00:00
} else {
2016-11-21 10:58:37 +00:00
console.log('running on BROWSER')
console.log('browser is ' + this.getEnv().userAgent)
2015-12-02 14:23:48 +00:00
}
2016-11-21 10:58:37 +00:00
console.log('the smartenv registration store currently holds the following properties:')
console.log(Object.getOwnPropertyNames(objectStorage.obs.getAll()))
}