Plop is a micro-generator framework designed to streamline the creation of consistent files and code patterns within a project. It acts as 'glue code' connecting Inquirer.js prompts for user input and Handlebars.js templates for content generation. The current stable version is 4.0.5, with patch and minor releases occurring periodically to address bugs, update dependencies, and introduce performance improvements. Major versions, like v4.0.0, introduce breaking changes such as updated Node.js requirements. Plop's core differentiator is its simplicity and focus on turning best practices for file creation into easily executable terminal commands, reducing manual boilerplate and ensuring uniformity across development teams.
npm install plopVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to programmatically use `nodePlop` from the `plop` package to define and execute a generator, simulating user input for component creation. It sets up a basic `plopfile` to generate a React component, including a TypeScript file and an optional CSS module, then cleans up the temporary files.
Upgrade your Node.js environment to version 18 or higher.
Ensure your `plopfile.js` uses the correct export syntax for your project's module type. If you're in an ESM project, use `export default function (plop) { ... }`. For CommonJS, use `module.exports = function (plop) { ... }`.For TypeScript `plopfile.ts`, install `ts-node` (`npm i -D ts-node`) or `tsx` and configure your `package.json` scripts, or use `npx plop --init-ts` to set up boilerplate.
Refer to the Handlebars.js documentation for correct syntax. Ensure that the data passed to your templates (from prompts) matches what the templates expect.
For convenient global access: `npm install -g plop`. For project-specific access: `npx plop` or add a script to `package.json` like `"generate": "plop"` and run `npm run generate`.
Ensure your `plopfile`'s module type matches its export statement. For CommonJS `plopfiles`, use `module.exports`. For ESM `plopfiles`, use `export default` and potentially specify a `.mjs` extension or set `"type": "module"` in your `package.json`.
Install plop globally (`npm install -g plop`) or run it using `npx plop` when installed locally within a project (`npm install --save-dev plop`). Alternatively, add a script to `package.json` like `"gen": "plop"` and execute with `npm run gen`.
Verify that your `plopfile` correctly exports a function that accepts `plop` as its first parameter: `export default function (plop) { /* ... */ }` (ESM) or `module.exports = function (plop) { /* ... */ }` (CommonJS).No dependency data recorded yet.