@@ -1,10 +1,10 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': minor
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Add partial templating to `fetch:template` action.
|
||||
|
||||
If an `extension` input is given, only files with that extension get their content processed. If `extension` is `true`, the `.njk` extension is used. The `extension` input is incompatible with both `cookiecutterCompat` and `copyWithoutRender`.
|
||||
If an `templateFileExtension` input is given, only files with that extension get their content processed. If `templateFileExtension` is `true`, the `.njk` extension is used. The `templateFileExtension` input is incompatible with both `cookiecutterCompat` and `copyWithoutRender`.
|
||||
|
||||
All other files get copied.
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('fetch:template', () => {
|
||||
action.handler(
|
||||
mockContext({
|
||||
copyWithoutRender: ['abc'],
|
||||
extension: true,
|
||||
templateFileExtension: true,
|
||||
}),
|
||||
),
|
||||
).rejects.toThrowError(
|
||||
@@ -123,7 +123,7 @@ describe('fetch:template', () => {
|
||||
action.handler(
|
||||
mockContext({
|
||||
cookiecutterCompat: true,
|
||||
extension: true,
|
||||
templateFileExtension: true,
|
||||
}),
|
||||
),
|
||||
).rejects.toThrowError(
|
||||
@@ -329,7 +329,7 @@ describe('fetch:template', () => {
|
||||
count: 1234,
|
||||
itemList: ['first', 'second', 'third'],
|
||||
},
|
||||
extension: true,
|
||||
templateFileExtension: true,
|
||||
});
|
||||
|
||||
mockFetchContents.mockImplementation(({ outputPath }) => {
|
||||
@@ -406,7 +406,7 @@ describe('fetch:template', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
context = mockContext({
|
||||
extension: '.jinja2',
|
||||
templateFileExtension: '.jinja2',
|
||||
values: {
|
||||
name: 'test-project',
|
||||
count: 1234,
|
||||
|
||||
@@ -44,7 +44,7 @@ type CookieCompatInput = {
|
||||
};
|
||||
|
||||
type ExtensionInput = {
|
||||
extension?: string | boolean;
|
||||
templateFileExtension?: string | boolean;
|
||||
};
|
||||
|
||||
export type FetchTemplateInput = {
|
||||
@@ -101,9 +101,10 @@ export function createFetchTemplateAction(options: {
|
||||
'Enable features to maximise compatibility with templates built for fetch:cookiecutter',
|
||||
type: 'boolean',
|
||||
},
|
||||
extension: {
|
||||
title: 'Extension to Process (.njk)',
|
||||
description: 'Extension to use for templated files.',
|
||||
templateFileExtension: {
|
||||
title: 'Template File Extension',
|
||||
description:
|
||||
'If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.',
|
||||
type: ['string', 'boolean'],
|
||||
},
|
||||
},
|
||||
@@ -128,7 +129,7 @@ export function createFetchTemplateAction(options: {
|
||||
}
|
||||
|
||||
if (
|
||||
ctx.input.extension &&
|
||||
ctx.input.templateFileExtension &&
|
||||
(ctx.input.copyWithoutRender || ctx.input.cookiecutterCompat)
|
||||
) {
|
||||
throw new InputError(
|
||||
@@ -137,8 +138,11 @@ export function createFetchTemplateAction(options: {
|
||||
}
|
||||
|
||||
let extension: string | false = false;
|
||||
if (ctx.input.extension) {
|
||||
extension = ctx.input.extension === true ? '.njk' : ctx.input.extension;
|
||||
if (ctx.input.templateFileExtension) {
|
||||
extension =
|
||||
ctx.input.templateFileExtension === true
|
||||
? '.njk'
|
||||
: ctx.input.templateFileExtension;
|
||||
if (!extension.startsWith('.')) {
|
||||
extension = `.${extension}`;
|
||||
}
|
||||
@@ -220,8 +224,8 @@ export function createFetchTemplateAction(options: {
|
||||
);
|
||||
|
||||
for (const location of allEntriesInTemplate) {
|
||||
let renderFilename = !nonTemplatedEntries.has(location);
|
||||
let renderContents = renderFilename;
|
||||
let renderFilename: boolean;
|
||||
let renderContents: boolean;
|
||||
|
||||
let localOutputPath = location;
|
||||
if (extension) {
|
||||
@@ -230,6 +234,8 @@ export function createFetchTemplateAction(options: {
|
||||
if (renderContents) {
|
||||
localOutputPath = localOutputPath.slice(0, -extension.length);
|
||||
}
|
||||
} else {
|
||||
renderFilename = renderContents = !nonTemplatedEntries.has(location);
|
||||
}
|
||||
if (renderFilename) {
|
||||
localOutputPath = templater.renderString(localOutputPath, context);
|
||||
|
||||
Reference in New Issue
Block a user