Skip to content

Commit

Permalink
fix: don't cross package boundaries for templates
Browse files Browse the repository at this point in the history
and copy the templates into the expected place in the bundle
  • Loading branch information
DanielMSchmidt committed Jul 24, 2023
1 parent 49f3699 commit 47ba4d8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/@cdktf/cli-core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export { TerraformCli } from "./models/terraform-cli";
export { CdktfConfig } from "./cdktf-config";
export { initializErrorReporting } from "./error-reporting";
export { CdktfStack } from "./cdktf-stack";
export { init, Project, InitArgs } from "./init";
export { init, Project, InitArgs, templates, templatesDir } from "./init";
export { get, GetStatus, runGetInDir } from "./get";
export { SynthesizedStack } from "./synth-stack";
export { CdktfProject, ProjectUpdate } from "./cdktf-project";
Expand Down
10 changes: 10 additions & 0 deletions packages/@cdktf/cli-core/src/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export type InitArgs = {
silent?: boolean;
};

export const templatesDir = path.join(__dirname, "..", "..", "templates");

const availableTemplates = fs
.readdirSync(templatesDir)
.filter((x) => !x.startsWith("."));
export const templates: string[] = [];
for (const template of availableTemplates) {
templates.push(template);
}

export async function init({
cdktfVersion,
destination,
Expand Down
1 change: 1 addition & 0 deletions packages/cdktf-cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ const nativeNodeModulesPlugin = {
}

fs.copySync("src/bin/cdktf", "./bundle/bin/cdktf");
fs.copySync("../@cdktf/cli-core/templates", "./bundle/templates");
})();
21 changes: 0 additions & 21 deletions packages/cdktf-cli/src/bin/cmds/helper/init-templates.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cdktf-cli/src/bin/cmds/helper/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
Errors,
sendTelemetry,
} from "@cdktf/commons";
import { templates, templatesDir } from "./init-templates";
import { templates, templatesDir } from "@cdktf/cli-core";
import ciDetect from "@npmcli/ci-detect";
import { isInteractiveTerminal } from "./check-environment";
import { getTerraformVersion } from "./terraform-check";
Expand Down
5 changes: 1 addition & 4 deletions packages/cdktf-cli/src/bin/cmds/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: MPL-2.0
import yargs from "yargs";

import { templates } from "./helper/init-templates";
import { readPackageJson, requireHandlers } from "./helper/utilities";
import { Errors } from "@cdktf/commons";
import { BaseCommand } from "./helper/base-command";
Expand All @@ -17,9 +16,7 @@ class Command extends BaseCommand {
.showHelpOnFail(true)
.option("template", {
type: "string",
desc: `The template to be used to create a new project. Either URL to zip file or one of the built-in templates: [${templates
.map((t) => `"${t}"`)
.join(", ")}]`,
desc: `The template to be used to create a new project. Either URL to zip file or one of the built-in templates.`,
})
.option("project-name", {
type: "string",
Expand Down

0 comments on commit 47ba4d8

Please sign in to comment.