#!/usr/bin/env node /// /** * Deals with the environment the current JS script is running in. */ var plugins = require("./smartenv.plugins"); var classes = require("./smartenv.classes"); var objectStorage = 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 classes.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(objectStorage.obs.getAll())); }; exports.init = function (objectArg) { objectArg.getEnv = getEnv; objectArg.printEnv = printEnv; }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZW52LmVudmlyb25tZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQztBQUMxQzs7R0FFRztBQUNILElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFDL0MsSUFBTyxPQUFPLFdBQVcsb0JBQW9CLENBQUMsQ0FBQztBQUMvQyxJQUFPLGFBQWEsV0FBVywwQkFBMEIsQ0FBQyxDQUFDO0FBRzNELElBQUksV0FBK0IsQ0FBQztBQUNwQyxJQUFJLGFBQWEsR0FBVyxLQUFLLENBQUM7QUFFbEM7OztHQUdHO0FBQ0gsSUFBSSxNQUFNLEdBQUc7SUFDVCxFQUFFLENBQUMsQ0FBQyxD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