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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include helpers in comments [feature request] #317

Open
lipsumar opened this issue Mar 21, 2022 · 4 comments
Open

Include helpers in comments [feature request] #317

lipsumar opened this issue Mar 21, 2022 · 4 comments

Comments

@lipsumar
Copy link

First off: amazing lib, incredibly useful 馃憦 馃挴

The only thing we're currently missing is to be able to use helpers in comments.

We're using Plop to make "create" packages. After the generator is done, we want to instruct users what to do next. It typically includes:

  • cd into "that directory the generator just created"
  • yarn install
  • etc...

Currently including a comment with a helper (such as "cd into {{dashCase name}}") will not execute the helper. Can plop also transform comment strings with helpers ?

@amwmedia
Copy link
Member

I'm not sure why this would be giving you problems. Plop treats all content in the template files the same, it has no concept of comments vs code. Can you provide an example of a template that doesn't render properly when run through plop?

@lipsumar
Copy link
Author

I was probably unclear: what i meant by "comment" is this: https://plopjs.com/documentation/#comments

What we typically do is:

plop.setGenerator('service', {
  actions: [
    {
      base: 'templates/typescript',
      destination: './{{dashCase name}}',
      templateFiles: 'templates/typescript/**/*',
      type: 'addMany',
    },
    'To start your server:',
    '  - cd {{dashCase name}}',
    '  - yarn install',
    '  - yarn start',
    '',
  ],
  prompts: [
    {
      message: 'Package name (will create a new directory)',
      name: 'name',
      type: 'input',
    },
  ],
});

This issue is the string ' - cd {{dashCase name}}', {{dashCase name}} is not replaced.

@amwmedia
Copy link
Member

amwmedia commented Mar 22, 2022

ah, I see... Yes, it would be possible to process this data through handlebars before it's printed to the terminal output. In the meantime, you could try using a Custom Action Function that simply returns the string you'd like to show.

const instructions = (answers) => plop.renderString(`\
To start your server:
  - cd {{dashCase name}}
  - yarn install
  - yarn start
`, answers);

plop.setGenerator('service', {
  actions: [
    {
      base: 'templates/typescript',
      destination: './{{dashCase name}}',
      templateFiles: 'templates/typescript/**/*',
      type: 'addMany',
    },
    instructions
  ],
  prompts: [
    {
      message: 'Package name (will create a new directory)',
      name: 'name',
      type: 'input',
    },
  ],
});

@crutchcorn
Copy link
Member

After looking through our PRs, I think this PR actually implements this:

#183

@lipsumar is there any chance that you could test this change and let us know if this solves your problem?

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

No branches or pull requests

3 participants