smartenv/dist/smartenv.classes.smartenv.js

109 lines
6.3 KiB
JavaScript

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
class Smartenv {
get runtimeEnv() {
if (typeof window !== 'undefined') {
return 'browser';
}
else if (typeof process !== 'undefined') {
return 'node';
}
}
get isBrowser() {
return !this.isNode;
}
get userAgent() {
if (this.isBrowser) {
return navigator.userAgent;
}
else {
return 'undefined';
}
}
get isNode() {
return this.runtimeEnv === 'node';
}
get nodeVersion() {
return process.version;
}
get isCI() {
if (this.isNode) {
if (process.env.CI) {
return true;
}
else {
return false;
}
;
}
else {
return false;
}
}
isMacAsync() {
return __awaiter(this, void 0, void 0, function* () {
if (this.isNode) {
let os = yield Promise.resolve().then(() => require('os'));
return os.platform() === 'darwin';
}
else {
return false;
}
});
}
isWindowsAsync() {
return __awaiter(this, void 0, void 0, function* () {
if (this.isNode) {
let os = yield Promise.resolve().then(() => require('os'));
return os.platform() === 'win32';
}
else {
return false;
}
});
}
isLinuxAsync() {
return __awaiter(this, void 0, void 0, function* () {
if (this.isNode) {
let os = yield Promise.resolve().then(() => require('os'));
return os.platform() === 'linux';
}
else {
return false;
}
});
}
/**
* get environment variables that fit the description
*/
// get envVars (regexArg: RegExp) {
// let EnvironmentArray = []
// // TODO: plugins.smartparam.forEachMinimatch()
// }
/**
* prints the environment to console
*/
printEnv() {
return __awaiter(this, void 0, void 0, function* () {
if (this.isNode) {
console.log('running on NODE');
let smartenvVersion = require('../package.json').version;
console.log('node version is ' + this.nodeVersion + ' and smartenv version is ' + smartenvVersion);
}
else {
console.log('running on BROWSER');
console.log('browser is ' + this.userAgent);
}
});
}
}
exports.Smartenv = Smartenv;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYuY2xhc3Nlcy5zbWFydGVudi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZW52LmNsYXNzZXMuc21hcnRlbnYudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQVFBO0lBRUUsSUFBSSxVQUFVO1FBQ1osRUFBRSxDQUFDLENBQUMsT0FBTyxNQUFNLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNsQyxNQUFNLENBQUMsU0FBUyxDQUFBO1FBQ2xCLENBQUM7UUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsT0FBTyxPQUFPLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztZQUMxQyxNQUFNLENBQUMsTUFBTSxDQUFBO1FBQ2YsQ0FBQztJQUNILENBQUM7SUFFRCxJQUFJLFNBQVM7UUFDWCxNQUFNLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFBO0lBQ3JCLENBQUM7SUFFRCxJQUFJLFNBQVM7UUFDWCxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUMsQ0FBQztZQUNuQixNQUFNLENBQUMsU0FBUyxDQUFDLFNBQVMsQ0FBQTtRQUM1QixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixNQUFNLENBQUMsV0FBVyxDQUFBO1FBQ3BCLENBQUM7SUFDSCxDQUFDO0lBRUQsSUFBSSxNQUFNO1FBQ1IsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUFVLEtBQUssTUFBTSxDQUFBO0lBQ25DLENBQUM7SUFFRCxJQUFJLFdBQVc7UUFDYixNQUFNLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0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