aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-codemod/plopfile.js
blob: 9cc2dd71beb6119d2d6b0e2b1c7afe6956f04d37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require("fs-extra");

module.exports = function plopConfig(plop) {
  // controller generator
  plop.setGenerator("controller", {
    description: "Add a new transformer",
    prompts: [
      {
        type: "input",
        name: "name",
        message: 'key for the transform (example: "create-turbo-config")',
      },
      {
        type: "input",
        name: "description",
        message:
          'description for the transform (example: "Create the `turbo.json` file from an existing "turbo" key in `package.json`")',
      },
      {
        type: "input",
        name: "introducedIn",
        message:
          'the semantic version of turbo where this change was introduced (example: "1.1.0")',
      },
    ],
    actions: [
      {
        type: "add",
        path: "src/transforms/{{name}}.ts",
        templateFile: "templates/transformer.hbs",
      },
      {
        type: "add",
        path: "__tests__/{{name}}.test.ts",
        templateFile: "templates/transformer.test.hbs",
      },
      function createFixturesDirectory(answers) {
        process.chdir(plop.getPlopfilePath());
        const directory = `__tests__/__fixtures__/${answers.name}`;
        fs.mkdirSync(`__tests__/__fixtures__/${answers.name}`);

        return `created empty ${directory} directory for fixtures`;
      },
    ],
  });
};