Skip to content

Commit

Permalink
Renders path templates when copyWithoutRender is used
Browse files Browse the repository at this point in the history
When putting templated paths in `copyWithoutRender` filter, like
`{{project}}/something`, the path template won't get rendered and the
files are copied to the exact `{{project}}/something` instead of
`someproject/something`.

Cookiecutter has fixed this issue, and the behaviour in scaffolder
should be consistent with Cookiecutter.

Signed-off-by: Mengnan Gong <namco1992@gmail.com>
  • Loading branch information
namco1992 committed Jul 7, 2022
1 parent fa2dbe8 commit 3c3c307
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-falcons-destroy.md
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---

Render the path templates for files that match `copyWithoutRender`, only the file content should be left untouched.
Expand Up @@ -300,10 +300,10 @@ describe('fetch:template', () => {
await action.handler(context);
});

it('ignores template syntax in files matched in copyWithoutRender', async () => {
it('renders path template and ignores content template in files matched in copyWithoutRender', async () => {
await expect(
fs.readFile(
`${workspacePath}/target/.unprocessed/templated-content-\${{ values.name }}.txt`,
`${workspacePath}/target/.unprocessed/templated-content-test-project.txt`,
'utf-8',
),
).resolves.toEqual('${{ values.count }}');
Expand Down
Expand Up @@ -193,22 +193,18 @@ export function createFetchTemplateAction(options: {
});

for (const location of allEntriesInTemplate) {
let renderFilename: boolean;
let renderContents: boolean;

let localOutputPath = location;
if (extension) {
renderFilename = true;
renderContents = extname(localOutputPath) === extension;
if (renderContents) {
localOutputPath = localOutputPath.slice(0, -extension.length);
}
} else {
renderFilename = renderContents = !nonTemplatedEntries.has(location);
}
if (renderFilename) {
localOutputPath = renderTemplate(localOutputPath, context);
renderContents = !nonTemplatedEntries.has(location);
}
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
Expand Down

0 comments on commit 3c3c307

Please sign in to comment.