Merge pull request #20983 from electrofelix/scaffolder-backend-templating-globby

Allow globby negative matches for copyWithoutTemplating
This commit is contained in:
Ben Lambert
2023-11-08 14:45:19 -06:00
committed by GitHub
3 changed files with 63 additions and 13 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': minor
---
Allow using `globby`'s negative matching with `copyWithoutTemplating`/`copyWithoutRender`. This allows including an entire subdirectory while excluding a single file so that it will still be templated instead of needing to list every other file and ensure the list is updated when new files are added.
@@ -470,6 +470,57 @@ describe('fetch:template', () => {
),
).resolves.toEqual('1234');
});
describe('with exclusion filter', () => {
beforeEach(async () => {
context = mockContext({
values: {
name: 'test-project',
count: 1234,
},
copyWithoutTemplating: [
'.unprocessed',
'!*/templated-process-content-${{ values.name }}.txt',
],
});
mockFetchContents.mockImplementation(({ outputPath }) => {
mockDir.setContent({
[outputPath]: {
processed: {
'templated-content-${{ values.name }}.txt':
'${{ values.count }}',
},
'.unprocessed': {
'templated-content-${{ values.name }}.txt':
'${{ values.count }}',
'templated-process-content-${{ values.name }}.txt':
'${{ values.count }}',
},
},
});
return Promise.resolve();
});
await action.handler(context);
});
it('renders path template including excluded matches in copyWithoutTemplating', async () => {
await expect(
fs.readFile(
`${workspacePath}/target/.unprocessed/templated-process-content-test-project.txt`,
'utf-8',
),
).resolves.toEqual('1234');
await expect(
fs.readFile(
`${workspacePath}/target/.unprocessed/templated-content-test-project.txt`,
'utf-8',
),
).resolves.toEqual('${{ values.count }}');
});
});
});
describe('cookiecutter compatibility mode', () => {
@@ -207,19 +207,13 @@ export function createFetchTemplateAction(options: {
});
const nonTemplatedEntries = new Set(
(
await Promise.all(
(copyOnlyPatterns || []).map(pattern =>
globby(pattern, {
cwd: templateDir,
dot: true,
onlyFiles: false,
markDirectories: true,
followSymbolicLinks: false,
}),
),
)
).flat(),
await globby(copyOnlyPatterns || [], {
cwd: templateDir,
dot: true,
onlyFiles: false,
markDirectories: true,
followSymbolicLinks: false,
}),
);
// Cookiecutter prefixes all parameters in templates with