Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-plop

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-plop

programmatic plopping for fun and profit

  • 0.32.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
increased by4.61%
Maintainers
2
Weekly downloads
 
Created

What is node-plop?

node-plop is a tool that allows you to create and manage code generators using a pluggable and customizable approach. It is built on top of plop, which is a micro-generator framework that helps you create consistent and repeatable code structures.

What are node-plop's main functionalities?

Creating Generators

This feature allows you to create a generator with prompts and actions. The example shows a basic generator that prompts the user for a name and then creates a file using a Handlebars template.

const nodePlop = require('node-plop');
const plop = nodePlop();

plop.setGenerator('basic-generator', {
  description: 'this is a basic generator',
  prompts: [
    {
      type: 'input',
      name: 'name',
      message: 'What is your name?'
    }
  ],
  actions: [
    {
      type: 'add',
      path: 'src/{{name}}.js',
      templateFile: 'plop-templates/basic.hbs'
    }
  ]
});

plop.getGenerator('basic-generator').runActions({ name: 'example' });

Custom Actions

This feature allows you to define custom actions that can be executed as part of the generator. The example shows how to create a custom action type and use it in a generator.

const nodePlop = require('node-plop');
const plop = nodePlop();

plop.setActionType('customAction', (answers, config, plop) => {
  return 'Custom action executed';
});

plop.setGenerator('custom-generator', {
  description: 'this is a custom generator',
  prompts: [
    {
      type: 'input',
      name: 'name',
      message: 'What is your name?'
    }
  ],
  actions: [
    {
      type: 'customAction'
    }
  ]
});

plop.getGenerator('custom-generator').runActions({ name: 'example' });

Using Handlebars Helpers

This feature allows you to add custom Handlebars helpers to your generators. The example shows how to add an 'upperCase' helper and use it in a generator to create a file with an uppercase name.

const nodePlop = require('node-plop');
const plop = nodePlop();

plop.addHelper('upperCase', (text) => text.toUpperCase());

plop.setGenerator('helper-generator', {
  description: 'this is a helper generator',
  prompts: [
    {
      type: 'input',
      name: 'name',
      message: 'What is your name?'
    }
  ],
  actions: [
    {
      type: 'add',
      path: 'src/{{upperCase name}}.js',
      templateFile: 'plop-templates/helper.hbs'
    }
  ]
});

plop.getGenerator('helper-generator').runActions({ name: 'example' });

Other packages similar to node-plop

Keywords

FAQs

Package last updated on 05 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc