cdktn-cli 0.0.1 → 0.22.0-pre.2

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.
Files changed (82) hide show
  1. package/README.md +1 -0
  2. package/ambient.d.ts +13 -0
  3. package/build.js +139 -0
  4. package/bundle/bin/cdktn +2 -0
  5. package/bundle/bin/cdktn.js +89 -0
  6. package/bundle/bin/cdktn.js.map +7 -0
  7. package/bundle/bin/cmds/handlers.js +739 -0
  8. package/bundle/bin/cmds/handlers.js.map +7 -0
  9. package/bundle/templates/csharp/.hooks.sscaff.js +63 -0
  10. package/bundle/templates/csharp/MainStack.cs +15 -0
  11. package/bundle/templates/csharp/MyTerraformStack.csproj +13 -0
  12. package/bundle/templates/csharp/Program.cs +17 -0
  13. package/bundle/templates/csharp/TestProgram.cs +42 -0
  14. package/bundle/templates/csharp/cdktf.json +11 -0
  15. package/bundle/templates/csharp/help +42 -0
  16. package/bundle/templates/csharp/{{}}.gitignore +345 -0
  17. package/bundle/templates/go/.hooks.sscaff.js +70 -0
  18. package/bundle/templates/go/cdktf.json +12 -0
  19. package/bundle/templates/go/go.mod +8 -0
  20. package/bundle/templates/go/help +32 -0
  21. package/bundle/templates/go/main.go +22 -0
  22. package/bundle/templates/go/main_test.go +42 -0
  23. package/bundle/templates/go/{{}}.gitignore +21 -0
  24. package/bundle/templates/java/.hooks.sscaff.js +64 -0
  25. package/bundle/templates/java/build.gradle +55 -0
  26. package/bundle/templates/java/cdktf.json +12 -0
  27. package/bundle/templates/java/gradle.properties +1 -0
  28. package/bundle/templates/java/gradlew +248 -0
  29. package/bundle/templates/java/gradlew.bat +92 -0
  30. package/bundle/templates/java/help +35 -0
  31. package/bundle/templates/java/settings.gradle +5 -0
  32. package/bundle/templates/java/src/main/java/com/mycompany/app/Main.java +16 -0
  33. package/bundle/templates/java/src/main/java/com/mycompany/app/MainStack.java +14 -0
  34. package/bundle/templates/java/src/test/java/com/company/app/MainTest.java +38 -0
  35. package/bundle/templates/java/{{}}.gitignore +14 -0
  36. package/bundle/templates/python/.hooks.sscaff.js +59 -0
  37. package/bundle/templates/python/Pipfile +7 -0
  38. package/bundle/templates/python/cdktf.json +12 -0
  39. package/bundle/templates/python/help +42 -0
  40. package/bundle/templates/python/main-test.py +26 -0
  41. package/bundle/templates/python/main.py +16 -0
  42. package/bundle/templates/python/{{}}.gitignore +7 -0
  43. package/bundle/templates/python-pip/.hooks.sscaff.js +63 -0
  44. package/bundle/templates/python-pip/cdktf.json +12 -0
  45. package/bundle/templates/python-pip/help +35 -0
  46. package/bundle/templates/python-pip/main-test.py +23 -0
  47. package/bundle/templates/python-pip/main.py +16 -0
  48. package/bundle/templates/python-pip/{{}}.gitignore +7 -0
  49. package/bundle/templates/typescript/.hooks.sscaff.js +78 -0
  50. package/bundle/templates/typescript/__tests__/main-test.ts +89 -0
  51. package/bundle/templates/typescript/cdktf.json +11 -0
  52. package/bundle/templates/typescript/help +51 -0
  53. package/bundle/templates/typescript/jest.config.js +187 -0
  54. package/bundle/templates/typescript/main.ts +14 -0
  55. package/bundle/templates/typescript/package.json +22 -0
  56. package/bundle/templates/typescript/setup.js +2 -0
  57. package/bundle/templates/typescript/tsconfig.json +35 -0
  58. package/bundle/templates/typescript/{{}}.gitignore +11 -0
  59. package/eslint.config.mjs +80 -0
  60. package/jest.config.js +19 -0
  61. package/package.json +133 -7
  62. package/src/bin/cdktn +2 -0
  63. package/src/bin/cmds/helper/__tests__/fixtures/foo.tfvars +4 -0
  64. package/src/bin/cmds/helper/__tests__/fixtures/hey-there.auto.tfvars +5 -0
  65. package/src/bin/cmds/helper/__tests__/fixtures/terraform.tfvars +4 -0
  66. package/src/bin/cmds/helper/render-ink.tsx +24 -0
  67. package/src/bin/cmds/ui/components/bottom-bars/approve.tsx +81 -0
  68. package/src/bin/cmds/ui/components/bottom-bars/outputs.tsx +30 -0
  69. package/src/bin/cmds/ui/components/bottom-bars/override.tsx +68 -0
  70. package/src/bin/cmds/ui/components/bottom-bars/status.tsx +183 -0
  71. package/src/bin/cmds/ui/components/outputs.tsx +103 -0
  72. package/src/bin/cmds/ui/components/stream-view.tsx +72 -0
  73. package/src/bin/cmds/ui/deploy.tsx +139 -0
  74. package/src/bin/cmds/ui/destroy.tsx +86 -0
  75. package/src/bin/cmds/ui/diff.tsx +59 -0
  76. package/src/bin/cmds/ui/get.tsx +134 -0
  77. package/src/bin/cmds/ui/list.tsx +59 -0
  78. package/src/bin/cmds/ui/output.tsx +52 -0
  79. package/src/bin/cmds/ui/provider-list.tsx +17 -0
  80. package/src/bin/cmds/ui/synth.tsx +51 -0
  81. package/src/bin/cmds/ui/watch.tsx +80 -0
  82. package/index.js +0 -2
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import React from "react";
7
+
8
+ import { useCdktfProject } from "./hooks/cdktf-project";
9
+ import { StreamView, StatusBottomBar } from "./components";
10
+
11
+ interface DiffConfig {
12
+ outDir: string;
13
+ targetStack?: string;
14
+ synthCommand: string;
15
+ refreshOnly?: boolean;
16
+ terraformParallelism?: number;
17
+ vars?: string[];
18
+ varFiles?: string[];
19
+ noColor?: boolean;
20
+ migrateState?: boolean;
21
+ skipSynth?: boolean;
22
+ skipProviderLock?: boolean;
23
+ }
24
+
25
+ export const Diff = ({
26
+ outDir,
27
+ targetStack,
28
+ synthCommand,
29
+ refreshOnly,
30
+ terraformParallelism,
31
+ vars,
32
+ varFiles,
33
+ noColor,
34
+ migrateState,
35
+ skipSynth,
36
+ skipProviderLock,
37
+ }: DiffConfig): React.ReactElement => {
38
+ const { status, logEntries } = useCdktfProject(
39
+ { outDir, synthCommand },
40
+ (project) =>
41
+ project.diff({
42
+ stackName: targetStack,
43
+ refreshOnly,
44
+ terraformParallelism,
45
+ vars,
46
+ varFiles,
47
+ noColor,
48
+ migrateState,
49
+ skipSynth,
50
+ skipProviderLock,
51
+ }),
52
+ );
53
+
54
+ return (
55
+ <StreamView logs={logEntries}>
56
+ <StatusBottomBar status={status} />
57
+ </StreamView>
58
+ );
59
+ };
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import React, { Fragment } from "react";
7
+
8
+ import { Text, Box, useApp, Newline } from "ink";
9
+ import Spinner from "ink-spinner";
10
+ import { GetOptions } from "@cdktn/provider-generator";
11
+ import {
12
+ IsErrorType,
13
+ Language,
14
+ sendTelemetry,
15
+ TerraformDependencyConstraint,
16
+ } from "@cdktn/commons";
17
+ import { get, GetStatus as Status } from "@cdktn/cli-core";
18
+
19
+ interface GetConfig {
20
+ codeMakerOutput: string;
21
+ language: Language;
22
+ constraints: TerraformDependencyConstraint[];
23
+ parallelism: number;
24
+ force?: boolean;
25
+ silent?: boolean;
26
+ providerSchemaCachePath?: string;
27
+ }
28
+
29
+ export const Get = ({
30
+ codeMakerOutput,
31
+ language,
32
+ constraints,
33
+ parallelism,
34
+ force,
35
+ silent = false,
36
+ providerSchemaCachePath,
37
+ }: GetConfig): React.ReactElement => {
38
+ const [currentStatus, setCurrentStatus] = React.useState<Status>(
39
+ Status.STARTING,
40
+ );
41
+ const { exit } = useApp();
42
+
43
+ const constructsOptions: GetOptions = {
44
+ codeMakerOutput: codeMakerOutput,
45
+ targetLanguage: language,
46
+ jsiiParallelism: parallelism,
47
+ };
48
+
49
+ React.useEffect(() => {
50
+ const runGet = async () => {
51
+ try {
52
+ await get({
53
+ constraints,
54
+ constructsOptions,
55
+ cleanDirectory: force,
56
+ onUpdate: setCurrentStatus,
57
+ providerSchemaCachePath,
58
+ reportTelemetry: async (payload) =>
59
+ await sendTelemetry("get", {
60
+ language: payload.targetLanguage,
61
+ ...payload.trackingPayload,
62
+ }),
63
+ });
64
+ } catch (e: any) {
65
+ // No stack trace for usage errors, as they explain themselves
66
+ if (!IsErrorType(e, "Usage")) {
67
+ console.error(e);
68
+ }
69
+
70
+ exit(new Error(e));
71
+ }
72
+ };
73
+ runGet();
74
+ // eslint-disable-next-line react-hooks/exhaustive-deps
75
+ }, []); // only once, we don't expect props to change
76
+
77
+ React.useEffect(() => {
78
+ if (currentStatus === Status.DONE) {
79
+ exit();
80
+ }
81
+ if (currentStatus === Status.ERROR) {
82
+ exit(
83
+ new Error(
84
+ `ERROR: synthesis failed, app expected to create "${codeMakerOutput}"`,
85
+ ),
86
+ );
87
+ }
88
+ }, [currentStatus]);
89
+
90
+ const isGenerating: boolean = currentStatus != Status.DONE;
91
+ const statusText = `${currentStatus}...`;
92
+ const jsonTerraformOutput = (
93
+ <Text>
94
+ Generated <Text color="green">{language}</Text> constructs in the output
95
+ directory: <Text bold>{codeMakerOutput}</Text>
96
+ {language === Language.GO && (
97
+ <>
98
+ <Newline />
99
+ <Newline />
100
+ <Text>
101
+ The generated code depends on{" "}
102
+ <Text color="cyan">jsii-runtime-go</Text>. If you haven&apos;t yet
103
+ installed it, you can run{" "}
104
+ <Text color="blueBright">go mod tidy</Text> to automatically install
105
+ it.
106
+ </Text>
107
+ </>
108
+ )}
109
+ </Text>
110
+ );
111
+
112
+ if (silent) {
113
+ return <Text></Text>;
114
+ }
115
+
116
+ return (
117
+ <Box>
118
+ {isGenerating ? (
119
+ <Fragment>
120
+ <Text color="green">
121
+ <Spinner type="dots" />
122
+ </Text>
123
+ <Box paddingLeft={1}>
124
+ <Text>{statusText}</Text>
125
+ </Box>
126
+ </Fragment>
127
+ ) : (
128
+ <Fragment>
129
+ <Box>{jsonTerraformOutput}</Box>
130
+ </Fragment>
131
+ )}
132
+ </Box>
133
+ );
134
+ };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import React, { Fragment } from "react";
7
+ import { Text, Box } from "ink";
8
+ import { useCdktfProject } from "./hooks/cdktf-project";
9
+ import { StreamView, StatusBottomBar } from "./components";
10
+
11
+ interface ListConfig {
12
+ outDir: string;
13
+ synthCommand: string;
14
+ }
15
+
16
+ export const List = ({
17
+ outDir,
18
+ synthCommand,
19
+ }: ListConfig): React.ReactElement => {
20
+ const { status, logEntries, returnValue } = useCdktfProject(
21
+ { outDir, synthCommand },
22
+ (project) => project.synth(),
23
+ );
24
+
25
+ return (
26
+ <StreamView logs={logEntries}>
27
+ <StatusBottomBar status={status}>
28
+ {status.type === "done" ? (
29
+ <Box>
30
+ <Fragment>
31
+ <Box flexDirection="column">
32
+ <Box>
33
+ <Box width="40%">
34
+ <Text bold>Stack name</Text>
35
+ </Box>
36
+ <Box width="60%">
37
+ <Text bold>Path</Text>
38
+ </Box>
39
+ </Box>
40
+ {returnValue!.map((stack) => (
41
+ <Box key={stack.name}>
42
+ <Box width="40%" paddingRight={1}>
43
+ <Text>{stack.name}</Text>
44
+ </Box>
45
+ <Box width="60%">
46
+ <Text>{stack.workingDirectory}</Text>
47
+ </Box>
48
+ </Box>
49
+ ))}
50
+ </Box>
51
+ </Fragment>
52
+ </Box>
53
+ ) : (
54
+ <></>
55
+ )}
56
+ </StatusBottomBar>
57
+ </StreamView>
58
+ );
59
+ };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ /* eslint-disable no-control-regex */
7
+ import React from "react";
8
+ import { NestedTerraformOutputs } from "@cdktn/cli-core";
9
+ import { useCdktfProject } from "./hooks/cdktf-project";
10
+ import { StreamView, OutputsBottomBar, StatusBottomBar } from "./components";
11
+
12
+ type OutputConfig = {
13
+ outDir: string;
14
+ targetStacks?: string[];
15
+ synthCommand: string;
16
+ onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void;
17
+ outputsPath?: string;
18
+ skipSynth?: boolean;
19
+ skipProviderLock?: boolean;
20
+ };
21
+
22
+ export const Output = ({
23
+ outDir,
24
+ targetStacks,
25
+ synthCommand,
26
+ onOutputsRetrieved,
27
+ outputsPath,
28
+ skipSynth,
29
+ skipProviderLock,
30
+ }: OutputConfig): React.ReactElement => {
31
+ const { status, logEntries, returnValue } = useCdktfProject(
32
+ { outDir, synthCommand },
33
+ async (project) => {
34
+ const outputs = await project.fetchOutputs({
35
+ stackNames: targetStacks,
36
+ skipSynth,
37
+ skipProviderLock,
38
+ });
39
+ onOutputsRetrieved(outputs);
40
+ return outputs;
41
+ },
42
+ );
43
+
44
+ const bottomBar =
45
+ status.type === "done" ? (
46
+ <OutputsBottomBar outputs={returnValue} outputsFile={outputsPath} />
47
+ ) : (
48
+ <StatusBottomBar status={status} />
49
+ );
50
+
51
+ return <StreamView logs={logEntries}>{bottomBar}</StreamView>;
52
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import React from "react";
7
+ import Table from "ink-table";
8
+
9
+ interface ProviderListProps {
10
+ data: any[];
11
+ }
12
+
13
+ export const ProviderListTable = ({
14
+ data,
15
+ }: ProviderListProps): React.ReactElement => {
16
+ return <Table data={data} />;
17
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import React from "react";
7
+ import { Text } from "ink";
8
+
9
+ import { useCdktfProject } from "./hooks/cdktf-project";
10
+ import { StreamView } from "./components";
11
+ import { SynthesizedStack } from "@cdktn/cli-core";
12
+ import { StatusBottomBar } from "./components/bottom-bars/status";
13
+
14
+ interface CommonSynthConfig {
15
+ outDir: string;
16
+ }
17
+
18
+ interface SynthConfig extends CommonSynthConfig {
19
+ synthCommand: string;
20
+ hcl: boolean;
21
+ }
22
+ type SynthOutputConfig = {
23
+ stacks: SynthesizedStack[];
24
+ };
25
+ const SynthOutput = ({ stacks }: SynthOutputConfig): React.ReactElement => {
26
+ return (
27
+ <Text>
28
+ Generated Terraform code for the stacks:{" "}
29
+ {stacks?.map((s) => s.name).join(", ")}
30
+ </Text>
31
+ );
32
+ };
33
+
34
+ export const Synth = ({
35
+ outDir,
36
+ synthCommand,
37
+ hcl,
38
+ }: SynthConfig): React.ReactElement => {
39
+ const { returnValue, logEntries, status } = useCdktfProject(
40
+ { outDir, synthCommand, hcl },
41
+ (project) => project.synth(),
42
+ );
43
+
44
+ return (
45
+ <StreamView logs={logEntries}>
46
+ <StatusBottomBar status={status}>
47
+ <SynthOutput stacks={status.type === "done" ? returnValue! : []} />
48
+ </StatusBottomBar>
49
+ </StreamView>
50
+ );
51
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import React, { useEffect, useState } from "react";
7
+ import { watch, WatchState } from "@cdktn/cli-core";
8
+ import { StreamView, WatchStatusBottomBar } from "./components";
9
+ import { LogEntry } from "./hooks/cdktf-project";
10
+
11
+ interface WatchConfig {
12
+ targetDir: string;
13
+ targetStacks?: string[];
14
+ parallelism?: number;
15
+ synthCommand: string;
16
+ autoApprove: boolean;
17
+ terraformParallelism?: number;
18
+ }
19
+
20
+ export const Watch = ({
21
+ targetDir,
22
+ targetStacks,
23
+ synthCommand,
24
+ autoApprove,
25
+ parallelism,
26
+ terraformParallelism,
27
+ }: WatchConfig): React.ReactElement => {
28
+ const [logEntryId, setLogEntryId] = useState<number>(0);
29
+ const [logEntries, setLogEntries] = useState<LogEntry[]>([]);
30
+ const [currentState, setCurrentState] = useState<WatchState>({
31
+ type: "waiting",
32
+ });
33
+
34
+ useEffect(() => {
35
+ const ac = new AbortController();
36
+ const onAbort = () => {
37
+ ac.abort();
38
+ };
39
+ process.on("SIGINT", onAbort);
40
+ process.on("SIGTERM", onAbort);
41
+ process.on("SIGQUIT", onAbort);
42
+
43
+ watch(
44
+ {
45
+ synthCommand,
46
+ outDir: targetDir,
47
+ onUpdate: () => {}, // eslint-disable-line @typescript-eslint/no-empty-function
48
+ onLog: ({ stackName, message, messageWithConstructPath }) => {
49
+ setLogEntries((prev) => [
50
+ ...prev,
51
+ {
52
+ id: `${stackName}-${logEntryId}`,
53
+ stackName: stackName,
54
+ content: messageWithConstructPath
55
+ ? messageWithConstructPath
56
+ : message,
57
+ },
58
+ ]);
59
+ setLogEntryId((current) => current + 1);
60
+ },
61
+ },
62
+ {
63
+ autoApprove,
64
+ stackNames: targetStacks,
65
+ parallelism,
66
+ terraformParallelism,
67
+ },
68
+ ac.signal as any,
69
+ (state) => {
70
+ setCurrentState(state);
71
+ },
72
+ );
73
+ }, []);
74
+
75
+ return (
76
+ <StreamView logs={logEntries}>
77
+ <WatchStatusBottomBar currentState={currentState} />
78
+ </StreamView>
79
+ );
80
+ };
package/index.js DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- console.log("cdktn-cli placeholder");