Compare commits
76 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
2fa659a22a | |||
bdc99cc3a6 | |||
2956278369 | |||
c61ef2eeba | |||
41c97c4c05 | |||
8870f9adf2 | |||
dfb400ba5c | |||
38609031d9 | |||
1d4808ed4a | |||
612f8307b8 |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
118
.gitlab-ci.yml
118
.gitlab-ci.yml
@ -1,35 +1,127 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testLTS:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
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
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
# qenv
|
||||
provides an easy way for promised environments
|
||||
|
||||
## Usage
|
||||
qenv looks for an qenv.yml that defines needed env vars. qenv dirst checks if they are already specified.
|
||||
If not, qenv by default looks for a .nogit/env.yml file.
|
||||
If any env var is not specified, qenv throws an error and exits.
|
0
dist/index.d.ts
vendored
0
dist/index.d.ts
vendored
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -1,3 +0,0 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbXX0=
|
3
dist/qenv.plugins.d.ts
vendored
3
dist/qenv.plugins.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import smartfile = require("smartfile");
|
6
dist/qenv.plugins.js
vendored
6
dist/qenv.plugins.js
vendored
@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.smartfile = require("smartfile");
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInFlbnYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNqQyxpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDIiwiZmlsZSI6InFlbnYucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQgaW1wb3J0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgaW1wb3J0IHNtYXJ0ZmlsZSA9IHJlcXVpcmUoXCJzbWFydGZpbGVcIik7XG4iXX0=
|
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": "pushrocks",
|
||||
"gitrepo": "qenv",
|
||||
"shortDescription": "easy promised environments",
|
||||
"npmPackagename": "@pushrocks/qenv",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"mode":"default"
|
||||
}
|
5183
package-lock.json
generated
Normal file
5183
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
package.json
43
package.json
@ -1,10 +1,13 @@
|
||||
{
|
||||
"name": "qenv",
|
||||
"version": "1.0.2",
|
||||
"description": "promised environments",
|
||||
"main": "dist/index.js",
|
||||
"name": "@pushrocks/qenv",
|
||||
"version": "4.0.8",
|
||||
"private": false,
|
||||
"description": "easy promised environments",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,14 +25,28 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/qenv#README",
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.6",
|
||||
"should": "^9.0.2",
|
||||
"typings-test": "^1.0.1"
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tsrun": "^1.2.12",
|
||||
"@gitzone/tstest": "^1.0.33",
|
||||
"@pushrocks/tapbundle": "^3.2.1",
|
||||
"@types/node": "^14.0.12",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.12",
|
||||
"q": "^1.4.1",
|
||||
"smartfile": "^3.0.10",
|
||||
"typings-global": "^1.0.3"
|
||||
}
|
||||
"@pushrocks/smartfile": "^7.0.12",
|
||||
"@pushrocks/smartlog": "^2.0.26"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
4
test/assets/env.json
Normal file
4
test/assets/env.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"key1": "fromJson",
|
||||
"key2" :"fromJson"
|
||||
}
|
4
test/assets/qenv.yml
Normal file
4
test/assets/qenv.yml
Normal file
@ -0,0 +1,4 @@
|
||||
required:
|
||||
- key1
|
||||
- key2
|
||||
- key3
|
29
test/test.ts
Normal file
29
test/test.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as path from 'path';
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as qenv from '../ts/index';
|
||||
|
||||
process.env['key1'] = 'original';
|
||||
|
||||
let testQenv: qenv.Qenv;
|
||||
|
||||
tap.test('should create a new class', async () => {
|
||||
testQenv = new qenv.Qenv(path.join(__dirname, 'assets'), path.join(__dirname, 'assets'), false);
|
||||
expect(testQenv).to.be.instanceof(qenv.Qenv);
|
||||
});
|
||||
|
||||
tap.test('key1 should be not be overwritten since it is already present', async () => {
|
||||
expect(testQenv.getEnvVarRequired('key1')).to.equal('original');
|
||||
expect(testQenv.getEnvVarOnDemand('key1')).to.equal('original');
|
||||
});
|
||||
|
||||
tap.test('key2 should be read from Yml', async () => {
|
||||
expect(testQenv.getEnvVarRequired('key2')).to.equal('fromJson');
|
||||
expect(testQenv.getEnvVarOnDemand('key2')).to.equal('fromJson');
|
||||
});
|
||||
|
||||
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
||||
expect(testQenv.keyValueObject.key1).to.equal('original');
|
||||
expect(testQenv.keyValueObject.key2).to.equal('fromJson');
|
||||
});
|
||||
|
||||
tap.start();
|
35
ts/index.ts
35
ts/index.ts
@ -1,34 +1 @@
|
||||
import * as plugins from "./qenv.plugins";
|
||||
|
||||
export class qenv {
|
||||
envVarsRequired:string[];
|
||||
envVarsAvailable:string[];
|
||||
envVarsMissing:string[];
|
||||
constructor(basePathArg = "./qenv.yml",envYmlPathArg){
|
||||
this.envVarsRequired = getEnvVarsRequired(basePathArg);
|
||||
this.envVarsAvailable;
|
||||
}
|
||||
};
|
||||
|
||||
let getEnvVarsRequired = (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 getEnvVarsAvailable = (requiredEnvVarsArg:string[]):string[] => {
|
||||
let result = [];
|
||||
for(let keyArg in requiredEnvVarsArg){
|
||||
let envVar = requiredEnvVarsArg[keyArg];
|
||||
if(process.env[envVar]){
|
||||
result.push(envVar);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export * from './qenv.classes.qenv';
|
||||
|
195
ts/qenv.classes.qenv.ts
Normal file
195
ts/qenv.classes.qenv.ts
Normal file
@ -0,0 +1,195 @@
|
||||
import * as plugins from './qenv.plugins';
|
||||
|
||||
/**
|
||||
* class Qenv
|
||||
* allows to make assertions about the environments while being more flexibel in how to meet them
|
||||
*/
|
||||
export class Qenv {
|
||||
public requiredEnvVars: string[] = [];
|
||||
public availableEnvVars: string[] = [];
|
||||
public missingEnvVars: string[] = [];
|
||||
public keyValueObject: { [key: string]: any } = {};
|
||||
public logger = new plugins.smartlog.ConsoleLog();
|
||||
|
||||
// filePaths
|
||||
public qenvFilePathAbsolute: string;
|
||||
public envFilePathAbsolute: string;
|
||||
|
||||
constructor(qenvFileBasePathArg = process.cwd(), envFileBasePathArg, failOnMissing = true) {
|
||||
// lets make sure paths are absolute
|
||||
this.qenvFilePathAbsolute = plugins.path.join(
|
||||
plugins.path.resolve(qenvFileBasePathArg),
|
||||
'qenv.yml'
|
||||
);
|
||||
this.envFilePathAbsolute = plugins.path.join(
|
||||
plugins.path.resolve(envFileBasePathArg),
|
||||
'env.json'
|
||||
);
|
||||
|
||||
this.getRequiredEnvVars();
|
||||
this.getAvailableEnvVars();
|
||||
|
||||
this.missingEnvVars = this.getMissingEnvVars();
|
||||
|
||||
// handle missing variables
|
||||
if (this.missingEnvVars.length > 0) {
|
||||
console.info('Required Env Vars are:');
|
||||
console.log(this.requiredEnvVars);
|
||||
console.error('However some Env variables could not be resolved:');
|
||||
console.log(this.missingEnvVars);
|
||||
if (failOnMissing) {
|
||||
this.logger.log('error', 'Exiting!');
|
||||
process.exit(1);
|
||||
} else {
|
||||
this.logger.log('warn', 'qenv is not set to fail on missing environment variables');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* only gets an environment variable if it is required within a read qenv.yml file
|
||||
* @param envVarName
|
||||
*/
|
||||
public getEnvVarRequired(envVarName): string {
|
||||
return this.keyValueObject[envVarName];
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to get any env var even if it is not required
|
||||
* @param wantedEnvVar
|
||||
*/
|
||||
public getEnvVarOnDemand(wantedEnvVar: string): string {
|
||||
let envVarFromEnvironmentVariable: string;
|
||||
let envVarFromEnvJsonFile: string;
|
||||
let envVarFromDockerSecret: string;
|
||||
let dockerSecretJson: string;
|
||||
|
||||
// env var check
|
||||
if (process.env[wantedEnvVar]) {
|
||||
this.availableEnvVars.push(wantedEnvVar);
|
||||
envVarFromEnvironmentVariable = process.env[wantedEnvVar];
|
||||
}
|
||||
|
||||
// env file check
|
||||
// lets determine the actual env yml
|
||||
let envJsonFileAsObject;
|
||||
try {
|
||||
envJsonFileAsObject = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
|
||||
} catch (err) {
|
||||
envJsonFileAsObject = {};
|
||||
}
|
||||
if (envJsonFileAsObject.hasOwnProperty(wantedEnvVar)) {
|
||||
envVarFromEnvJsonFile = envJsonFileAsObject[wantedEnvVar];
|
||||
}
|
||||
|
||||
// docker secret check
|
||||
if (
|
||||
plugins.smartfile.fs.isDirectory('/run') &&
|
||||
plugins.smartfile.fs.isDirectory('/run/secrets') &&
|
||||
plugins.smartfile.fs.fileExistsSync(`/run/secrets/${wantedEnvVar}`)
|
||||
) {
|
||||
envVarFromDockerSecret = plugins.smartfile.fs.toStringSync(`/run/secrets/${wantedEnvVar}`);
|
||||
}
|
||||
|
||||
// docker secret.json
|
||||
if (
|
||||
plugins.smartfile.fs.isDirectory('/run') &&
|
||||
plugins.smartfile.fs.isDirectory('/run/secrets')
|
||||
) {
|
||||
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
|
||||
for (const secret of availableSecrets) {
|
||||
if (secret.includes('secret.json') && !envVarFromDockerSecret) {
|
||||
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
|
||||
envVarFromDockerSecret = secretObject[wantedEnvVar];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// warn if there is more than one candidate
|
||||
const availableCcandidates: any[] = [];
|
||||
[
|
||||
envVarFromEnvironmentVariable,
|
||||
envVarFromEnvJsonFile,
|
||||
envVarFromDockerSecret,
|
||||
dockerSecretJson
|
||||
].forEach(candidate => {
|
||||
if (candidate) {
|
||||
availableCcandidates.push(candidate);
|
||||
}
|
||||
});
|
||||
if (availableCcandidates.length > 1) {
|
||||
this.logger.log(
|
||||
'warn',
|
||||
`found multiple candidates for ${wantedEnvVar} Choosing in the order of envVar, envFileVar, dockerSecret, dockerSecretJson`
|
||||
);
|
||||
console.log(availableCcandidates);
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case !!envVarFromEnvironmentVariable:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as environment variable`);
|
||||
return envVarFromEnvironmentVariable;
|
||||
case !!envVarFromEnvJsonFile:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as env.json variable`);
|
||||
return envVarFromEnvJsonFile;
|
||||
case !!envVarFromDockerSecret:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as docker secret`);
|
||||
return envVarFromDockerSecret;
|
||||
case !!dockerSecretJson:
|
||||
this.logger.log('ok', `found ${wantedEnvVar} as docker secret.json`);
|
||||
return dockerSecretJson;
|
||||
default:
|
||||
this.logger.log(
|
||||
'warn',
|
||||
`could not find the wanted environment variable ${wantedEnvVar} anywhere`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the required env values
|
||||
*/
|
||||
private getRequiredEnvVars = () => {
|
||||
let qenvFile: any = {};
|
||||
if (plugins.smartfile.fs.fileExistsSync(this.qenvFilePathAbsolute)) {
|
||||
qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
|
||||
}
|
||||
if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) {
|
||||
this.logger.log(
|
||||
'warn',
|
||||
`qenv (promised environment): ./qenv.yml File does not contain a 'required' Array! This might be ok though.`
|
||||
);
|
||||
} else {
|
||||
for (const keyArg of Object.keys(qenvFile.required)) {
|
||||
this.requiredEnvVars.push(qenvFile.required[keyArg]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* gets the available env vars
|
||||
*/
|
||||
private getAvailableEnvVars = () => {
|
||||
for (const requiredEnvVar of this.requiredEnvVars) {
|
||||
const chosenVar = this.getEnvVarOnDemand(requiredEnvVar);
|
||||
if (chosenVar) {
|
||||
this.availableEnvVars.push(requiredEnvVar);
|
||||
this.keyValueObject[requiredEnvVar] = chosenVar;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* gets missing env vars
|
||||
*/
|
||||
private getMissingEnvVars = (): string[] => {
|
||||
const missingEnvVars: string[] = [];
|
||||
for (const envVar of this.requiredEnvVars) {
|
||||
if (!this.availableEnvVars.includes(envVar)) {
|
||||
missingEnvVars.push(envVar);
|
||||
}
|
||||
}
|
||||
return missingEnvVars;
|
||||
};
|
||||
}
|
@ -1,4 +1,10 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import path = require("path");
|
||||
export import smartfile = require("smartfile");
|
||||
// native
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
|
||||
export { smartfile, smartlog };
|
||||
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user