Compare commits
54 Commits
Author | SHA1 | Date | |
---|---|---|---|
eaf379b119 | |||
0074938e57 | |||
eed1c75aba | |||
6de2f36964 | |||
76e777a3ac | |||
165cd3737e | |||
2f11d1ba0f | |||
33692ff417 | |||
f408337186 | |||
bd6d574226 | |||
d5c2d167ec | |||
2af6d5a974 | |||
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 | |||
b7342dbf05 | |||
677c8d33b9 | |||
ffc781011d | |||
aeec1b36a3 | |||
4c2e7f9446 | |||
dddad457f3 | |||
4f110c6e64 | |||
12d971c470 | |||
886c245e8d | |||
50d610e5df | |||
5edb62c134 | |||
38f22a6d95 | |||
91cdb71388 | |||
ab33e97c8d |
26
.gitignore
vendored
26
.gitignore
vendored
@ -1,14 +1,20 @@
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
#npm devug
|
||||
npm-debug.log
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
ts/typings/
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
test/browser/browserified/
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
@ -1,38 +1,70 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .yarn/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
@ -40,32 +72,57 @@ testSTABLE:
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage --publish gitlab
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
29
README.md
29
README.md
@ -1,29 +0,0 @@
|
||||
# smartenv
|
||||
store things about your environment and let them travel across modules
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartenv)
|
||||
[](https://GitLab.com/pushrocks/smartenv)
|
||||
[](https://github.com/pushrocks/smartenv)
|
||||
[](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/smartenv)
|
||||
[](https://david-dm.org/pushrocks/smartenv)
|
||||
[](https://www.bithound.io/github/pushrocks/smartenv/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartenv)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## 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://push.rocks)
|
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import { getEnv, printEnv, getEnvVars } from './smartenv.export';
|
||||
import { obs } from './smartenv.objectstorage';
|
||||
export { getEnv, getEnvVars, printEnv, obs };
|
9
dist/index.js
vendored
9
dist/index.js
vendored
@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const smartenv_export_1 = require("./smartenv.export");
|
||||
exports.getEnv = smartenv_export_1.getEnv;
|
||||
exports.printEnv = smartenv_export_1.printEnv;
|
||||
exports.getEnvVars = smartenv_export_1.getEnvVars;
|
||||
const smartenv_objectstorage_1 = require("./smartenv.objectstorage");
|
||||
exports.obs = smartenv_objectstorage_1.obs;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHVEQUE4RDtBQUs1RCxpQkFMTSx3QkFBTSxDQUtOO0FBRU4sbUJBUGMsMEJBQVEsQ0FPZDtBQURSLHFCQU53Qiw0QkFBVSxDQU14QjtBQUxaLHFFQUE4QztBQU81QyxjQVBPLDRCQUFHLENBT1AifQ==
|
11
dist/smartenv.classes.environment.d.ts
vendored
11
dist/smartenv.classes.environment.d.ts
vendored
@ -1,11 +0,0 @@
|
||||
export declare class Environment {
|
||||
runtimeEnv: string;
|
||||
isBrowser: boolean;
|
||||
userAgent: string;
|
||||
isNode: boolean;
|
||||
nodeVersion: string;
|
||||
isCI: boolean;
|
||||
isTravis: boolean;
|
||||
isC9: boolean;
|
||||
constructor();
|
||||
}
|
18
dist/smartenv.classes.environment.js
vendored
18
dist/smartenv.classes.environment.js
vendored
@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const helpers = require("./smartenv.envhelpers");
|
||||
class Environment {
|
||||
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();
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.Environment = Environment;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYuY2xhc3Nlcy5lbnZpcm9ubWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZW52LmNsYXNzZXMuZW52aXJvbm1lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxpREFBaUQ7QUFFakQ7SUFTRTtRQUNFLElBQUksQ0FBQyxVQUFVLEdBQUcsT0FBTyxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQ3hDLElBQUksQ0FBQyxTQUFTLEdBQUcsT0FBTyxDQUFDLFNBQVMsRUFBRSxDQUFBO1FBQ3BDLElBQUksQ0FBQyxTQUFTLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixFQUFFLENBQUE7UUFDN0MsSUFBSSxDQUFDLE1BQU0sR0FBRyxPQUFPLENBQUMsTUFBTSxFQUFFLENBQUE7UUFDOUIsSUFBSSxDQUFDLFdBQVcsR0FBRyxPQUFPLENBQUMsY0FBYyxFQUFFLENBQUE7UUFDM0MsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxFQUFFLENBQUE7UUFDMUIsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUMsUUFBUSxFQUFFLENBQUE7UUFDbEMsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxFQUFFLENBQUE7SUFDNUIsQ0FBQztJQUFBLENBQUM7Q0FDSDtBQW5CRCxrQ0FtQkMifQ==
|
8
dist/smartenv.envhelpers.d.ts
vendored
8
dist/smartenv.envhelpers.d.ts
vendored
@ -1,8 +0,0 @@
|
||||
export declare let getEnvString: () => string;
|
||||
export declare let getUserAgentString: () => string;
|
||||
export declare let isNode: () => boolean;
|
||||
export declare let getNodeVersion: () => string;
|
||||
export declare let isBrowser: () => boolean;
|
||||
export declare let isCI: () => boolean;
|
||||
export declare let isC9: () => boolean;
|
||||
export declare let isTravis: () => boolean;
|
54
dist/smartenv.envhelpers.js
vendored
54
dist/smartenv.envhelpers.js
vendored
@ -1,54 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEnvString = function () {
|
||||
if (typeof window !== 'undefined') {
|
||||
return 'browser';
|
||||
}
|
||||
else if (typeof process !== 'undefined') {
|
||||
return 'node';
|
||||
}
|
||||
};
|
||||
exports.getUserAgentString = function () {
|
||||
if (exports.isBrowser()) {
|
||||
return navigator.userAgent;
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
exports.isNode = function () {
|
||||
return exports.getEnvString() === 'node';
|
||||
};
|
||||
exports.getNodeVersion = function () {
|
||||
return process.version;
|
||||
};
|
||||
exports.isBrowser = function () {
|
||||
return !exports.isNode();
|
||||
};
|
||||
exports.isCI = function () {
|
||||
if (process.env.CI) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
;
|
||||
};
|
||||
exports.isC9 = function () {
|
||||
if (process.env.C9_HOSTNAME) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
exports.isTravis = function () {
|
||||
if (process.env.TRAVIS) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYuZW52aGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3N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QUNuQixNQUFNLENBQUMsSUFBSSxDQUFBO0lBQ2IsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ04sTUFBTSxDQUFDLEtBQUssQ0FBQTtJQUNkLENBQUM7SUFBQSxDQUFDO0FBQ0osQ0FBQyxDQUFBO0FBRVUsUUFBQSxJQUFJLEdBQUc7SUFDaEIsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFDO1FBQzVCLE1BQU0sQ0FBQyxJQUFJLENBQUE7SUFDYixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDTixNQUFNLENBQUMsS0FBSyxDQUFBO0lBQ2QsQ0FBQztBQUNILENBQUMsQ0FBQTtBQUVVLFFBQUEsUUFBUSxHQUFHO0lBQ3BCLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztRQUN2QixNQUFNLENBQUMsSUFBSSxDQUFBO0lBQ2IsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ04sTUFBTSxDQUFDLEtBQUssQ0FBQTtJQUNkLENBQUM7SUFBQSxDQUFDO0FBQ0osQ0FBQyxDQUFBIn0=
|
15
dist/smartenv.export.d.ts
vendored
15
dist/smartenv.export.d.ts
vendored
@ -1,15 +0,0 @@
|
||||
import * as classes from './smartenv.classes.environment';
|
||||
/**
|
||||
* returns the environment
|
||||
* @returns {Environment}
|
||||
*/
|
||||
export declare let getEnv: () => classes.Environment;
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
export declare let printEnv: () => void;
|
||||
export interface IEnvObject {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
export declare let getEnvVars: (regexArg: RegExp) => Promise<IEnvObject[]>;
|
53
dist/smartenv.export.js
vendored
53
dist/smartenv.export.js
vendored
@ -1,53 +0,0 @@
|
||||
"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 });
|
||||
const classes = require("./smartenv.classes.environment");
|
||||
const objectStorage = require("./smartenv.objectstorage");
|
||||
let environment = null;
|
||||
/**
|
||||
* returns the environment
|
||||
* @returns {Environment}
|
||||
*/
|
||||
exports.getEnv = function () {
|
||||
if (!environment) {
|
||||
environment = new classes.Environment();
|
||||
}
|
||||
;
|
||||
return environment;
|
||||
};
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
exports.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()));
|
||||
};
|
||||
exports.getEnvVars = (regexArg) => __awaiter(this, void 0, void 0, function* () {
|
||||
let resultArray = [];
|
||||
for (let key in process.env) {
|
||||
if (regexArg.test(key)) {
|
||||
resultArray.push({
|
||||
name: key,
|
||||
value: process.env[key]
|
||||
});
|
||||
}
|
||||
}
|
||||
return resultArray;
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYuZXhwb3J0LmpzIiwic291cmNlUm9vdCI6IiI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FPLENBQUMsR0FBRyxDQUFDLDJFQUEyRSxDQUFDLENBQUE7SUFDeEYsT0FBTyxDQUFDLEdBQUcsQ0FBQyxNQUFNLENBQUMsbUJBQW1CLENBQUMsYUFBYSxDQUFDLEdBQUcsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFDLENBQUE7QUFDckUsQ0FBQyxDQUFBO0FBT1UsUUFBQSxVQUFVLEdBQUcsQ0FBTyxRQUFnQjtJQUM3QyxJQUFJLFdBQVcsR0FBaUIsRUFBRSxDQUFBO0lBQ2xDLEdBQUcsQ0FBQyxDQUFDLElBQUksR0FBRyxJQUFJLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO1FBQzVCLEVBQUUsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBQ3ZCLFdBQVcsQ0FBQyxJQUFJLENBQUM7Z0JBQ2YsSUFBSSxFQUFFLEdBQUc7Z0JBQ1QsS0FBSyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDO2FBQ3hCLENBQUMsQ0FBQTtRQUNKLENBQUM7SUFDSCxDQUFDO0lBQ0QsTUFBTSxDQUFDLFdBQVcsQ0FBQTtBQUNwQixDQUFDLENBQUEsQ0FBQSJ9
|
5
dist/smartenv.objectstorage.d.ts
vendored
5
dist/smartenv.objectstorage.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
export declare let obsItems: any;
|
||||
/**
|
||||
* Objectstorage allows easy sharing of objects within node
|
||||
*/
|
||||
export declare let obs: any;
|
47
dist/smartenv.objectstorage.js
vendored
47
dist/smartenv.objectstorage.js
vendored
@ -1,47 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugins = require("./smartenv.plugins");
|
||||
exports.obsItems = {};
|
||||
/**
|
||||
* Objectstorage allows easy sharing of objects within node
|
||||
*/
|
||||
exports.obs = {
|
||||
add: (keyNameArg, objectArg) => {
|
||||
if (!keyNameArg) {
|
||||
console.log('keyName is undefined');
|
||||
return;
|
||||
}
|
||||
if (!objectArg) {
|
||||
console.log('objectArg is undefined');
|
||||
}
|
||||
if (!(exports.obsItems[keyNameArg])) {
|
||||
exports.obsItems[keyNameArg] = objectArg;
|
||||
}
|
||||
else {
|
||||
console.log('object is already present, so add operation has failed.');
|
||||
}
|
||||
return exports.obsItems[keyNameArg];
|
||||
},
|
||||
replace: function (paramNameArg, objectArg) {
|
||||
exports.obsItems[paramNameArg] = objectArg;
|
||||
},
|
||||
merge: function (paramNameArg, objectArg) {
|
||||
if (!(typeof exports.obsItems[paramNameArg] === 'undefined')) {
|
||||
exports.obsItems[paramNameArg] = plugins.lodash.assign(exports.obsItems[paramNameArg], objectArg);
|
||||
}
|
||||
else {
|
||||
console.log('object is not present, so there is nothing to merge');
|
||||
}
|
||||
},
|
||||
get: function (keyName) {
|
||||
return exports.obsItems[keyName];
|
||||
},
|
||||
getAll: function () {
|
||||
return exports.obsItems;
|
||||
},
|
||||
addComplete: function (itemsArg) {
|
||||
exports.obsItems = plugins.lodash.assign(exports.obsItems, itemsArg);
|
||||
return exports.obsItems;
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYub2JqZWN0c3RvcmFnZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZW52Lm9iamVjdHN0b3JhZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw4Q0FBOEM7QUFFbkMsUUFBQSxRQUFRLEdBQVEsRUFBRSxDQUFBO0FBRTdCOztHQUVHO0FBQ1EsUUFBQSxHQUFHLEdBQVE7SUFDcEIsR0FBRyxFQUFFLENBQUMsVUFBVSxFQUFFLFNBQVM7UUFDekIsRUFBRSxDQUFDLENBQUMsQ0FBQyxV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JQUFJLENBQUMsQ0FBQztZQUNOLE9BQU8sQ0FBQyxHQUFHLENBQUMscURBQXFELENBQUMsQ0FBQTtRQUNwRSxDQUFDO0lBQ0gsQ0FBQztJQUNELEdBQUcsRUFBRSxVQUFVLE9BQU87UUFDcEIsTUFBTSxDQUFDLGdCQUFRLENBQUUsT0FBTyxDQUFFLENBQUE7SUFDNUIsQ0FBQztJQUNELE1BQU0sRUFBRTtRQUNOLE1BQU0sQ0FBQyxnQkFBUSxDQUFBO0lBQ2pCLENBQUM7SUFDRCxXQUFXLEVBQUUsVUFBVSxRQUFRO1FBQzdCLGdCQUFRLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsZ0JBQVEsRUFBRSxRQUFRLENBQUMsQ0FBQTtRQUNwRCxNQUFNLENBQUMsZ0JBQVEsQ0FBQTtJQUNqQixDQUFDO0NBQ0YsQ0FBQSJ9
|
4
dist/smartenv.plugins.d.ts
vendored
4
dist/smartenv.plugins.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import 'typings-global';
|
||||
import * as smartq from 'smartq';
|
||||
import * as lodash from 'lodash';
|
||||
export { smartq, lodash };
|
8
dist/smartenv.plugins.js
vendored
8
dist/smartenv.plugins.js
vendored
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
const smartq = require("smartq");
|
||||
exports.smartq = smartq;
|
||||
const lodash = require("lodash");
|
||||
exports.lodash = lodash;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZW52LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIsaUNBQWdDO0FBSTVCLHdCQUFNO0FBSFYsaUNBQWdDO0FBSTVCLHdCQUFNIn0=
|
@ -1,7 +1,17 @@
|
||||
{
|
||||
"npmci": {
|
||||
"globalNpmTools": [
|
||||
"npmts"
|
||||
]
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartenv",
|
||||
"description": "store things about your environment and let them travel across modules",
|
||||
"npmPackagename": "@pushrocks/smartenv",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"mode":"default",
|
||||
"coverageTreshold":75
|
||||
}
|
46
package.json
46
package.json
@ -1,12 +1,15 @@
|
||||
{
|
||||
"name": "smartenv",
|
||||
"version": "2.0.6",
|
||||
"name": "@pushrocks/smartenv",
|
||||
"version": "5.0.5",
|
||||
"description": "store things about your environment and let them travel across modules",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)",
|
||||
"testbrowser": "(npm test) && (node testbrowser.js)"
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
||||
"testbrowser": "(npm test) && (node testbrowser.js)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,12 +25,31 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartenv",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.4",
|
||||
"smartq": "^1.1.1",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/smartpromise": "^3.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"beautylog": "^6.1.5",
|
||||
"tapbundle": "^1.0.5"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.56",
|
||||
"@gitzone/tsbundle": "^2.0.7",
|
||||
"@gitzone/tsrun": "^1.2.31",
|
||||
"@gitzone/tstest": "^1.0.68",
|
||||
"@pushrocks/tapbundle": "^5.0.2",
|
||||
"@types/node": "^18.11.18",
|
||||
"@types/npm": "^7.19.0"
|
||||
},
|
||||
"private": false,
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
4382
pnpm-lock.yaml
generated
Normal file
4382
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
readme.md
Normal file
37
readme.md
Normal file
@ -0,0 +1,37 @@
|
||||
# @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)
|
||||
|
||||
## 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.
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
61
test/test.ts
61
test/test.ts
@ -1,38 +1,37 @@
|
||||
import * as smartenv from '../dist/index.js'
|
||||
import * as beautylog from 'beautylog'
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartenv from '../ts/index.js';
|
||||
|
||||
import { tap, expect } from 'tapbundle'
|
||||
let testEnv: smartenv.Smartenv;
|
||||
|
||||
tap.test('should print env', async () => {
|
||||
smartenv.printEnv()
|
||||
}).catch(tap.threw)
|
||||
testEnv = new smartenv.Smartenv();
|
||||
});
|
||||
|
||||
// test smartenv.obs.add
|
||||
tap.test('obs add something', async () => {
|
||||
smartenv.obs.add('myTestObject', { key1: 'Peter' })
|
||||
smartenv.obs.add('myTestObject', { key1: 'Klaus' }) // now trying to add a second
|
||||
return expect(smartenv.obs.get('myTestObject').key1).to.equal('Peter')
|
||||
})
|
||||
tap.test('should print a overview to console', async () => {
|
||||
testEnv.printEnv();
|
||||
});
|
||||
|
||||
// test smartenv.obs.replace
|
||||
tap.test('', async () => {
|
||||
smartenv.obs.replace('myTestObject', { key1: 'Klaus' })
|
||||
expect(smartenv.obs.get('myTestObject').key1).to.equal('Klaus')
|
||||
})
|
||||
tap.test('should get os', async () => {
|
||||
const resultMac = await testEnv.isMacAsync();
|
||||
const resultLinux = await testEnv.isLinuxAsync();
|
||||
const resultWindows = await testEnv.isWindowsAsync();
|
||||
const osModule = await import('os');
|
||||
if (resultMac) {
|
||||
expect(osModule.platform()).toEqual('darwin');
|
||||
console.log('platform is Mac!');
|
||||
} else if (resultLinux) {
|
||||
expect(osModule.platform()).toEqual('linux');
|
||||
console.log('platform is Linux!');
|
||||
} else {
|
||||
expect(osModule.platform()).toEqual('win32');
|
||||
console.log('platform is Windows!');
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should merge things', async () => {
|
||||
smartenv.obs.merge('myTestObject', { key2: 'Peter' })
|
||||
expect(smartenv.obs.get('myTestObject').key1).to.equal('Klaus')
|
||||
return expect(smartenv.obs.get('myTestObject').key2).to.equal('Peter')
|
||||
})
|
||||
tap.test('should state wether we are in CI', async () => {
|
||||
if (process.env.CI) {
|
||||
expect(testEnv.isCI).toBeTrue();
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('set via get', async () => {
|
||||
smartenv.obs.get('myTestObject').key2 = 'hello'
|
||||
return expect(smartenv.obs.get('myTestObject').key2).to.equal('hello')
|
||||
})
|
||||
|
||||
tap.test('should get regex env array', async () => {
|
||||
process.env.CUSTOM = 'some'
|
||||
let resultArray = await smartenv.getEnvVars(/CUSTOM/)
|
||||
return expect(resultArray).to.be.length(1)
|
||||
})
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartenv',
|
||||
version: '5.0.5',
|
||||
description: 'store things about your environment and let them travel across modules'
|
||||
}
|
11
ts/index.ts
11
ts/index.ts
@ -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.js';
|
||||
|
9
ts/interfaces/index.ts
Normal file
9
ts/interfaces/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export let defaultme = null;
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
window: any;
|
||||
navigator: any;
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
};
|
||||
}
|
151
ts/smartenv.classes.smartenv.ts
Normal file
151
ts/smartenv.classes.smartenv.ts
Normal file
@ -0,0 +1,151 @@
|
||||
import * as plugins from './smartenv.plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
// interfaces
|
||||
export interface IEnvObject {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smartenv class that makes it easy
|
||||
*/
|
||||
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
|
||||
);
|
||||
return moduleResult;
|
||||
} 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: ${moduleNameArg}`);
|
||||
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 process !== 'undefined') {
|
||||
return 'node';
|
||||
} else {
|
||||
return 'browser';
|
||||
}
|
||||
}
|
||||
|
||||
public get isBrowser(): boolean {
|
||||
return !this.isNode;
|
||||
}
|
||||
|
||||
public get userAgent(): string {
|
||||
if (this.isBrowser) {
|
||||
// make sure we are in Browser
|
||||
return navigator.userAgent;
|
||||
} else {
|
||||
return 'undefined';
|
||||
}
|
||||
}
|
||||
|
||||
public get isNode(): boolean {
|
||||
return this.runtimeEnv === 'node';
|
||||
}
|
||||
|
||||
public get nodeVersion(): string {
|
||||
return process.version;
|
||||
}
|
||||
|
||||
public get isCI(): boolean {
|
||||
if (this.isNode) {
|
||||
if (process.env.CI) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async isMacAsync(): Promise<boolean> {
|
||||
if (this.isNode) {
|
||||
const os = await this.getSafeNodeModule('os');
|
||||
return os.platform() === 'darwin';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async isWindowsAsync(): Promise<boolean> {
|
||||
if (this.isNode) {
|
||||
const os = await this.getSafeNodeModule('os');
|
||||
return os.platform() === 'win32';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async isLinuxAsync(): Promise<boolean> {
|
||||
if (this.isNode) {
|
||||
const os = await this.getSafeNodeModule('os');
|
||||
return os.platform() === 'linux';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
public async printEnv() {
|
||||
if (this.isNode) {
|
||||
console.log('running on NODE');
|
||||
console.log('node version is ' + this.nodeVersion);
|
||||
} else {
|
||||
console.log('running on BROWSER');
|
||||
console.log('browser is ' + this.userAgent);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +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'
|
||||
}
|
||||
}
|
||||
|
||||
export let getUserAgentString = function (): string {
|
||||
if (isBrowser()) {
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
@ -1,8 +1,3 @@
|
||||
import 'typings-global'
|
||||
import * as smartq from 'smartq'
|
||||
import * as lodash from 'lodash'
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export {
|
||||
smartq,
|
||||
lodash
|
||||
}
|
||||
export { smartpromise };
|
||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user