From dc383083e522ebb905eda843a236c388d64ded33 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Sun, 20 Oct 2024 10:50:05 -0400 Subject: [PATCH] feat(cli): add support for local templates --- .../cdktf-cli/src/bin/cmds/helper/init.ts | 15 +++++--- packages/cdktf-cli/src/bin/cmds/init.ts | 2 +- .../typescript/init-local-template/cdktf.json | 8 +++++ test/typescript/init-local-template/test.ts | 35 +++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 test/typescript/init-local-template/cdktf.json create mode 100644 test/typescript/init-local-template/test.ts diff --git a/packages/cdktf-cli/src/bin/cmds/helper/init.ts b/packages/cdktf-cli/src/bin/cmds/helper/init.ts index ed250e203b..0a42caae00 100644 --- a/packages/cdktf-cli/src/bin/cmds/helper/init.ts +++ b/packages/cdktf-cli/src/bin/cmds/helper/init.ts @@ -519,15 +519,22 @@ async function getTemplate( } } - // treat as remote url - if (!templates.includes(templateName)) { - return fetchRemoteTemplate(templateName); - } else { + if (templates.includes(templateName)) { return { Name: templateName, Path: path.join(templatesDir, templateName), }; } + if ( + templateName.startsWith("http://") || + templateName.startsWith("https://") + ) { + return fetchRemoteTemplate(templateName); + } + return { + Name: path.basename(templateName), + Path: templateName, + }; } async function fetchRemoteTemplate(templateUrl: string): Promise