Merge pull request #8028 from timja/skip-empty-file-name-scaffolder
Skip empty file names during scaffolder
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Skip empty file names when scaffolding with nunjucks
|
||||
@@ -144,6 +144,7 @@ describe('fetch:template', () => {
|
||||
name: 'test-project',
|
||||
count: 1234,
|
||||
itemList: ['first', 'second', 'third'],
|
||||
showDummyFile: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -163,6 +164,10 @@ describe('fetch:template', () => {
|
||||
},
|
||||
'.${{ values.name }}': '${{ values.itemList | dump }}',
|
||||
'a-binary-file.png': aBinaryFile,
|
||||
'{% if values.showDummyFile %}dummy-file.txt{% else %}{% endif %}':
|
||||
'dummy file',
|
||||
'${{ "dummy-file2.txt" if values.showDummyFile else "" }}':
|
||||
'some dummy file',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -181,6 +186,18 @@ describe('fetch:template', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('skips empty filename', async () => {
|
||||
await expect(
|
||||
fs.pathExists(`${workspacePath}/target/dummy-file.txt`),
|
||||
).resolves.toEqual(false);
|
||||
});
|
||||
|
||||
it('skips empty filename syntax #2', async () => {
|
||||
await expect(
|
||||
fs.pathExists(`${workspacePath}/target/dummy-file2.txt`),
|
||||
).resolves.toEqual(false);
|
||||
});
|
||||
|
||||
it('copies files with no templating in names or content successfully', async () => {
|
||||
await expect(
|
||||
fs.readFile(`${workspacePath}/target/static.txt`, 'utf-8'),
|
||||
|
||||
@@ -241,6 +241,11 @@ export function createFetchTemplateAction(options: {
|
||||
localOutputPath = templater.renderString(localOutputPath, context);
|
||||
}
|
||||
const outputPath = resolvePath(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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!renderContents && !extension) {
|
||||
ctx.logger.info(
|
||||
|
||||
Reference in New Issue
Block a user