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

Using Async Prompts with case modifiers in actions fails #451

Open
alikleitcr7 opened this issue Oct 5, 2024 · 0 comments
Open

Using Async Prompts with case modifiers in actions fails #451

alikleitcr7 opened this issue Oct 5, 2024 · 0 comments

Comments

@alikleitcr7
Copy link

I have the following code:

/**
 * @param {import('plop').NodePlopAPI} plop - The plop API object
 */
export default function (plop) {
  // create your generators here
  plop.setGenerator("add-service", {
    description: "adds service",
    // prompts: [
    //   {
    //     type: "input",
    //     name: "name",
    //     message: "controller name",
    //   },
    // ],
    async prompts(inquirer) {
      const initPrompts = [
        {
          type: "input",
          name: "name",
          message: "controller name",
        },
      ];

      for (let i = 0; i < initPrompts.length; i++) {
        const element = initPrompts[i];

        await inquirer.prompt(element);
      }
    },
    actions: [
      {
        type: "add",
        path: "output/packages/http/src/services/{{pascalCase name}}Service.ts",
        templateFile:
          "plop-templates/add-service/packages/http/src/services/service.hbs",
      },
    ],
  });
}

Above will fail with the following error when we specify `{{pascalCase name}}:

Cannot read properties of undefined (reading 'replace')

But will pass if it was done with the commented out block instead of a dynamic async block:

    // prompts: [
    //   {
    //     type: "input",
    //     name: "name",
    //     message: "controller name",
    //   },
    // ],

Additionally, if we don't specify the case modifier, it will be undefined.

Version: 4.0.1

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

No branches or pull requests

1 participant