Plop.js Template files adding a root directory in the destination folder

1.1k views Asked by At

I'm running into an issue unsure if it's me. I'm using Plop.js within a project to quickly code generate boilerplate (bp) for new packages.

I've got 4 different template folders that plop maps from when a user enters the generate command. User is prompted with a list of package types to create:

choices: ['react', 'node', 'browser', 'isomorphic'],

Based on the users response to the prompts, plop chooses the folder to pull the template files from.

Template folder structure looks like this:

plop-template/
- react/
- node/
- browser/
- isomorphic/

The templateFiles: property is correctly identifying and creating the bp based on the user response.

templateFiles: 'plop_templates/{{project-type}}/**/*/',

the issue i'm running into is the project-type is being added to the file destination path

So what i would like to occur is the

/project-name/ ... boiler plate created

But what is happening is:

/project-name/project-type/ ... boiler plate created

So, is it possible to remove the /project-type/ from the destination path?

Plopfile.js (v. "plop": "3.1.1"):

const findEtensionFile = require("../lib/file-extention-locator");

module.exports = function (plop) {
  plop.getDestBasePath;
  plop.setGenerator("component", {
    prompts: [
      {
        type: "input",
        name: "project-name",
        message: "What's the name your project? ",
      },
      {
        type: "list",
        name: "project-type",
        message: "Project Type:",
        choices: ["react", "node", "browser", "isomorphic"],
      },
    ],
    actions: function (data) {
      var actions = [];

      actions.push({
        type: "addMany",
        globOptions: { dot: true },
        destination: "../../../{{project-name}}",
        base: "/",
        templateFiles: "plop_templates/{{project-type}}/**/*/",
      });

      return actions;
    },
  });
};

What I've tried: filter: property ... This can be used to modify the file contents, seems like that only affects the base: property (string).. documentation seems to indicate this is the route where I can filter out but can't find a value that doesn't break BP creation.

Any help would be greatly appreciated.

1

There are 1 answers

0
Sean McIntyre On

Discovered the error was mine. Seems like the base: value must match the entire value for templateFiles. In this case:

base: 'plop_templates/{{project-type}}',
templateFiles: "plop_templates/{{project-type}}/**/*/",

Even though the /plop_templates/ folder wasn't being created in the path.