task-script-support-cli 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/yargs-template/task-runner/src/tasks/check-env.ts +7 -7
- package/assets/yargs-template/task-runner/src/types/state.ts +5 -3
- package/assets/yargs-template/task-runner/tests/tasks/check-env.test.ts +8 -3
- package/dist/assets/yargs-template/task-runner/src/tasks/check-env.ts +7 -7
- package/dist/assets/yargs-template/task-runner/src/types/state.ts +5 -3
- package/dist/assets/yargs-template/task-runner/tests/tasks/check-env.test.ts +8 -3
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { AppTask } from "../wrappers/app-task";
|
|
3
3
|
import { autoInjectable } from "tsyringe";
|
|
4
|
-
import { EnvironmentConfigKeys } from "../types/state";
|
|
4
|
+
import { EnvironmentConfigKeys, EnvKey } from "../types/state";
|
|
5
5
|
import { UtilService } from "../services/util-service";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -11,17 +11,17 @@ import { UtilService } from "../services/util-service";
|
|
|
11
11
|
export default class CheckEnv extends AppTask {
|
|
12
12
|
loggerName = "Check Environment";
|
|
13
13
|
|
|
14
|
-
requiredEnv:
|
|
15
|
-
secretEnv: Set<
|
|
14
|
+
requiredEnv: Set<EnvKey> = new Set();
|
|
15
|
+
secretEnv: Set<EnvKey> = new Set([
|
|
16
16
|
// add keys that should be masked in log output here
|
|
17
17
|
]);
|
|
18
|
-
optionalEnv = [
|
|
18
|
+
optionalEnv: Set<EnvKey> = new Set([
|
|
19
19
|
EnvironmentConfigKeys.NODE_ENV,
|
|
20
20
|
EnvironmentConfigKeys.PINO_LOG_TARGET,
|
|
21
21
|
EnvironmentConfigKeys.PINO_LOG_DIR_PATH,
|
|
22
22
|
EnvironmentConfigKeys.PINO_LOG_FILENAME,
|
|
23
23
|
EnvironmentConfigKeys.PINO_LOG_LEVEL,
|
|
24
|
-
];
|
|
24
|
+
]);
|
|
25
25
|
|
|
26
26
|
async run() {
|
|
27
27
|
this.logger.debug(chalk.blueBright("Running Check Environment"));
|
|
@@ -32,7 +32,7 @@ export default class CheckEnv extends AppTask {
|
|
|
32
32
|
.filter((e) => !!process.env[e])
|
|
33
33
|
.forEach((e) => {
|
|
34
34
|
let envVal = process.env[e] || "";
|
|
35
|
-
if (this.secretEnv.has(e)) {
|
|
35
|
+
if (this.secretEnv.has(e as EnvKey)) {
|
|
36
36
|
envVal = UtilService.maskValue(envVal);
|
|
37
37
|
}
|
|
38
38
|
this.logger.debug(
|
|
@@ -40,7 +40,7 @@ export default class CheckEnv extends AppTask {
|
|
|
40
40
|
);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
this.requiredEnv
|
|
43
|
+
[...this.requiredEnv]
|
|
44
44
|
.filter((e) => !process.env[e])
|
|
45
45
|
.forEach((e) =>
|
|
46
46
|
errorMessages.push(`Missing required environment variable ${e}`),
|
|
@@ -3,8 +3,8 @@ import yargs from "yargs";
|
|
|
3
3
|
|
|
4
4
|
// Add app data here as needed. Use readonly for immutable fields.
|
|
5
5
|
//
|
|
6
|
-
// Note: this object gets passed to deepMerge upon updating app state
|
|
7
|
-
// which also merges array fields. This might be fine or you might want
|
|
6
|
+
// Note: this object gets passed to deepMerge upon updating the app state,
|
|
7
|
+
// which also merges array fields. This might be fine, or you might want
|
|
8
8
|
// to make your arrays <type>[] | undefined to allow clobbering.
|
|
9
9
|
export interface AppStateData {
|
|
10
10
|
readonly errorMessages?: string[];
|
|
@@ -29,7 +29,9 @@ export const EnvironmentConfigKeys = {
|
|
|
29
29
|
NODE_ENV: "NODE_ENV",
|
|
30
30
|
PINO_LOG_FILENAME: "PINO_LOG_FILENAME",
|
|
31
31
|
PINO_LOG_TARGET: "PINO_LOG_TARGET",
|
|
32
|
-
};
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export type EnvKey = keyof typeof EnvironmentConfigKeys;
|
|
33
35
|
|
|
34
36
|
export const DefaultValues = {
|
|
35
37
|
debugMode: false,
|
|
@@ -4,6 +4,7 @@ import { LogService } from "../../src/services/log-service";
|
|
|
4
4
|
import { CommandService } from "task-script-support";
|
|
5
5
|
import { AppStateData, CLIArgs } from "../../src/types/state";
|
|
6
6
|
import { container } from "tsyringe";
|
|
7
|
+
import chalk from "chalk";
|
|
7
8
|
|
|
8
9
|
describe("CheckEnv", () => {
|
|
9
10
|
let mockLogService = {} as LogService;
|
|
@@ -37,7 +38,7 @@ describe("CheckEnv", () => {
|
|
|
37
38
|
|
|
38
39
|
await checkEnv.run();
|
|
39
40
|
expect(mockLogService.debug).toHaveBeenCalledWith(
|
|
40
|
-
"Running Check Environment",
|
|
41
|
+
chalk.blueBright("Running Check Environment"),
|
|
41
42
|
);
|
|
42
43
|
expect(checkEnv.state.data.environmentValidated).toBe(true);
|
|
43
44
|
});
|
|
@@ -48,7 +49,7 @@ describe("CheckEnv", () => {
|
|
|
48
49
|
throw testError;
|
|
49
50
|
});
|
|
50
51
|
const checkEnv = container.resolve(CheckEnv);
|
|
51
|
-
checkEnv.requiredEnv = ["MISSING_ENV_VAR"];
|
|
52
|
+
(checkEnv.requiredEnv as unknown) = ["MISSING_ENV_VAR"];
|
|
52
53
|
try {
|
|
53
54
|
expect(await checkEnv.run()).toThrow(testError);
|
|
54
55
|
} catch (err) {
|
|
@@ -65,7 +66,11 @@ describe("CheckEnv", () => {
|
|
|
65
66
|
throw testError;
|
|
66
67
|
});
|
|
67
68
|
const checkEnv = container.resolve(CheckEnv);
|
|
68
|
-
checkEnv.requiredEnv = [
|
|
69
|
+
(checkEnv.requiredEnv as unknown) = [
|
|
70
|
+
"MISSING_ENV_1",
|
|
71
|
+
"MISSING_ENV_2",
|
|
72
|
+
"MISSING_ENV_3",
|
|
73
|
+
];
|
|
69
74
|
try {
|
|
70
75
|
await checkEnv.run();
|
|
71
76
|
} catch (err) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { AppTask } from "../wrappers/app-task";
|
|
3
3
|
import { autoInjectable } from "tsyringe";
|
|
4
|
-
import { EnvironmentConfigKeys } from "../types/state";
|
|
4
|
+
import { EnvironmentConfigKeys, EnvKey } from "../types/state";
|
|
5
5
|
import { UtilService } from "../services/util-service";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -11,17 +11,17 @@ import { UtilService } from "../services/util-service";
|
|
|
11
11
|
export default class CheckEnv extends AppTask {
|
|
12
12
|
loggerName = "Check Environment";
|
|
13
13
|
|
|
14
|
-
requiredEnv:
|
|
15
|
-
secretEnv: Set<
|
|
14
|
+
requiredEnv: Set<EnvKey> = new Set();
|
|
15
|
+
secretEnv: Set<EnvKey> = new Set([
|
|
16
16
|
// add keys that should be masked in log output here
|
|
17
17
|
]);
|
|
18
|
-
optionalEnv = [
|
|
18
|
+
optionalEnv: Set<EnvKey> = new Set([
|
|
19
19
|
EnvironmentConfigKeys.NODE_ENV,
|
|
20
20
|
EnvironmentConfigKeys.PINO_LOG_TARGET,
|
|
21
21
|
EnvironmentConfigKeys.PINO_LOG_DIR_PATH,
|
|
22
22
|
EnvironmentConfigKeys.PINO_LOG_FILENAME,
|
|
23
23
|
EnvironmentConfigKeys.PINO_LOG_LEVEL,
|
|
24
|
-
];
|
|
24
|
+
]);
|
|
25
25
|
|
|
26
26
|
async run() {
|
|
27
27
|
this.logger.debug(chalk.blueBright("Running Check Environment"));
|
|
@@ -32,7 +32,7 @@ export default class CheckEnv extends AppTask {
|
|
|
32
32
|
.filter((e) => !!process.env[e])
|
|
33
33
|
.forEach((e) => {
|
|
34
34
|
let envVal = process.env[e] || "";
|
|
35
|
-
if (this.secretEnv.has(e)) {
|
|
35
|
+
if (this.secretEnv.has(e as EnvKey)) {
|
|
36
36
|
envVal = UtilService.maskValue(envVal);
|
|
37
37
|
}
|
|
38
38
|
this.logger.debug(
|
|
@@ -40,7 +40,7 @@ export default class CheckEnv extends AppTask {
|
|
|
40
40
|
);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
this.requiredEnv
|
|
43
|
+
[...this.requiredEnv]
|
|
44
44
|
.filter((e) => !process.env[e])
|
|
45
45
|
.forEach((e) =>
|
|
46
46
|
errorMessages.push(`Missing required environment variable ${e}`),
|
|
@@ -3,8 +3,8 @@ import yargs from "yargs";
|
|
|
3
3
|
|
|
4
4
|
// Add app data here as needed. Use readonly for immutable fields.
|
|
5
5
|
//
|
|
6
|
-
// Note: this object gets passed to deepMerge upon updating app state
|
|
7
|
-
// which also merges array fields. This might be fine or you might want
|
|
6
|
+
// Note: this object gets passed to deepMerge upon updating the app state,
|
|
7
|
+
// which also merges array fields. This might be fine, or you might want
|
|
8
8
|
// to make your arrays <type>[] | undefined to allow clobbering.
|
|
9
9
|
export interface AppStateData {
|
|
10
10
|
readonly errorMessages?: string[];
|
|
@@ -29,7 +29,9 @@ export const EnvironmentConfigKeys = {
|
|
|
29
29
|
NODE_ENV: "NODE_ENV",
|
|
30
30
|
PINO_LOG_FILENAME: "PINO_LOG_FILENAME",
|
|
31
31
|
PINO_LOG_TARGET: "PINO_LOG_TARGET",
|
|
32
|
-
};
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export type EnvKey = keyof typeof EnvironmentConfigKeys;
|
|
33
35
|
|
|
34
36
|
export const DefaultValues = {
|
|
35
37
|
debugMode: false,
|
|
@@ -4,6 +4,7 @@ import { LogService } from "../../src/services/log-service";
|
|
|
4
4
|
import { CommandService } from "task-script-support";
|
|
5
5
|
import { AppStateData, CLIArgs } from "../../src/types/state";
|
|
6
6
|
import { container } from "tsyringe";
|
|
7
|
+
import chalk from "chalk";
|
|
7
8
|
|
|
8
9
|
describe("CheckEnv", () => {
|
|
9
10
|
let mockLogService = {} as LogService;
|
|
@@ -37,7 +38,7 @@ describe("CheckEnv", () => {
|
|
|
37
38
|
|
|
38
39
|
await checkEnv.run();
|
|
39
40
|
expect(mockLogService.debug).toHaveBeenCalledWith(
|
|
40
|
-
"Running Check Environment",
|
|
41
|
+
chalk.blueBright("Running Check Environment"),
|
|
41
42
|
);
|
|
42
43
|
expect(checkEnv.state.data.environmentValidated).toBe(true);
|
|
43
44
|
});
|
|
@@ -48,7 +49,7 @@ describe("CheckEnv", () => {
|
|
|
48
49
|
throw testError;
|
|
49
50
|
});
|
|
50
51
|
const checkEnv = container.resolve(CheckEnv);
|
|
51
|
-
checkEnv.requiredEnv = ["MISSING_ENV_VAR"];
|
|
52
|
+
(checkEnv.requiredEnv as unknown) = ["MISSING_ENV_VAR"];
|
|
52
53
|
try {
|
|
53
54
|
expect(await checkEnv.run()).toThrow(testError);
|
|
54
55
|
} catch (err) {
|
|
@@ -65,7 +66,11 @@ describe("CheckEnv", () => {
|
|
|
65
66
|
throw testError;
|
|
66
67
|
});
|
|
67
68
|
const checkEnv = container.resolve(CheckEnv);
|
|
68
|
-
checkEnv.requiredEnv = [
|
|
69
|
+
(checkEnv.requiredEnv as unknown) = [
|
|
70
|
+
"MISSING_ENV_1",
|
|
71
|
+
"MISSING_ENV_2",
|
|
72
|
+
"MISSING_ENV_3",
|
|
73
|
+
];
|
|
69
74
|
try {
|
|
70
75
|
await checkEnv.run();
|
|
71
76
|
} catch (err) {
|
package/dist/package.json
CHANGED