🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

plop

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

plop

Micro-generator framework that makes it easy for an entire team to create files with a level of uniformity

4.0.1
latest
Version published
Weekly downloads
853K
-19.31%
Maintainers
2
Weekly downloads
 
Created

What is plop?

Plop is a micro-generator framework that helps you create consistent and repeatable code snippets, files, or projects. It allows you to define templates and automate the creation of boilerplate code, making it easier to maintain consistency across your codebase.

What are plop's main functionalities?

File Generation

This feature allows you to generate files based on templates. In this example, a new component file is created using a Handlebars template. The user is prompted for the component name, and the file is generated in the specified path.

module.exports = function (plop) {
  plop.setGenerator('component', {
    description: 'Create a new component',
    prompts: [
      {
        type: 'input',
        name: 'name',
        message: 'Component name?'
      }
    ],
    actions: [
      {
        type: 'add',
        path: 'src/components/{{pascalCase name}}/{{pascalCase name}}.js',
        templateFile: 'plop-templates/component.hbs'
      }
    ]
  });
};

Custom Actions

Plop allows you to define custom actions that can be executed as part of the generation process. In this example, a custom action type is defined and used in a generator.

module.exports = function (plop) {
  plop.setActionType('customAction', function (answers, config, plop) {
    // Custom action logic here
    return 'Custom action executed';
  });
  plop.setGenerator('custom', {
    description: 'Run a custom action',
    prompts: [],
    actions: [
      {
        type: 'customAction'
      }
    ]
  });
};

Template Rendering

This feature allows you to render templates with dynamic data. In this example, a README file is generated using a Handlebars template, with the project name provided by the user.

module.exports = function (plop) {
  plop.setGenerator('readme', {
    description: 'Create a README file',
    prompts: [
      {
        type: 'input',
        name: 'projectName',
        message: 'Project name?'
      }
    ],
    actions: [
      {
        type: 'add',
        path: 'README.md',
        templateFile: 'plop-templates/readme.hbs'
      }
    ]
  });
};

Other packages similar to plop

FAQs

Package last updated on 22 Dec 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