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

feat(plop): add option to use custom templates #59

Merged
merged 3 commits into from
Nov 28, 2019

Conversation

connor-baer
Copy link
Member

@connor-baer connor-baer commented Oct 28, 2019

Purpose

I've worked on several projects where the default templates didn't match the custom project setup.

Approach & changes

  • add a custom opts parameter to the Plop config file
  • add the templateDir and templateExtension options
  • add documentation

Plop will first check for a custom template and fall back to the default template. This makes it easy to override just one or some of the templates.

Copy link
Collaborator

@felixjung felixjung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this. Since this doesn't change the kinds of templates supported, I'm assuming this is for cases where you, for example, would like to have ts or flow templates?

Are the existing templates up-to-date? 😀

Copy link

@afonsodelgado afonsodelgado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice feature! Thank you for adding this! :)

@connor-baer
Copy link
Member Author

connor-baer commented Oct 29, 2019

@felixjung You're right, it doesn't change the supported templates or prompt. I think this would be much harder to customize because Foundry's plop config contains a lot of custom code. You'd probably be better off adding a custom generator:

const configFn = require('@sumup/foundry/plop').react;

module.exports = plop => {
  plop.setGenerator('Vue', {
    description: 'Generate a new Vue component',
    prompts: [], // array of inquirer prompts
    actions: []  // array of actions
  });
  return configFn(plop);
};

I'll add some documentation about this in a follow-up PR.

Regarding the support for TypeScript, this is also not possible with this PR since the file extensions are still hard-coded. We could add another option to set the language/compiler. WDYT?

const configFn = require('@sumup/foundry/plop').react;

const opts = {
  language: 'TypeScript' | 'JavaScript'
}

module.exports = plop => configFn(plop, opts);

My motivation for this change was, in fact, to use custom Flow templates on the partner portal. Flow works with the .js extension.

Edit: I've added an option to customize the template extension.

@connor-baer connor-baer changed the base branch from canary to master November 28, 2019 19:41
@connor-baer connor-baer merged commit 5ba08fa into master Nov 28, 2019
@connor-baer connor-baer deleted the feature/plop-template-dir branch November 28, 2019 19:45
@connor-baer
Copy link
Member Author

🎉 This PR is included in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants