Compare commits

..

103 Commits

Author SHA1 Message Date
7655318629 6.0.5 2024-02-09 15:42:01 +01:00
754ffa6cac fix(core): update 2024-02-09 15:42:00 +01:00
b644ca0c1a 6.0.4 2023-10-20 18:18:48 +02:00
9f638d687b fix(core): update 2023-10-20 18:18:47 +02:00
a9bdfe9373 6.0.3 2023-10-20 17:21:52 +02:00
2017d51f11 fix(core): update 2023-10-20 17:21:51 +02:00
765011ad2a 6.0.2 2023-08-09 17:47:21 +02:00
d807cc6de2 fix(core): update 2023-08-09 17:47:20 +02:00
53721a41c2 6.0.1 2023-08-09 14:50:33 +02:00
c9f79e6ea4 fix(core): update 2023-08-09 14:50:32 +02:00
3c7e3e2589 6.0.0 2023-08-09 13:24:50 +02:00
205d27f9a0 BREAKING CHANGE(core): update 2023-08-09 13:24:49 +02:00
56ce78f794 5.0.5 2023-08-09 12:49:52 +02:00
9d33054f03 fix(core): update 2023-08-09 12:49:52 +02:00
072ca59ab0 5.0.4 2023-08-08 19:50:45 +02:00
59e3759a3a fix(core): update 2023-08-08 19:50:44 +02:00
bc95ba3f2d 5.0.3 2023-08-08 19:08:25 +02:00
1e6b9779b8 fix(core): update 2023-08-08 19:08:25 +02:00
3988887a37 switch to new org scheme 2023-07-11 00:07:40 +02:00
5a26ba7771 switch to new org scheme 2023-07-10 02:41:52 +02:00
f61c0da30a 5.0.2 2022-08-02 14:50:18 +02:00
3dfb07e875 fix(core): update 2022-08-02 14:50:18 +02:00
fde1e90440 5.0.1 2022-07-28 10:10:40 +02:00
f06c9f186f fix(core): update 2022-07-28 10:10:39 +02:00
e539489901 5.0.0 2022-07-28 10:09:35 +02:00
a1dcfba0a2 BREAKING CHANGE(core): switch to esm 2022-07-28 10:09:34 +02:00
cff79e56c0 4.0.11 2022-07-28 10:09:01 +02:00
44252ab0d3 fix(core): update 2022-07-28 10:09:01 +02:00
d4c3ec6c90 4.0.10 2020-06-08 19:03:18 +00:00
42aa1c2831 fix(core): update 2020-06-08 19:03:17 +00:00
adf602ab86 4.0.9 2020-06-08 18:58:56 +00:00
8bc8285430 fix(core): update 2020-06-08 18:58:55 +00:00
63d9434a39 4.0.8 2020-06-08 18:58:44 +00:00
32ddc9cfed fix(core): update 2020-06-08 18:58:43 +00:00
936a719682 4.0.7 2020-06-08 18:57:23 +00:00
56c4b43f3c fix(core): update 2020-06-08 18:57:22 +00:00
5ed11a280f 4.0.6 2019-10-01 12:32:40 +02:00
346809d5be fix(core): update 2019-10-01 12:32:39 +02:00
90add506e3 4.0.5 2019-09-13 11:20:48 +02:00
adea8d1d69 fix(core): update 2019-09-13 11:20:47 +02:00
1b2eb1d763 4.0.4 2019-08-29 14:29:16 +02:00
cbc974b3d1 fix(core): update 2019-08-29 14:29:16 +02:00
76e72e2a28 4.0.3 2019-08-29 14:19:16 +02:00
697eb83390 fix(core): update 2019-08-29 14:19:15 +02:00
00ec15ccf7 4.0.2 2019-08-06 17:41:46 +02:00
b54a5e2fef fix(core): update 2019-08-06 17:41:45 +02:00
a1aa1543a2 4.0.1 2019-08-06 17:37:07 +02:00
0e48cb8f89 fix(core): update 2019-08-06 17:37:07 +02:00
d76d1a263b 4.0.0 2019-01-15 23:54:29 +01:00
5f6f434998 BREAKING CHANGE(process.env): treat environment as immutable 2019-01-15 23:54:29 +01:00
8e7909e367 3.1.1 2019-01-14 22:42:25 +01:00
ff9302f745 fix(core): update 2019-01-14 22:42:24 +01:00
3577fa22e1 3.1.0 2019-01-14 01:54:05 +01:00
f5275adfbd feat(docker secret): docker secret.json can now also be named [anything].secret.json 2019-01-14 01:54:04 +01:00
31bf1b27a4 3.0.7 2019-01-13 22:33:19 +01:00
a77def5844 fix(core): update 2019-01-13 22:33:18 +01:00
2357699f3e 3.0.6 2019-01-13 22:04:20 +01:00
01f5784488 fix(core): update 2019-01-13 22:04:20 +01:00
80f35c39aa 3.0.5 2019-01-13 21:35:57 +01:00
87f55773bd fix(core): update 2019-01-13 21:35:57 +01:00
1a25341232 3.0.4 2019-01-13 18:25:09 +01:00
ccd41d86bf fix(core): update 2019-01-13 18:25:09 +01:00
0a3a7e480e 3.0.3 2019-01-13 00:00:32 +01:00
33a91c6ae7 fix(core): update 2019-01-13 00:00:32 +01:00
0cfbdf2c9e 3.0.2 2019-01-06 03:36:40 +01:00
f7362e5444 fix(core): update 2019-01-06 03:36:40 +01:00
7844fdb954 3.0.1 2019-01-06 03:20:59 +01:00
81d1a4f15e fix(core): update 2019-01-06 03:20:59 +01:00
da02923679 3.0.0 2019-01-06 01:30:56 +01:00
d7927ead86 2.0.3 2019-01-06 01:30:07 +01:00
9214ac49d5 fix(core): update 2019-01-06 01:30:07 +01:00
309b3e100d 2.0.2 2018-08-13 21:58:19 +02:00
eac42f50d6 fix(core): update 2018-08-13 21:58:18 +02:00
c83b7688e9 2.0.1 2018-08-13 00:45:57 +02:00
524fc5265f fix(docs): update 2018-08-13 00:45:57 +02:00
692168c8c2 2.0.0 2018-08-13 00:09:37 +02:00
2b3198c5bb BREAKING CHANGE(scope): change scope to @pushrocks/ 2018-08-13 00:09:37 +02:00
26104a231d 1.1.7 2017-05-13 11:40:13 +02:00
44bc565efe fix path resolution for env.yml 2017-05-13 11:40:10 +02:00
09c6a0aa8a 1.1.6 2017-05-12 19:12:07 +02:00
5a307f4c2c add relative path compatibility 2017-05-12 19:12:03 +02:00
2925a88e5b 1.1.5 2017-05-12 18:17:29 +02:00
0a4bad1ad0 refactor code 2017-05-12 18:17:22 +02:00
e34d37da19 1.1.4 2017-05-12 17:57:11 +02:00
a029eeb6c1 update to latest standards 2017-05-12 17:56:51 +02:00
7527049fd0 1.1.3 2017-01-21 11:57:09 +01:00
25589d4ca2 cleanup dependencies 2017-01-21 11:57:04 +01:00
73c223af6c 1.1.2 2017-01-21 11:51:35 +01:00
ead69f3bb9 remove beautylog dependency 2017-01-21 11:51:30 +01:00
7de17bbefa add better README 2016-12-31 19:26:32 +01:00
4e39970dd7 1.1.1 2016-08-04 16:44:48 +02:00
2a7c239176 fix interface naming 2016-08-04 16:44:42 +02:00
35e71ccf00 1.1.0 2016-08-04 16:09:44 +02:00
11a2cf83ee add keyValueObjectArray 2016-08-04 16:09:39 +02:00
d7a0541d81 1.0.8 2016-06-21 16:25:09 +02:00
c03e17d522 improve log output 2016-06-21 16:25:03 +02:00
b9d1080829 1.0.7 2016-06-21 16:13:45 +02:00
a84a257e4b improve log output 2016-06-21 16:13:29 +02:00
2fa659a22a 1.0.6 2016-06-20 22:19:11 +02:00
bdc99cc3a6 link typings om package.json 2016-06-20 22:18:48 +02:00
2956278369 cosmetics 2016-06-20 12:05:35 +02:00
c61ef2eeba 1.0.5 2016-06-20 11:21:26 +02:00
41c97c4c05 improve README 2016-06-20 11:21:21 +02:00
29 changed files with 6357 additions and 252 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

21
.gitignore vendored
View File

@ -1,3 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
docs/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,35 +0,0 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
testLEGACY:
stage: test
script:
- npmci test lts
tags:
- docker
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker

View File

@ -1,4 +0,0 @@
node_modules/
coverage/
docs/

11
.vscode/launch.json vendored Normal file
View 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
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,19 +0,0 @@
# qenv
provides an easy way for promised environments
## Usage
qenv needs two files to work:
* **qenv.yml** - specified which ENV vars are required
* **env.yml** specified all env vars that are not already set in the current environment
Now obviously you can set build specific env vars in many CI environments.
So there we do not need an **env.yml** since all ENV vars are in place
However when on another machine you can have a env.yml that will be added to the environment by qenv.
```typescript
import {Qenv} from "qenv";
myQenv = new Qenv("path/to/dir/where/qenv.yml/is/","path/to/dir/where/env.yml/is(");
```

6
dist/index.d.ts vendored
View File

@ -1,6 +0,0 @@
export declare class Qenv {
requiredEnvVars: string[];
availableEnvVars: string[];
missingEnvVars: string[];
constructor(basePathArg: string, envYmlPathArg: any);
}

52
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +0,0 @@
import "typings-global";
export import beautylog = require("beautylog");
export declare let lodash: any;
export import path = require("path");
export import smartfile = require("smartfile");

View File

@ -1,8 +0,0 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.lodash = require("lodash");
exports.path = require("path");
exports.smartfile = require("smartfile");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInFlbnYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxjQUFNLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0FBQ3hCLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDIiwiZmlsZSI6InFlbnYucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQgaW1wb3J0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgbGV0IGxvZGFzaCA9IHJlcXVpcmUoXCJsb2Rhc2hcIik7XG5leHBvcnQgaW1wb3J0IHBhdGggPSByZXF1aXJlKFwicGF0aFwiKTtcbmV4cG9ydCBpbXBvcnQgc21hcnRmaWxlID0gcmVxdWlyZShcInNtYXJ0ZmlsZVwiKTtcbiJdfQ==

17
npmextra.json Normal file
View File

@ -0,0 +1,17 @@
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "push.rocks",
"gitrepo": "qenv",
"description": "easy promised environments",
"npmPackagename": "@push.rocks/qenv",
"license": "MIT"
}
}
}

View File

@ -1,3 +0,0 @@
{
"mode":"default"
}

View File

@ -1,10 +1,15 @@
{
"name": "qenv",
"version": "1.0.4",
"description": "promised environments",
"main": "dist/index.js",
"name": "@push.rocks/qenv",
"version": "6.0.5",
"private": false,
"description": "easy promised environments",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
@ -22,15 +27,32 @@
},
"homepage": "https://gitlab.com/pushrocks/qenv#README",
"devDependencies": {
"npmts-g": "^5.2.6",
"should": "^9.0.2",
"typings-test": "^1.0.1"
"@git.zone/tsbuild": "^2.1.72",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.86",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.11.17"
},
"dependencies": {
"beautylog": "^5.0.12",
"lodash": "^4.13.1",
"q": "^1.4.1",
"smartfile": "^3.0.10",
"typings-global": "^1.0.3"
}
"@api.global/typedrequest": "^3.0.4",
"@configvault.io/interfaces": "^1.0.17",
"@push.rocks/smartfile": "^11.0.4",
"@push.rocks/smartlog": "^3.0.3",
"@push.rocks/smartpath": "^5.0.11"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

5697
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

52
readme.md Normal file
View File

@ -0,0 +1,52 @@
# @push.rocks/qenv
easy promised environments
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/qenv)
* [gitlab.com (source)](https://gitlab.com/push.rocks/qenv)
* [github.com (source mirror)](https://github.com/push.rocks/qenv)
* [docs (typedoc)](https://push.rocks.gitlab.io/qenv/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/qenv/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/qenv/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/qenv)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/qenv)](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/@push.rocks/qenv)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/qenv)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/qenv)](https://lossless.cloud)
## Usage
Use TypeScript for best in class instellisense.
qenv works with two files:
- **qenv.yml** - specifies which ENV vars are required.
- **env.yml** - specifies all env vars that are not already set in the current environment.
Now obviously you can set build specific env vars in many CI environments.
So there we do not need an **env.yml** since all ENV vars are in place
However when on another machine you can have a env.yml that will be added to the environment by qenv.
```javascript
import { Qenv } from 'qenv';
const myQenv = new Qenv('path/to/dir/where/qenv.yml/is/', 'path/to/dir/where/env.yml/is(');
```
## 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)

4
test/assets/env.json Normal file
View File

@ -0,0 +1,4 @@
{
"key1": "fromJson",
"key2" :"fromJson"
}

View File

@ -1,2 +0,0 @@
key1: fromYml
key2: fromYml

View File

@ -1,4 +1,4 @@
vars:
required:
- key1
- key2
- key3

2
test/test.d.ts vendored
View File

@ -1,2 +0,0 @@
import "typings-test";
import "should";

View File

@ -1,23 +0,0 @@
"use strict";
require("typings-test");
var path = require("path");
require("should");
var index_1 = require("../dist/index");
process.cwd = function () {
return path.join(__dirname, "./assets/");
};
process.env["key1"] = "original";
var qenvTestObject;
describe("Qenv class", function () {
it("should create a new class", function () {
qenvTestObject = new index_1.Qenv(process.cwd(), process.cwd());
});
it("key1 should be not be overwritten since it is already present", function () {
process.env.key1.should.equal("original");
});
it("key2 should be read from Yml", function () {
process.env.key2.should.equal("fromYml");
});
});
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsSUFBWSxJQUFJLFdBQU0sTUFBTSxDQUFDLENBQUE7QUFDN0IsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQixzQkFBbUIsZUFBZSxDQUFDLENBQUE7QUFFbkMsT0FBTyxDQUFDLEdBQUcsR0FBRztJQUNWLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxXQUFXLENBQUMsQ0FBQztBQUM1QyxDQUFDLENBQUE7QUFFRCxPQUFPLENBQUMsR0FBRyxDQUFDLE1BQU0sQ0FBQyxHQUFHLFVBQVUsQ0FBQTtBQUVoQyxJQUFJLGNBQW1CLENBQUM7QUFDeEIsUUFBUSxDQUFDLFlBQVksRUFBQztJQUNsQixFQUFFLENBQUMsMkJBQTJCLEVBQUM7UUFDM0IsY0FBYyxHQUFHLElBQUksWUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUMsQ0FBQztJQUMzRCxDQUFDLENBQUMsQ0FBQztJQUNILEVBQUUsQ0FBQywrREFBK0QsRUFBQztRQUMvRCxPQUFPLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0lBQzlDLENBQUMsQ0FBQyxDQUFDO0lBQ0gsRUFBRSxDQUFDLDhCQUE4QixFQUFDO1FBQzlCLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDN0MsQ0FBQyxDQUFDLENBQUE7QUFFTixDQUFDLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy10ZXN0XCI7XG5pbXBvcnQgKiBhcyBwYXRoIGZyb20gXCJwYXRoXCI7XG5pbXBvcnQgXCJzaG91bGRcIjtcbmltcG9ydCB7UWVudn0gZnJvbSBcIi4uL2Rpc3QvaW5kZXhcIjtcblxucHJvY2Vzcy5jd2QgPSAoKSA9PiB7XG4gICAgcmV0dXJuIHBhdGguam9pbihfX2Rpcm5hbWUsXCIuL2Fzc2V0cy9cIik7XG59XG5cbnByb2Nlc3MuZW52W1wia2V5MVwiXSA9IFwib3JpZ2luYWxcIlxuXG5sZXQgcWVudlRlc3RPYmplY3Q6UWVudjtcbmRlc2NyaWJlKFwiUWVudiBjbGFzc1wiLGZ1bmN0aW9uKCl7XG4gICAgaXQoXCJzaG91bGQgY3JlYXRlIGEgbmV3IGNsYXNzXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgcWVudlRlc3RPYmplY3QgPSBuZXcgUWVudihwcm9jZXNzLmN3ZCgpLHByb2Nlc3MuY3dkKCkpO1xuICAgIH0pO1xuICAgIGl0KFwia2V5MSBzaG91bGQgYmUgbm90IGJlIG92ZXJ3cml0dGVuIHNpbmNlIGl0IGlzIGFscmVhZHkgcHJlc2VudFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIHByb2Nlc3MuZW52LmtleTEuc2hvdWxkLmVxdWFsKFwib3JpZ2luYWxcIik7XG4gICAgfSk7XG4gICAgaXQoXCJrZXkyIHNob3VsZCBiZSByZWFkIGZyb20gWW1sXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgcHJvY2Vzcy5lbnYua2V5Mi5zaG91bGQuZXF1YWwoXCJmcm9tWW1sXCIpO1xuICAgIH0pXG5cbn0pOyJdfQ==

View File

@ -1,24 +1,35 @@
import "typings-test";
import * as path from "path";
import "should";
import {Qenv} from "../dist/index";
import * as path from 'path';
import { tap, expect } from '@push.rocks/tapbundle';
import * as qenv from '../ts/index.js';
process.cwd = () => {
return path.join(__dirname,"./assets/");
}
import * as smartpath from '@push.rocks/smartpath';
process.env["key1"] = "original"
export { smartpath };
let qenvTestObject:Qenv;
describe("Qenv class",function(){
it("should create a new class",function(){
qenvTestObject = new Qenv(process.cwd(),process.cwd());
});
it("key1 should be not be overwritten since it is already present",function(){
process.env.key1.should.equal("original");
});
it("key2 should be read from Yml",function(){
process.env.key2.should.equal("fromYml");
})
const testDir = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
process.env['key1'] = 'original';
let testQenv: qenv.Qenv;
tap.test('should create a new class', async () => {
testQenv = new qenv.Qenv(path.join(testDir, 'assets'), path.join(testDir, 'assets'), false);
expect(testQenv).toBeInstanceOf(qenv.Qenv);
});
tap.test('key1 should be not be overwritten since it is already present', async () => {
expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
});
tap.test('key2 should be read from Yml', async () => {
expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
});
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
expect(await testQenv.keyValueObject.key1).toEqual('original');
expect(await testQenv.keyValueObject.key2).toEqual('fromJson');
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/qenv',
version: '6.0.5',
description: 'easy promised environments'
}

View File

@ -1,51 +1 @@
import * as plugins from "./qenv.plugins";
export class Qenv {
requiredEnvVars:string[];
availableEnvVars:string[];
missingEnvVars:string[];
constructor(basePathArg = process.cwd(),envYmlPathArg){
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars,envYmlPathArg);
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars,this.availableEnvVars);
for(let keyArg in this.missingEnvVars){
plugins.beautylog.warn(this.missingEnvVars[keyArg] + " is required, but missing!")
}
}
};
let getRequiredEnvVars = (pathArg:string):string[] => {
let result:string[] = [];
let qenvFilePath = plugins.path.join(pathArg,"qenv.yml");
let qenvFile = plugins.smartfile.local.toObjectSync(qenvFilePath);
for(let keyArg in qenvFile.vars){
result.push(qenvFile.vars[keyArg]);
}
return result;
}
let getAvailableEnvVars = (requiredEnvVarsArg:string[],envYmlPathArg:string):string[] => {
let result = [];
envYmlPathArg = plugins.path.join(envYmlPathArg,"env.yml")
let envYml;
try {
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
}
catch(err){
envYml = {};
}
for(let keyArg in requiredEnvVarsArg){
let requiredEnvVar:string = requiredEnvVarsArg[keyArg];
if(process.env[requiredEnvVar]){
result.push(requiredEnvVar);
} else if(envYml.hasOwnProperty(requiredEnvVar)){
process.env[requiredEnvVar] = envYml[requiredEnvVar];
result.push(requiredEnvVar);
}
}
return result;
}
let getMissingEnvVars = (requiredEnvVarsArray:string[],availableEnvVarsArray:string[]) => {
return plugins.lodash.difference(requiredEnvVarsArray,availableEnvVarsArray);
}
export * from './qenv.classes.qenv.js';

View File

@ -0,0 +1,30 @@
import * as plugins from './qenv.plugins.js';
export class CloudlyAdapter {
public configVaultUrl: string;
constructor(configVaultUrl?: string) {
this.configVaultUrl = configVaultUrl;
}
public async getConfigBundle(): Promise<plugins.configvaultInterfaces.data.IConfigBundle> {
if (this.configVaultUrl) {
console.log(`ConfigVault specified through constructor`)
} else if (process.env['CONFIGVAULT_URL']) {
this.configVaultUrl = process.env['CONFIGVAULT_URL'];
} else {
return null;
}
const parsedUrl = new URL(this.configVaultUrl);
const tr =
new plugins.typedrequest.TypedRequest<plugins.configvaultInterfaces.requests.IReq_GetEnvBundle>(
`${parsedUrl.host}/typedrequest`,
'getEnvBundle'
);
const response = await tr.fire({
authorization: parsedUrl.pathname.replace('/', ''),
})
}
}

198
ts/qenv.classes.qenv.ts Normal file
View File

@ -0,0 +1,198 @@
import { CloudlyAdapter } from './qenv.classes.configvaultadapter.js';
import * as plugins from './qenv.plugins.js';
export type TEnvVarRef = string | (() => Promise<string>);
export class Qenv {
public requiredEnvVars: string[] = [];
public availableEnvVars: string[] = [];
public missingEnvVars: string[] = [];
public keyValueObject: { [key: string]: any } = {};
public logger = new plugins.smartlog.ConsoleLog();
public cloudlyAdapter: CloudlyAdapter;
public qenvFilePathAbsolute: string;
public envFilePathAbsolute: string;
constructor(
qenvFileBasePathArg: string = process.cwd(),
envFileBasePathArg?: string,
failOnMissing: boolean = true
) {
this.cloudlyAdapter = new CloudlyAdapter();
this.initializeFilePaths(qenvFileBasePathArg, envFileBasePathArg);
this.loadRequiredEnvVars();
this.loadAvailableEnvVars();
this.checkForMissingEnvVars(failOnMissing);
}
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg: string) {
this.qenvFilePathAbsolute = plugins.path.join(
plugins.path.resolve(qenvFileBasePathArg),
'qenv.yml'
);
if (envFileBasePathArg) {
this.envFilePathAbsolute = plugins.path.join(
plugins.path.resolve(envFileBasePathArg),
'env.json'
);
}
}
private loadRequiredEnvVars() {
if (plugins.smartfile.fs.fileExistsSync(this.qenvFilePathAbsolute)) {
const qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
if (qenvFile?.required && Array.isArray(qenvFile.required)) {
this.requiredEnvVars.push(...qenvFile.required);
} else {
this.logger.log('warn', 'qenv.yml does not contain a "required" Array!');
}
}
}
private loadAvailableEnvVars() {
for (const envVar of this.requiredEnvVars) {
const value = this.getEnvVarOnDemand(envVar);
if (value) {
this.availableEnvVars.push(envVar);
this.keyValueObject[envVar] = value;
}
}
}
private checkForMissingEnvVars(failOnMissing: boolean) {
this.missingEnvVars = this.requiredEnvVars.filter(
(envVar) => !this.availableEnvVars.includes(envVar)
);
if (this.missingEnvVars.length > 0) {
console.info('Required Env Vars are:', this.requiredEnvVars);
console.error('Missing Env Vars:', this.missingEnvVars);
if (failOnMissing) {
this.logger.log('error', 'Exiting due to missing env vars!');
process.exit(1);
} else {
this.logger.log('warn', 'qenv is not set to fail on missing environment variables');
}
}
}
public async getEnvVarOnDemand(
envVarNameOrNames: TEnvVarRef | TEnvVarRef[]
): Promise<string | undefined> {
if (Array.isArray(envVarNameOrNames)) {
for (const envVarName of envVarNameOrNames) {
const value = await this.tryGetEnvVar(envVarName);
if (value) {
return value;
}
}
return undefined;
} else {
return await this.tryGetEnvVar(envVarNameOrNames);
}
}
public getEnvVarOnDemandSync(envVarNameOrNames: string | string[]): string | undefined {
console.warn('requesting env var sync leaves out potentially important async env sources.');
if (Array.isArray(envVarNameOrNames)) {
for (const envVarName of envVarNameOrNames) {
const value = this.tryGetEnvVarSync(envVarName);
if (value) {
return value;
}
}
return undefined;
} else {
return this.tryGetEnvVarSync(envVarNameOrNames);
}
}
public async getEnvVarOnDemandAsObject(envVarNameOrNames: string | string[]): Promise<any> {
const rawValue = await this.getEnvVarOnDemand(envVarNameOrNames);
if (rawValue && rawValue.startsWith('base64Object:')) {
const base64Part = rawValue.split('base64Object:')[1];
return this.decodeBase64(base64Part);
}
return rawValue;
}
private async tryGetEnvVar(envVarRefArg: TEnvVarRef): Promise<string | undefined> {
if (typeof envVarRefArg === 'function') {
return await envVarRefArg();
}
return (
this.getFromEnvironmentVariable(envVarRefArg) ||
this.getFromEnvJsonFile(envVarRefArg) ||
this.getFromDockerSecret(envVarRefArg) ||
this.getFromDockerSecretJson(envVarRefArg)
);
}
private tryGetEnvVarSync(envVarName: string): string | undefined {
return (
this.getFromEnvironmentVariable(envVarName) ||
this.getFromEnvJsonFile(envVarName) ||
this.getFromDockerSecret(envVarName) ||
this.getFromDockerSecretJson(envVarName)
);
}
private getFromEnvironmentVariable(envVarName: string): string | undefined {
return process.env[envVarName];
}
private getFromEnvJsonFile(envVarName: string): string | undefined {
if (!plugins.smartfile.fs.fileExistsSync(this.envFilePathAbsolute)) {
return undefined;
}
try {
const envJson = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
const value = envJson[envVarName];
if (typeof value === 'object') {
return 'base64Object:' + this.encodeBase64(value);
}
return value;
} catch (error) {
return undefined;
}
}
private getFromDockerSecret(envVarName: string): string | undefined {
const secretPath = `/run/secrets/${envVarName}`;
if (plugins.smartfile.fs.fileExistsSync(secretPath)) {
return plugins.smartfile.fs.toStringSync(secretPath);
}
return undefined;
}
private getFromDockerSecretJson(envVarName: string): string | undefined {
if (plugins.smartfile.fs.isDirectory('/run/secrets')) {
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
for (const secret of availableSecrets) {
if (secret.includes('secret.json')) {
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
const value = secretObject[envVarName];
if (typeof value === 'object') {
return 'base64Object:' + this.encodeBase64(value);
}
return value;
}
}
}
return undefined;
}
private encodeBase64(data: any): string {
const jsonString = JSON.stringify(data);
return Buffer.from(jsonString).toString('base64');
}
private decodeBase64(encodedString: string): any {
const decodedString = Buffer.from(encodedString, 'base64').toString('utf-8');
return JSON.parse(decodedString);
}
}

View File

@ -1,5 +1,22 @@
import "typings-global";
export import beautylog = require("beautylog");
export let lodash = require("lodash");
export import path = require("path");
export import smartfile = require("smartfile");
// native
import * as path from 'path';
export { path };
// @api.global scope
import * as typedrequest from '@api.global/typedrequest';
export {
typedrequest,
}
// @pushrocks scope
import * as smartfile from '@push.rocks/smartfile';
import * as smartlog from '@push.rocks/smartlog';
export { smartfile, smartlog };
// @configvault.io scope
import * as configvaultInterfaces from '@configvault.io/interfaces';
export { configvaultInterfaces };

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}