diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts index a1afabc39e..15e1a6fd75 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts @@ -206,16 +206,17 @@ export function createFetchTemplateAction(options: { } else { renderFilename = renderContents = !nonTemplatedEntries.has(location); } + if (renderFilename) { localOutputPath = renderTemplate(localOutputPath, context); } - const outputPath = resolveSafeChildPath(outputDir, localOutputPath); - // variables have been expanded to make an empty file name - // this is due to a conditional like if values.my_condition then file-name.txt else empty string so skip - if (outputDir === outputPath) { + + if (containsSkippedContent(localOutputPath)) { continue; } + const outputPath = resolveSafeChildPath(outputDir, localOutputPath); + if (!renderContents && !extension) { ctx.logger.info( `Copying file/directory ${location} without processing.`, @@ -257,3 +258,12 @@ export function createFetchTemplateAction(options: { }, }); } + +function containsSkippedContent(localOutputPath: string): boolean { + // if the path starts with / means that the root directory has been skipped + // if the path is empty means that there is a file skipped in the root + // if the path includes // means that there is a subdirectory skipped + return localOutputPath.startsWith('/') + || localOutputPath === '' + || localOutputPath.includes('//'); +}