Compare commits

..

22 Commits

Author SHA1 Message Date
d5c2d167ec 5.0.0 2022-03-16 16:10:47 +01:00
2af6d5a974 4.0.18 2022-03-16 16:10:09 +01:00
fdba21d60d 4.0.17 2022-03-16 16:09:25 +01:00
c17ebca309 fix(core): update 2022-03-16 16:09:24 +01:00
a014dcf1ab 4.0.16 2020-10-13 20:09:15 +00:00
44bee7bf6f fix(core): update 2020-10-13 20:09:15 +00:00
7841917058 4.0.15 2020-09-29 19:29:51 +00:00
f5a674f98d fix(core): update 2020-09-29 19:29:50 +00:00
80ece7c093 4.0.14 2020-09-29 19:10:00 +00:00
39250b3d47 fix(core): update 2020-09-29 19:10:00 +00:00
ed78c0becf 4.0.13 2020-09-29 18:38:22 +00:00
63c103fde5 fix(core): update 2020-09-29 18:38:21 +00:00
88003bde0f 4.0.12 2020-09-29 17:49:34 +00:00
276a0641e8 fix(core): update 2020-09-29 17:49:33 +00:00
b166269cb4 4.0.11 2020-09-29 10:23:08 +00:00
3ca1b425bf fix(core): update 2020-09-29 10:23:07 +00:00
ffc07da665 4.0.10 2020-06-25 23:00:33 +00:00
be2adaf259 fix(core): update 2020-06-25 23:00:32 +00:00
7aa9637826 4.0.9 2020-06-25 22:26:05 +00:00
a3c4f87741 fix(core): update 2020-06-25 22:26:04 +00:00
f005f57764 4.0.8 2020-06-25 22:23:10 +00:00
6e418cdbf8 fix(core): update 2020-06-25 22:23:10 +00:00
13 changed files with 18123 additions and 948 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@ -1,18 +1,16 @@
# gitzone ci_default # gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
variables:
GIT_STRATEGY: clone
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
@ -21,57 +19,71 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless
- docker - docker
- notpriv - 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
- priv
testBuild: testBuild:
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 command npm run build - 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 lts - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
@ -81,11 +93,15 @@ 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:
- lossless
- docker - docker
- priv - priv
@ -96,20 +112,20 @@ trigger:
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
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:

29
.vscode/launch.json vendored Normal file
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@ -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
[![build status](https://gitlab.com/pushrocks/smartenv/badges/master/build.svg)](https://gitlab.com/pushrocks/smartenv/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartenv/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartenv/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartenv.svg)](https://www.npmjs.com/package/@pushrocks/smartenv)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartenv/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartenv)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](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)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -4,11 +4,12 @@
"npmAccessLevel": "public" "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"
} }

18687
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
{ {
"name": "@pushrocks/smartenv", "name": "@pushrocks/smartenv",
"version": "4.0.8", "version": "5.0.0",
"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,30 +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.6", "@types/node": "^17.0.21"
"@types/node": "^12.12.7",
"is-wsl": "^2.1.1"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.56",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsbundle": "^1.0.98",
"@gitzone/tstest": "^1.0.28", "@gitzone/tsrun": "^1.2.31",
"@pushrocks/tapbundle": "^3.0.13", "@gitzone/tstest": "^1.0.68",
"@types/npm": "^2.0.31", "@pushrocks/tapbundle": "^5.0.2",
"tslint": "^5.20.1", "@types/npm": "^7.19.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"private": false, "private": false,
"files": [ "files": [
"ts/*", "ts/**/*",
"ts_web/*", "ts_web/**/*",
"dist/*", "dist/**/*",
"dist_web/*", "dist_*/**/*",
"dist_ts_web/*", "dist_ts/**/*",
"assets/*", "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
View 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 | [![pipeline status](https://gitlab.com/pushrocks/smartenv/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartenv/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartenv)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartenv)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartenv)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartenv)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartenv)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](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)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -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();
} }
}); });

View File

@ -1 +1 @@
export * from './smartenv.classes.smartenv'; export * from './smartenv.classes.smartenv.js';

View File

@ -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,6 +11,59 @@ export interface IEnvObject {
* Smartenv class that makes it easy * Smartenv class that makes it easy
*/ */
export class Smartenv { export class Smartenv {
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() { public get runtimeEnv() {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
return 'browser'; return 'browser';
@ -36,10 +89,6 @@ export class Smartenv {
return this.runtimeEnv === 'node'; return this.runtimeEnv === 'node';
} }
public get isWsl(): boolean {
return plugins.isWsl;
}
public get nodeVersion(): string { public get nodeVersion(): string {
return process.version; return process.version;
} }
@ -58,7 +107,7 @@ export class Smartenv {
public async isMacAsync(): Promise<boolean> { public async isMacAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = await import('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'darwin'; return os.platform() === 'darwin';
} else { } else {
return false; return false;
@ -67,7 +116,7 @@ export class Smartenv {
public async isWindowsAsync(): Promise<boolean> { public async isWindowsAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = await import('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'win32'; return os.platform() === 'win32';
} else { } else {
return false; return false;
@ -76,30 +125,21 @@ export class Smartenv {
public async isLinuxAsync(): Promise<boolean> { public async isLinuxAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const 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
*/ */
public async printEnv() { public async printEnv() {
if (this.isNode) { if (this.isNode) {
console.log('running on NODE'); console.log('running on NODE');
const 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');

View File

@ -1,12 +1,3 @@
import * as smartparam from '@pushrocks/smartparam';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
export { smartparam, smartpromise }; export { smartpromise };
// third party scope
import isWsl from 'is-wsl';
export {
isWsl
};