update smartenv to support os information on nodejs
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import * as plugins from './smartenv.plugins'
|
||||
import helpers = require('./smartenv.envhelpers')
|
||||
|
||||
// interfaces
|
||||
export interface IEnvObject {
|
||||
@ -8,28 +7,81 @@ export interface IEnvObject {
|
||||
}
|
||||
|
||||
export class Smartenv {
|
||||
runtimeEnv: string
|
||||
isBrowser: boolean
|
||||
userAgent: string
|
||||
isNode: boolean
|
||||
nodeVersion: string
|
||||
isCI: boolean
|
||||
constructor() {
|
||||
this.runtimeEnv = helpers.getEnvString()
|
||||
this.isBrowser = helpers.isBrowser()
|
||||
this.userAgent = helpers.getUserAgentString()
|
||||
this.isNode = helpers.isNode()
|
||||
this.nodeVersion = helpers.getNodeVersion()
|
||||
this.isCI = helpers.isCI()
|
||||
};
|
||||
|
||||
get runtimeEnv () {
|
||||
if (typeof window !== 'undefined') {
|
||||
return 'browser'
|
||||
} else if (typeof process !== 'undefined') {
|
||||
return 'node'
|
||||
}
|
||||
}
|
||||
|
||||
get isBrowser (): boolean {
|
||||
return !this.isNode
|
||||
}
|
||||
|
||||
get userAgent (): string {
|
||||
if (this.isBrowser) { // make sure we are in Browser
|
||||
return navigator.userAgent
|
||||
} else {
|
||||
return 'undefined'
|
||||
}
|
||||
}
|
||||
|
||||
get isNode ():boolean {
|
||||
return this.runtimeEnv === 'node'
|
||||
}
|
||||
|
||||
get nodeVersion ():string {
|
||||
return process.version
|
||||
}
|
||||
|
||||
get isCI (): boolean {
|
||||
if (this.isNode) {
|
||||
if (process.env.CI) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
};
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async isMacAsync (): Promise<boolean> {
|
||||
if(this.isNode) {
|
||||
let os = await import('os')
|
||||
return os.platform() === 'darwin'
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async isWindowsAsync (): Promise<boolean> {
|
||||
if(this.isNode) {
|
||||
let os = await import('os')
|
||||
return os.platform() === 'win32'
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async isLinuxAsync (): Promise<boolean> {
|
||||
if(this.isNode) {
|
||||
let os = await import('os')
|
||||
return os.platform() === 'linux'
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get environment variables that fit the description
|
||||
*/
|
||||
async getEnvVars (regexArg: RegExp) {
|
||||
let EnvironmentArray = []
|
||||
// TODO: plugins.smartparam.forEachMinimatch()
|
||||
}
|
||||
// get envVars (regexArg: RegExp) {
|
||||
// let EnvironmentArray = []
|
||||
// // TODO: plugins.smartparam.forEachMinimatch()
|
||||
// }
|
||||
|
||||
/**
|
||||
* prints the environment to console
|
||||
|
@ -1,39 +0,0 @@
|
||||
import * as plugins from './smartenv.plugins'
|
||||
export let getEnvString = function (): string {
|
||||
if (typeof window !== 'undefined') {
|
||||
return 'browser'
|
||||
} else if (typeof process !== 'undefined') {
|
||||
return 'node'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the user agent string in a browser
|
||||
*/
|
||||
export let getUserAgentString = function (): string {
|
||||
if (isBrowser()) { // make sure we are in Browser
|
||||
return navigator.userAgent
|
||||
} else {
|
||||
return 'undefined'
|
||||
}
|
||||
}
|
||||
|
||||
export let isNode = function (): boolean {
|
||||
return getEnvString() === 'node'
|
||||
}
|
||||
|
||||
export let getNodeVersion = function (): string {
|
||||
return process.version
|
||||
}
|
||||
|
||||
export let isBrowser = function (): boolean {
|
||||
return !isNode()
|
||||
}
|
||||
|
||||
export let isCI = function () {
|
||||
if (process.env.CI) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
};
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import 'typings-global'
|
||||
import * as smartparam from 'smartparam'
|
||||
import * as smartq from 'smartq'
|
||||
import * as lodash from 'lodash'
|
||||
|
Reference in New Issue
Block a user