streamline package

This commit is contained in:
2017-05-17 15:59:10 +02:00
parent 47f840841c
commit ab33e97c8d
24 changed files with 370 additions and 1883 deletions

View File

@ -1,10 +1 @@
import {getEnv, printEnv, getEnvVars} from './smartenv.export'
import { obs } from './smartenv.objectstorage'
export {
getEnv,
getEnvVars,
printEnv,
obs
}
export * from './smartenv.classes.smartenv'

View File

@ -1,22 +0,0 @@
import helpers = require('./smartenv.envhelpers')
export class Environment {
runtimeEnv: string
isBrowser: boolean
userAgent: string
isNode: boolean
nodeVersion: string
isCI: boolean
isTravis: boolean
isC9: 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()
this.isTravis = helpers.isTravis()
this.isC9 = helpers.isC9()
};
}

View File

@ -0,0 +1,47 @@
import * as plugins from './smartenv.plugins'
import helpers = require('./smartenv.envhelpers')
// interfaces
export interface IEnvObject {
name: string
value: string
}
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 environment variables that fit the description
*/
async getEnvVars (regexArg: RegExp) {
let EnvironmentArray = []
// TODO: plugins.smartparam.forEachMinimatch()
}
/**
* prints the environment to console
*/
async printEnv () {
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)
}
}
}

View File

@ -7,11 +7,14 @@ export let getEnvString = function (): string {
}
}
/**
* gets the user agent string in a browser
*/
export let getUserAgentString = function (): string {
if (isBrowser()) {
if (isBrowser()) { // make sure we are in Browser
return navigator.userAgent
} else {
return undefined
return 'undefined'
}
}
@ -34,19 +37,3 @@ export let isCI = function () {
return false
};
}
export let isC9 = function () {
if (process.env.C9_HOSTNAME) {
return true
} else {
return false
}
}
export let isTravis = function () {
if (process.env.TRAVIS) {
return true
} else {
return false
};
}

View File

@ -1,56 +0,0 @@
/**
* Deals with the environment the current JS script is running in.
*/
import * as plugins from './smartenv.plugins'
import * as classes from './smartenv.classes.environment'
import * as objectStorage from './smartenv.objectstorage'
let environment: classes.Environment = null
/**
* returns the environment
* @returns {Environment}
*/
export let getEnv = function () {
if (!environment) {
environment = new classes.Environment()
};
return environment
}
/**
* prints the environment to console
*/
export let printEnv = function () {
if (this.getEnv().isNode) {
console.log('running on NODE')
let smartenvVersion = require('../package.json').version
console.log('node version is ' + this.getEnv().nodeVersion + ' and smartenv version is ' + smartenvVersion)
} else {
console.log('running on BROWSER')
console.log('browser is ' + this.getEnv().userAgent)
}
console.log('the smartenv registration store currently holds the following properties:')
console.log(Object.getOwnPropertyNames(objectStorage.obs.getAll()))
}
export interface IEnvObject {
name: string
value: string
}
export let getEnvVars = async (regexArg: RegExp) => {
let resultArray: IEnvObject[] = []
for (let key in process.env) {
if (regexArg.test(key)) {
resultArray.push({
name: key,
value: process.env[key]
})
}
}
return resultArray
}

View File

@ -1,44 +0,0 @@
import plugins = require('./smartenv.plugins')
export let obsItems: any = {}
/**
* Objectstorage allows easy sharing of objects within node
*/
export let obs: any = {
add: (keyNameArg, objectArg) => {
if (!keyNameArg) {
console.log('keyName is undefined')
return
}
if (!objectArg) {
console.log('objectArg is undefined')
}
if (!(obsItems[ keyNameArg ])) {
obsItems[ keyNameArg ] = objectArg
} else {
console.log('object is already present, so add operation has failed.')
}
return obsItems[ keyNameArg ]
},
replace: function (paramNameArg, objectArg) {
obsItems[ paramNameArg ] = objectArg
},
merge: function (paramNameArg, objectArg) {
if (!(typeof obsItems[ paramNameArg ] === 'undefined')) {
obsItems[ paramNameArg ] = plugins.lodash.assign(obsItems[ paramNameArg ], objectArg)
} else {
console.log('object is not present, so there is nothing to merge')
}
},
get: function (keyName) {
return obsItems[ keyName ]
},
getAll: function () {
return obsItems
},
addComplete: function (itemsArg) {
obsItems = plugins.lodash.assign(obsItems, itemsArg)
return obsItems
}
}

View File

@ -1,8 +1,10 @@
import 'typings-global'
import * as smartparam from 'smartparam'
import * as smartq from 'smartq'
import * as lodash from 'lodash'
export {
smartq,
lodash
lodash,
smartparam,
smartq
}