Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
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.
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' });
Yeoman Generator is a scaffolding tool that allows you to create and manage code generators. It provides a more extensive ecosystem and a larger community compared to node-plop. Yeoman generators are more feature-rich and offer more built-in functionalities, but they can be more complex to set up and use.
Hygen is a fast and lightweight code generator that focuses on simplicity and ease of use. It uses plain JavaScript and EJS templates, making it easy to get started. Compared to node-plop, Hygen is more straightforward but may lack some of the advanced customization options available in node-plop.
Slush is a scaffolding tool that uses Gulp for task automation. It allows you to create and manage code generators with a focus on flexibility and customization. Slush provides a different approach compared to node-plop, leveraging the power of Gulp to handle complex tasks and workflows.
This is an early publication of the plop core logic being removed from the CLI tool. Main purpose for this is to make it easier for others to automate code generation through processes and tools OTHER than the command line. This also makes it easier to test the code functionality of PLOP without needing to test via the CLI interface.
This is the backend code that drives the plop CLI tool using node-plop.
import nodePlop from 'node-plop';
// load an instance of plop from a plopfile
const plop = await nodePlop(`./path/to/plopfile.js`);
// get a generator by name
const basicAdd = plop.getGenerator('basic-add');
// run all the generator actions using the data specified
basicAdd.runActions({name: 'this is a test'}).then(function (results) {
// do something after the actions have run
});
FAQs
programmatic plopping for fun and profit
We found that node-plop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.