@catladder/cli 1.103.0 → 1.104.0

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/package.json CHANGED
@@ -24,7 +24,7 @@
24
24
  "node": ">=12.0.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@catladder/pipeline": "1.103.0",
27
+ "@catladder/pipeline": "1.104.0",
28
28
  "@kubernetes/client-node": "^0.16.2",
29
29
  "@tsconfig/node14": "^1.0.1",
30
30
  "@types/common-tags": "^1.8.0",
@@ -57,5 +57,5 @@
57
57
  "typescript": "^4.5.4",
58
58
  "vorpal": "^1.12.0"
59
59
  },
60
- "version": "1.103.0"
60
+ "version": "1.104.0"
61
61
  }
@@ -2,6 +2,7 @@ import { getProjectConfig } from "../../config/getProjectConfig";
2
2
  import { printVariables } from "./printVariables";
3
3
  import type { Choice } from "./types";
4
4
  import { writeDotEnvFiles } from "./writeDotEnvFiles";
5
+ import { writeDTsFiles } from "./writeEnvDTs";
5
6
 
6
7
  export default async (choice?: Choice) => {
7
8
  const config = await getProjectConfig();
@@ -12,4 +13,6 @@ export default async (choice?: Choice) => {
12
13
  await printVariables(config, choice);
13
14
 
14
15
  await writeDotEnvFiles(config, choice);
16
+
17
+ await writeDTsFiles(config, choice);
15
18
  };
@@ -0,0 +1,71 @@
1
+ import type { Config } from "@catladder/pipeline";
2
+ import { writeFile } from "fs-extra";
3
+ import { join } from "path";
4
+ import { getEnvironment } from "../../config/getProjectConfig";
5
+ import { getGitRoot } from "../../utils/projects";
6
+ import type { Choice } from "./types";
7
+ import {
8
+ getComponentFullPath,
9
+ getCurrentComponentAndEnvFromChoice,
10
+ } from "./utils";
11
+
12
+ export const writeDTsFiles = async (config: Config, choice?: Choice) => {
13
+ const { env, currentComponent } = await getCurrentComponentAndEnvFromChoice(
14
+ config,
15
+ choice
16
+ );
17
+
18
+ const componentsWithEnabledEnvDTsWrite = Object.entries(config.components)
19
+ .filter(([, component]) => component?.envDTs)
20
+ .map(([componentName]) => componentName);
21
+
22
+ const componentsToActuallyWriteDotEnvNow = currentComponent
23
+ ? componentsWithEnabledEnvDTsWrite.includes(currentComponent)
24
+ ? [currentComponent]
25
+ : []
26
+ : componentsWithEnabledEnvDTsWrite;
27
+ const gitRoot = await getGitRoot();
28
+
29
+ for (const componentName of componentsToActuallyWriteDotEnvNow) {
30
+ const envNames = await getEnvsForDTs(env, componentName);
31
+ const envDTsContent = createEnvDTsContent(envNames);
32
+
33
+ const componentDir = getComponentFullPath(gitRoot, config, componentName);
34
+ const filePath = join(componentDir, "env.d.ts");
35
+ await writeFile(filePath, envDTsContent);
36
+ }
37
+ };
38
+
39
+ async function getEnvsForDTs(
40
+ env: string,
41
+ componentName: string
42
+ ): Promise<string[]> {
43
+ const environment = await getEnvironment(env, componentName);
44
+ const allEnvKeys = Object.keys(environment.envVars);
45
+ const hiddenEnvKeys = new Set(
46
+ environment.secretEnvVarKeys
47
+ .filter((s) => s.hidden)
48
+ .map((s) => s.key)
49
+ .concat(["_ALL_ENV_VAR_KEYS"])
50
+ );
51
+ const dTsEnvKeys = allEnvKeys.filter((k) => !hiddenEnvKeys.has(k));
52
+
53
+ return dTsEnvKeys;
54
+ }
55
+
56
+ function createEnvDTsContent(envNames: string[]) {
57
+ return `/* tslint:disable prettier/prettier */
58
+ /* eslint-disable prettier/prettier */
59
+ /* prettier-ignore */
60
+ // automatically generated by catladder. Do not modify!
61
+ export {}
62
+
63
+ declare global {
64
+ namespace NodeJS {
65
+ interface ProcessEnv {
66
+ ${envNames.map((name) => ` ${name}: string`).join("\n")}
67
+ }
68
+ }
69
+ }
70
+ `;
71
+ }