Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
fdba21d60d | |||
c17ebca309 | |||
a014dcf1ab | |||
44bee7bf6f | |||
7841917058 | |||
f5a674f98d | |||
80ece7c093 | |||
39250b3d47 | |||
ed78c0becf | |||
63c103fde5 | |||
88003bde0f | |||
276a0641e8 | |||
b166269cb4 | |||
3ca1b425bf | |||
ffc07da665 | |||
be2adaf259 | |||
7aa9637826 | |||
a3c4f87741 | |||
f005f57764 | |||
6e418cdbf8 | |||
87155900e1 | |||
d24b11f737 | |||
17ebd58951 | |||
32bd229f91 | |||
4e5ddf8411 | |||
701c7c1b8b | |||
9a272def16 | |||
0213950aae |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
108
.gitlab-ci.yml
108
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,60 +18,74 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -79,33 +93,39 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -113,5 +133,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
28
README.md
28
README.md
@ -1,28 +0,0 @@
|
|||||||
# @pushrocks/smartenv
|
|
||||||
store things about your environment and let them travel across modules
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartenv)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartenv)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartenv)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartenv/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartenv/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartenv/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartenv)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartenv)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
@ -1,18 +1,15 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
|
||||||
"coverageTreshold": 60
|
|
||||||
},
|
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public"
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartenv",
|
"gitrepo": "smartenv",
|
||||||
"shortDescription": "store things about your environment and let them travel across modules",
|
"description": "store things about your environment and let them travel across modules",
|
||||||
"npmPackagename": "@pushrocks/smartenv",
|
"npmPackagename": "@pushrocks/smartenv",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
18885
package-lock.json
generated
18885
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
44
package.json
44
package.json
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartenv",
|
"name": "@pushrocks/smartenv",
|
||||||
"version": "4.0.4",
|
"version": "4.0.17",
|
||||||
"description": "store things about your environment and let them travel across modules",
|
"description": "store things about your environment and let them travel across modules",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)",
|
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
||||||
"testbrowser": "(npm test) && (node testbrowser.js)"
|
"testbrowser": "(npm test) && (node testbrowser.js)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -23,28 +24,33 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartenv",
|
"homepage": "https://gitlab.com/pushrocks/smartenv",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartparam": "^1.0.4",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@types/node": "^17.0.21"
|
||||||
"@types/node": "^12.0.8"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.56",
|
||||||
"@gitzone/tsrun": "^1.2.6",
|
"@gitzone/tsbundle": "^1.0.98",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tsrun": "^1.2.31",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@gitzone/tstest": "^1.0.68",
|
||||||
"@types/npm": "^2.0.29",
|
"@pushrocks/tapbundle": "^5.0.2",
|
||||||
"tslint": "^5.17.0",
|
"@types/npm": "^7.19.0",
|
||||||
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": false,
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"assets/*",
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
39
readme.md
Normal file
39
readme.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# @pushrocks/smartenv
|
||||||
|
store things about your environment and let them travel across modules
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartenv)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartenv)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartenv)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartenv/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
10
test/test.ts
10
test/test.ts
@ -1,5 +1,5 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as smartenv from '../ts/index';
|
import * as smartenv from '../ts/index.js';
|
||||||
|
|
||||||
let testEnv: smartenv.Smartenv;
|
let testEnv: smartenv.Smartenv;
|
||||||
|
|
||||||
@ -17,20 +17,20 @@ tap.test('should get os', async () => {
|
|||||||
const resultWindows = await testEnv.isWindowsAsync();
|
const resultWindows = await testEnv.isWindowsAsync();
|
||||||
const osModule = await import('os');
|
const osModule = await import('os');
|
||||||
if (resultMac) {
|
if (resultMac) {
|
||||||
expect(osModule.platform()).to.equal('darwin');
|
expect(osModule.platform()).toEqual('darwin');
|
||||||
console.log('platform is Mac!');
|
console.log('platform is Mac!');
|
||||||
} else if (resultLinux) {
|
} else if (resultLinux) {
|
||||||
expect(osModule.platform()).to.equal('linux');
|
expect(osModule.platform()).toEqual('linux');
|
||||||
console.log('platform is Linux!');
|
console.log('platform is Linux!');
|
||||||
} else {
|
} else {
|
||||||
expect(osModule.platform()).to.equal('win32');
|
expect(osModule.platform()).toEqual('win32');
|
||||||
console.log('platform is Windows!');
|
console.log('platform is Windows!');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should state wether we are in CI', async () => {
|
tap.test('should state wether we are in CI', async () => {
|
||||||
if (process.env.CI) {
|
if (process.env.CI) {
|
||||||
expect(testEnv.isCI).to.be.true;
|
expect(testEnv.isCI).toBeTrue();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
export * from './smartenv.classes.smartenv';
|
export * from './smartenv.classes.smartenv.js';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as plugins from './smartenv.plugins';
|
import * as plugins from './smartenv.plugins.js';
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
export interface IEnvObject {
|
export interface IEnvObject {
|
||||||
@ -11,7 +11,60 @@ export interface IEnvObject {
|
|||||||
* Smartenv class that makes it easy
|
* Smartenv class that makes it easy
|
||||||
*/
|
*/
|
||||||
export class Smartenv {
|
export class Smartenv {
|
||||||
get runtimeEnv() {
|
public async getEnvAwareModule(optionsArg: {
|
||||||
|
nodeModuleName: string;
|
||||||
|
webUrlArg: string;
|
||||||
|
getFunction: () => any;
|
||||||
|
}) {
|
||||||
|
if (this.isNode) {
|
||||||
|
const moduleResult = await this.getSafeNodeModule(optionsArg.nodeModuleName);
|
||||||
|
return moduleResult;
|
||||||
|
} else if (this.isBrowser) {
|
||||||
|
const moduleResult = await this.getSafeWebModule(optionsArg.webUrlArg, optionsArg.getFunction);
|
||||||
|
} else {
|
||||||
|
console.error('platform for loading not supported by smartenv');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getSafeNodeModule<T = any>(moduleNameArg: string): Promise<T> {
|
||||||
|
if (!this.isNode) {
|
||||||
|
console.error('You tried to load a node module in a wrong context');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// tslint:disable-next-line: function-constructor
|
||||||
|
return (new Function(`return import('${moduleNameArg}')`))() as Promise<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public loadedScripts: string[] = [];
|
||||||
|
public async getSafeWebModule(urlArg: string, getFunctionArg: () => any) {
|
||||||
|
if (!this.isBrowser) {
|
||||||
|
console.error('You tried to load a web module in a wrong context');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.loadedScripts.includes(urlArg)) {
|
||||||
|
return getFunctionArg();
|
||||||
|
} else {
|
||||||
|
this.loadedScripts.push(urlArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const done = plugins.smartpromise.defer();
|
||||||
|
if (globalThis.importScripts) {
|
||||||
|
globalThis.importScripts(urlArg);
|
||||||
|
done.resolve();
|
||||||
|
} else {
|
||||||
|
const script = document.createElement('script');
|
||||||
|
script.onload = () => {
|
||||||
|
done.resolve();
|
||||||
|
};
|
||||||
|
script.src = urlArg;
|
||||||
|
document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
await done.promise;
|
||||||
|
return getFunctionArg();
|
||||||
|
}
|
||||||
|
|
||||||
|
public get runtimeEnv() {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
return 'browser';
|
return 'browser';
|
||||||
} else if (typeof process !== 'undefined') {
|
} else if (typeof process !== 'undefined') {
|
||||||
@ -19,11 +72,11 @@ export class Smartenv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get isBrowser(): boolean {
|
public get isBrowser(): boolean {
|
||||||
return !this.isNode;
|
return !this.isNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
get userAgent(): string {
|
public get userAgent(): string {
|
||||||
if (this.isBrowser) {
|
if (this.isBrowser) {
|
||||||
// make sure we are in Browser
|
// make sure we are in Browser
|
||||||
return navigator.userAgent;
|
return navigator.userAgent;
|
||||||
@ -32,15 +85,15 @@ export class Smartenv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get isNode(): boolean {
|
public get isNode(): boolean {
|
||||||
return this.runtimeEnv === 'node';
|
return this.runtimeEnv === 'node';
|
||||||
}
|
}
|
||||||
|
|
||||||
get nodeVersion(): string {
|
public get nodeVersion(): string {
|
||||||
return process.version;
|
return process.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isCI(): boolean {
|
public get isCI(): boolean {
|
||||||
if (this.isNode) {
|
if (this.isNode) {
|
||||||
if (process.env.CI) {
|
if (process.env.CI) {
|
||||||
return true;
|
return true;
|
||||||
@ -52,50 +105,41 @@ export class Smartenv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async isMacAsync(): Promise<boolean> {
|
public async isMacAsync(): Promise<boolean> {
|
||||||
if (this.isNode) {
|
if (this.isNode) {
|
||||||
let os = await import('os');
|
const os = await this.getSafeNodeModule('os');
|
||||||
return os.platform() === 'darwin';
|
return os.platform() === 'darwin';
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async isWindowsAsync(): Promise<boolean> {
|
public async isWindowsAsync(): Promise<boolean> {
|
||||||
if (this.isNode) {
|
if (this.isNode) {
|
||||||
let os = await import('os');
|
const os = await this.getSafeNodeModule('os');
|
||||||
return os.platform() === 'win32';
|
return os.platform() === 'win32';
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async isLinuxAsync(): Promise<boolean> {
|
public async isLinuxAsync(): Promise<boolean> {
|
||||||
if (this.isNode) {
|
if (this.isNode) {
|
||||||
let os = await import('os');
|
const os = await this.getSafeNodeModule('os');
|
||||||
return os.platform() === 'linux';
|
return os.platform() === 'linux';
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* get environment variables that fit the description
|
|
||||||
*/
|
|
||||||
// get envVars (regexArg: RegExp) {
|
|
||||||
// let EnvironmentArray = []
|
|
||||||
// // TODO: plugins.smartparam.forEachMinimatch()
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prints the environment to console
|
* prints the environment to console
|
||||||
*/
|
*/
|
||||||
async printEnv() {
|
public async printEnv() {
|
||||||
if (this.isNode) {
|
if (this.isNode) {
|
||||||
console.log('running on NODE');
|
console.log('running on NODE');
|
||||||
let smartenvVersion = require('../package.json').version;
|
|
||||||
console.log(
|
console.log(
|
||||||
'node version is ' + this.nodeVersion + ' and smartenv version is ' + smartenvVersion
|
'node version is ' + this.nodeVersion
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log('running on BROWSER');
|
console.log('running on BROWSER');
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as smartparam from '@pushrocks/smartparam';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartq from '@pushrocks/smartpromise';
|
|
||||||
|
|
||||||
export { smartparam, smartq };
|
export { smartpromise };
|
||||||
|
Reference in New Issue
Block a user