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

Support multiple component generation in one go using whitespaces as a delimiter #379

Open
silicakes opened this issue May 29, 2023 · 0 comments

Comments

@silicakes
Copy link

silicakes commented May 29, 2023

In other generators, you can run something like:

$ whatever generate componentA componentB componentC

While trying to achieve this with plop, I got the following solution:

const page = {
  description: "⚛ react page",
  prompts: [
    {
      type: "input",
      name: "names",
      message: "page name",
    },
  ],
  actions: (data) => {
    const names = data.names.split(/\s+/).map((name) => name.trim());
    return names.flatMap((name) => {
      return [
        {
          type: "add",
          path: `../src/pages/{{pascalCase name}}/{{pascalCase name}}.tsx`,
          templateFile: "./templates/page.tsx.hbs",
          data: { name },
        },
        {
          type: "add",
          path: "../src/pages/{{pascalCase name}}/{{pascalCase name}}.test.tsx",
          templateFile: "./templates/test.tsx.hbs",
          data: { name },
        },
      ];
    });
  },
};

const generator = (plop) => {
  plop.setDefaultInclude({ generators: true });
  plop.setGenerator("page", page);
};

This allowed the feature to work using commas to delimit the different files, i.e:

$ plop page page1,page2,page3

✔  ++ src/pages/Page1/Page1.tsx
✔  ++ src/pages/Page1/Page1.test.tsx
✔  ++ src/pages/Page2/Page2.tsx
✔  ++ src/pages/Page2/Page2.test.tsx
✔  ++ src/pages/Page3/Page3.tsx
✔  ++ src/pages/Page3/Page3.test.ts

When trying to adjust the code to use whitespaces, plop currently returns the following error:

[PLOP] Too many bypass arguments passed

I'd love to hear your advice on this.

@silicakes silicakes changed the title Support multiple component generation in one go using whitespaces as a separator Support multiple component generation in one go using whitespaces as a delimiter May 29, 2023
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