A modular Plop.js code generator for creating React components, hooks, contexts, Redux slices, and more with TypeScript support.
Step 1: Link this package globally
# In this directory (/Users/cybercat/work/react/plop-react-generator)
pnpm link --globalStep 2: Link in your React project
# In your React project (e.g., react-test)
cd /Users/cybercat/work/react/react-test
pnpm link --global @cybercat/plop-generatorsStep 3: Use the generator
# Method A: Using cybercat-plop binary
cybercat-plop component MyButton
# Method B: Using npx plop (if plop is installed in your project)
npx plop component MyButton
# Method C: Add to package.json scripts
{
"scripts": {
"generate": "cybercat-plop",
"g": "cybercat-plop"
}
}
# Then: pnpm g component MyButton# In your React project
cd /Users/cybercat/work/react/react-test
pnpm add -D file:../plop-react-generator
# Use it
npx plop component MyButton# From your React project
npx plop --plopfile ../plop-react-generator/plopfile.cjs component MyButton
# Or add to package.json:
{
"scripts": {
"plop": "plop --plopfile ../plop-react-generator/plopfile.cjs",
"g": "plop --plopfile ../plop-react-generator/plopfile.cjs"
}
}component- React component with TypeScript, CSS modules, testslayout- Layout componentpage/page2- Page componentscontext- Context (Basic or Advanced mode)hook- Custom React hook
redux-basic- Basic Redux sliceredux-async- Async Redux slice with thunksredux-entity- Redux entity sliceredux-api- Redux API slicereducer-basic- Basic reducerlazy-redux-*- Lazy-loaded Redux variants
react-query-basic- Basic query hookreact-query-mutation- Mutation hookreact-query-infinite- Infinite query hookreact-query-service- API service with hooks
service- API servicemodel- Data modelconstants- Constants fileutil- Utility functionserror- Error classesstory- Storybook story
cybercat-plop
# or
npx plopcybercat-plop component ButtonPrompts:
- Component name?
Button - Base HTML element?
button - Make component flexible (allow 'as' prop)?
Yes - Directory?
src/components(or use fzf)
Generates:
src/components/Button/
βββ Button.tsx
βββ Button.types.ts
βββ Button.test.tsx
βββ Button.module.css
βββ index.ts
Auto-updates src/components/index.ts with barrel exports!
cybercat-plop hook useCountercybercat-plop context AuthChoose: Basic (flat) or Advanced (folder structure with provider/hook)
cybercat-plop redux-async userscybercat-plop react-query-basic useTodos- β TypeScript Support - Full type safety
- β CSS Modules - Scoped styles
- β
Polymorphic Components - Flexible
asprop - β Auto Barrel Exports - Updates index.ts automatically
- β Test Files - Co-located test scaffolding
- β Redux Toolkit - Modern Redux patterns
- β React Query - Query/mutation hooks
- β Interactive Picker - fzf directory selection
- β Handlebars Helpers - Powerful template logic
plop-react-generator/
βββ plopfile.cjs # Main entry (~10 lines!)
βββ plop-config/ # Modular configuration
β βββ generators/ # All generator configs
β β βββ component.js.cjs
β β βββ context.js.cjs
β β βββ hooks.js.cjs
β β βββ reactQuery.js.cjs
β β βββ reducers.js.cjs
β β βββ ...
β βββ helpers/ # Handlebars helpers
β β βββ handlebars-helpers.js.cjs
β β βββ plop-helpers.js.cjs
β βββ utils/ # Shared utilities
βββ plop-templates/ # Handlebars templates
βββ Component/
βββ Context/
βββ ReactQuery/
βββ Redux*/
βββ ...
See plop-config/README.md for architecture details.
- Edit templates or generators
- Changes reflect immediately in all linked projects! β¨
- No reinstall needed
# In your React project after making changes
pnpm install# At workspace root
pnpm install- Create generator file:
// plop-config/generators/my-generator.js.cjs
module.exports = {
description: "Create something awesome",
prompts: [
{
type: "input",
name: "name",
message: "What's the name?",
}
],
actions: [
{
type: "add",
path: "{{dir}}/{{pascalCase name}}.tsx",
templateFile: "plop-templates/MyTemplate.tsx.hbs",
}
]
};- Register in
plop-config/generators/index.js.cjs:
const myGenerator = require('./my-generator.js.cjs');
function register(plop) {
// ... existing generators
plop.setGenerator("my-generator", myGenerator);
}Create .hbs file in plop-templates/:
- Case transforms:
{{pascalCase}},{{camelCase}},{{kebabCase}} - Conditionals:
{{eq a b}},{{ne a b}},{{or a b}},{{and a b}} - Utilities:
{{includes str substr}},{{ternary cond a b}},{{default val fallback}} - Arrays:
{{reverse arr}}
# Test in any React project
cd /path/to/react-project
cybercat-plop component TestComponent
# Verify generated files
ls -la src/components/TestComponent/This is normal! The cybercat-plop binary is available after linking.
# Unlink and relink
pnpm unlink --global
pnpm link --global
# Check if linked
pnpm list --global --depth 0 | grep plopTry using npx plop instead of cybercat-plop, or add script to package.json.
cybercat-plop help # Show help
cybercat-plop # Interactive mode with all generatorsPrivate - For personal use by @cybercat
Made with β€οΈ for rapid React development