46 lines
5.0 KiB
JavaScript
46 lines
5.0 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 classes = require("./smartenv.classes");
|
|
var objectStorage = require("./smartenv.objectstorage");
|
|
var environment;
|
|
var envDetermined = false;
|
|
/**
|
|
* returns the environment
|
|
* @returns {Environment}
|
|
*/
|
|
var getEnv = function () {
|
|
if (!envDetermined) {
|
|
environment = new classes.Environment();
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZW52LmVudmlyb25tZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQztBQUMxQzs7R0FFRztBQUNILElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFDL0MsSUFBTyxPQUFPLFdBQVcsb0JBQW9CLENBQUMsQ0FBQztBQUMvQyxJQUFPLGFBQWEsV0FBVywwQkFBMEIsQ0FBQyxDQUFDO0FBRzNELElBQ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