Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Plugin: Fix incorrect templates being used for scaffolding #158

Merged
merged 5 commits into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions packages/create-plugin/src/commands/generate.plopfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function (plop: NodePlopAPI) {
templateData: { pluginId },
});

// Copy over files from the plugin type specific folder, e.g. "tempaltes/app" for "app" plugins ("app" | "panel" | "datasource").
// Copy over files from the plugin type specific folder, e.g. "templates/app" for "app" plugins ("app" | "panel" | "datasource").
const pluginTypeSpecificActions = getActionsForTemplateFolder({
folderPath: TEMPLATE_PATHS[pluginType],
exportPath,
Expand All @@ -113,6 +113,20 @@ export default function (plop: NodePlopAPI) {
? getActionsForTemplateFolder({ folderPath: backendFolderPath, exportPath })
: [];

// Common, pluginType and backend actions can contain different templates for the same destination.
// This filtering removes the duplicate file additions to prevent plop erroring and makes sure the
// correct template is scaffolded.
// Note that the order is reversed so backend > pluginType > common
const pluginActions = [...backendActions, ...pluginTypeSpecificActions, ...commonActions].reduce((acc, file) => {
const actionExists = acc.find((f) => f.path === file.path);
// return early to prevent multiple add type actions being added to the array
if (actionExists && actionExists.type === 'add' && file.type === 'add') {
return acc;
}
acc.push(file);
return acc;
}, []);

// Copy over Github workflow files (if selected)
const ciWorkflowActions = hasGithubWorkflows
? getActionsForTemplateFolder({ folderPath: TEMPLATE_PATHS.ciWorkflows, exportPath })
Expand All @@ -125,14 +139,7 @@ export default function (plop: NodePlopAPI) {
// Replace conditional bits in the Readme files
const readmeActions = getActionsForReadme({ exportPath });

return [
...commonActions,
...pluginTypeSpecificActions,
...backendActions,
...ciWorkflowActions,
...readmeActions,
...isCompatibleWorkflowActions,
];
return [...pluginActions, ...ciWorkflowActions, ...readmeActions, ...isCompatibleWorkflowActions];
},
});
}
Expand Down Expand Up @@ -196,7 +203,7 @@ function getActionsForTemplateFolder({
templateFile: f,
// The target path where the compiled template is saved to
path: path.join(exportPath, getExportPath(f), getExportFileName(f)),
// We would like to override generated files in development mode
// Support overriding files in development for overriding "generated" plugins.
force: IS_DEV,
// We would still like to scaffold as many files as possible even if one fails
abortOnFail: false,
Expand Down