Compare commits
88 Commits
Author | SHA1 | Date | |
---|---|---|---|
3c7e3e2589 | |||
205d27f9a0 | |||
56ce78f794 | |||
9d33054f03 | |||
072ca59ab0 | |||
59e3759a3a | |||
bc95ba3f2d | |||
1e6b9779b8 | |||
3988887a37 | |||
5a26ba7771 | |||
f61c0da30a | |||
3dfb07e875 | |||
fde1e90440 | |||
f06c9f186f | |||
e539489901 | |||
a1dcfba0a2 | |||
cff79e56c0 | |||
44252ab0d3 | |||
d4c3ec6c90 | |||
42aa1c2831 | |||
adf602ab86 | |||
8bc8285430 | |||
63d9434a39 | |||
32ddc9cfed | |||
936a719682 | |||
56c4b43f3c | |||
5ed11a280f | |||
346809d5be | |||
90add506e3 | |||
adea8d1d69 | |||
1b2eb1d763 | |||
cbc974b3d1 | |||
76e72e2a28 | |||
697eb83390 | |||
00ec15ccf7 | |||
b54a5e2fef | |||
a1aa1543a2 | |||
0e48cb8f89 | |||
d76d1a263b | |||
5f6f434998 | |||
8e7909e367 | |||
ff9302f745 | |||
3577fa22e1 | |||
f5275adfbd | |||
31bf1b27a4 | |||
a77def5844 | |||
2357699f3e | |||
01f5784488 | |||
80f35c39aa | |||
87f55773bd | |||
1a25341232 | |||
ccd41d86bf | |||
0a3a7e480e | |||
33a91c6ae7 | |||
0cfbdf2c9e | |||
f7362e5444 | |||
7844fdb954 | |||
81d1a4f15e | |||
da02923679 | |||
d7927ead86 | |||
9214ac49d5 | |||
309b3e100d | |||
eac42f50d6 | |||
c83b7688e9 | |||
524fc5265f | |||
692168c8c2 | |||
2b3198c5bb | |||
26104a231d | |||
44bc565efe | |||
09c6a0aa8a | |||
5a307f4c2c | |||
2925a88e5b | |||
0a4bad1ad0 | |||
e34d37da19 | |||
a029eeb6c1 | |||
7527049fd0 | |||
25589d4ca2 | |||
73c223af6c | |||
ead69f3bb9 | |||
7de17bbefa | |||
4e39970dd7 | |||
2a7c239176 | |||
35e71ccf00 | |||
11a2cf83ee | |||
d7a0541d81 | |||
c03e17d522 | |||
b9d1080829 | |||
a84a257e4b |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal 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
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal 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 @gitzone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
docs/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
@ -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
|
|
@ -1,4 +0,0 @@
|
|||||||
node_modules/
|
|
||||||
coverage/
|
|
||||||
docs/
|
|
||||||
|
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
19
README.md
19
README.md
@ -1,19 +0,0 @@
|
|||||||
# qenv
|
|
||||||
provides an easy way for promised environments
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
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.
|
|
||||||
|
|
||||||
```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
6
dist/index.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
export declare class Qenv {
|
|
||||||
requiredEnvVars: string[];
|
|
||||||
availableEnvVars: string[];
|
|
||||||
missingEnvVars: string[];
|
|
||||||
constructor(basePathArg: string, envYmlPathArg: any);
|
|
||||||
}
|
|
52
dist/index.js
vendored
52
dist/index.js
vendored
File diff suppressed because one or more lines are too long
5
dist/qenv.plugins.d.ts
vendored
5
dist/qenv.plugins.d.ts
vendored
@ -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");
|
|
8
dist/qenv.plugins.js
vendored
8
dist/qenv.plugins.js
vendored
@ -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
17
npmextra.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"mode":"default"
|
|
||||||
}
|
|
50
package.json
50
package.json
@ -1,11 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "qenv",
|
"name": "@push.rocks/qenv",
|
||||||
"version": "1.0.6",
|
"version": "6.0.0",
|
||||||
"description": "promised environments",
|
"private": false,
|
||||||
"main": "dist/index.js",
|
"description": "easy promised environments",
|
||||||
"typings": "dist/index.d.ts",
|
"main": "dist_ts/index.js",
|
||||||
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -23,15 +27,31 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6",
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
"should": "^9.0.2",
|
"@gitzone/tsrun": "^1.2.44",
|
||||||
"typings-test": "^1.0.1"
|
"@gitzone/tstest": "^1.0.77",
|
||||||
|
"@push.rocks/tapbundle": "^5.0.12",
|
||||||
|
"@types/node": "^20.4.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^5.0.12",
|
"@configvault.io/interfaces": "^1.0.2",
|
||||||
"lodash": "^4.13.1",
|
"@push.rocks/smartfile": "^10.0.28",
|
||||||
"q": "^1.4.1",
|
"@push.rocks/smartlog": "^3.0.3",
|
||||||
"smartfile": "^3.0.10",
|
"@push.rocks/smartpath": "^5.0.11"
|
||||||
"typings-global": "^1.0.3"
|
},
|
||||||
}
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
4792
pnpm-lock.yaml
generated
Normal file
4792
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
52
readme.md
Normal file
52
readme.md
Normal 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 | [](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.
|
||||||
|
|
||||||
|
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
4
test/assets/env.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"key1": "fromJson",
|
||||||
|
"key2" :"fromJson"
|
||||||
|
}
|
@ -1,2 +0,0 @@
|
|||||||
key1: fromYml
|
|
||||||
key2: fromYml
|
|
@ -1,4 +1,4 @@
|
|||||||
vars:
|
required:
|
||||||
- key1
|
- key1
|
||||||
- key2
|
- key2
|
||||||
- key3
|
- key3
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import "typings-test";
|
|
||||||
import "should";
|
|
23
test/test.js
23
test/test.js
@ -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==
|
|
49
test/test.ts
49
test/test.ts
@ -1,24 +1,35 @@
|
|||||||
import "typings-test";
|
import * as path from 'path';
|
||||||
import * as path from "path";
|
import { tap, expect } from '@push.rocks/tapbundle';
|
||||||
import "should";
|
import * as qenv from '../ts/index.js';
|
||||||
import {Qenv} from "../dist/index";
|
|
||||||
|
|
||||||
process.cwd = () => {
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
return path.join(__dirname,"./assets/");
|
|
||||||
}
|
|
||||||
|
|
||||||
process.env["key1"] = "original"
|
export { smartpath };
|
||||||
|
|
||||||
let qenvTestObject:Qenv;
|
const testDir = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
||||||
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");
|
|
||||||
})
|
|
||||||
|
|
||||||
|
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
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/qenv',
|
||||||
|
version: '6.0.0',
|
||||||
|
description: 'easy promised environments'
|
||||||
|
}
|
52
ts/index.ts
52
ts/index.ts
@ -1,51 +1 @@
|
|||||||
import * as plugins from "./qenv.plugins";
|
export * from './qenv.classes.qenv.js';
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
144
ts/qenv.classes.qenv.ts
Normal file
144
ts/qenv.classes.qenv.ts
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
import * as plugins from './qenv.plugins.js';
|
||||||
|
|
||||||
|
export class Qenv {
|
||||||
|
public requiredEnvVars: string[] = [];
|
||||||
|
public availableEnvVars: string[] = [];
|
||||||
|
public missingEnvVars: string[] = [];
|
||||||
|
public keyValueObject: { [key: string]: any } = {};
|
||||||
|
public logger = new plugins.smartlog.ConsoleLog();
|
||||||
|
|
||||||
|
public qenvFilePathAbsolute: string;
|
||||||
|
public envFilePathAbsolute: string;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
qenvFileBasePathArg: string = process.cwd(),
|
||||||
|
envFileBasePathArg: string,
|
||||||
|
failOnMissing: boolean = true
|
||||||
|
) {
|
||||||
|
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');
|
||||||
|
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(envVarName: string): Promise<string | undefined> {
|
||||||
|
return (
|
||||||
|
this.getFromEnvironmentVariable(envVarName) ||
|
||||||
|
this.getFromEnvJsonFile(envVarName) ||
|
||||||
|
this.getFromDockerSecret(envVarName) ||
|
||||||
|
this.getFromDockerSecretJson(envVarName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getEnvVarOnDemandSync(envVarName: string): Promise<string | undefined> {
|
||||||
|
console.warn('requesting env var sync leaves out potentially important async env sources.');
|
||||||
|
return (
|
||||||
|
this.getFromEnvironmentVariable(envVarName) ||
|
||||||
|
this.getFromEnvJsonFile(envVarName) ||
|
||||||
|
this.getFromDockerSecret(envVarName) ||
|
||||||
|
this.getFromDockerSecretJson(envVarName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getEnvVarOnDemandAsObject(envVarName: string): Promise<any> {
|
||||||
|
const rawValue = await this.getEnvVarOnDemand(envVarName);
|
||||||
|
if (rawValue && rawValue.startsWith('base64Object:')) {
|
||||||
|
const base64Part = rawValue.split('base64Object:')[1];
|
||||||
|
return this.decodeBase64(base64Part);
|
||||||
|
}
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getFromEnvironmentVariable(envVarName: string): string | undefined {
|
||||||
|
return process.env[envVarName];
|
||||||
|
}
|
||||||
|
|
||||||
|
private getFromEnvJsonFile(envVarName: string): string | 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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,10 @@
|
|||||||
import "typings-global";
|
// native
|
||||||
export import beautylog = require("beautylog");
|
import * as path from 'path';
|
||||||
export let lodash = require("lodash");
|
|
||||||
export import path = require("path");
|
export { path };
|
||||||
export import smartfile = require("smartfile");
|
|
||||||
|
// @pushrocks scope
|
||||||
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
|
import * as smartlog from '@push.rocks/smartlog';
|
||||||
|
|
||||||
|
export { smartfile, smartlog };
|
||||||
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user