smartenv/dist/smartenv.environment.js

57 lines
6.6 KiB
JavaScript

#!/usr/bin/env node
/// <reference path="typings/main.d.ts" />
/**
* Deals with the environment the current JS script is running in.
*/
var plugins = require("./smartenv.plugins");
var SmartenvClasses = require("./smartenv.classes");
var SmartenvObjectStorage = require("./smartenv.objectstorage");
var environment;
var envDetermined = 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';
}
environment = new SmartenvClasses.Environment(localRunTimeEnv, localUserAgent);
})();
envDetermined = true; // ensure code above only runs once
}
;
return environment;
};
/**
* 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);
}
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
console.log(Object.getOwnPropertyNames(SmartenvObjectStorage.obs.getAll()));
};
exports.init = function (objectArg) {
objectArg.getEnv = getEnv;
objectArg.printEnv = printEnv;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZW52LmVudmlyb25tZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQztBQUMxQzs7R0FFRztBQUNILElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFDL0MsSUFBTyxlQUFlLFdBQVcsb0JBQW9CLENBQUMsQ0FBQztBQUN2RCxJQUFPLHFCQUFxQixXQUFXLDBCQUEwQixDQUFDLENBQUM7QUFHbkUsSUFBSSxXQUF1QyxD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