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

plop

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

plop - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

inquirer-prompts.md

7

example/package.json
{
"name": "plop-example",
"version": "1.3.0"
"name": "plop-example",
"version": "1.4.0",
"devDependencies": {
"plop": "^1.4.0"
}
}

@@ -19,2 +19,3 @@ module.exports = function (plop) {

// setGenerator creates a generator that can be run with "plop generatorName"

@@ -62,2 +63,7 @@ plop.setGenerator('test', {

function customAction(answers) {
// move the current working directory to the plop file path
// this allows this action to work even when the generator is
// executed from inside a subdirectory
process.chdir(plop.getPlopfilePath());
// custom function can be synchronous or async (by returning a promise)

@@ -100,5 +106,37 @@ var fs = require('fs'),

// adding a custom inquirer prompt type
plop.addPrompt('directory', require('inquirer-directory'));
plop.setGenerator('custom-prompt', {
description: 'custom inquirer prompt example',
prompts: [
{
type: 'input',
name: 'fileName',
message: 'Pick a file name:',
validate: function (value) {
if ((/.+/).test(value)) { return true; }
return 'file name is required';
}
}, {
type: 'directory',
name: 'path',
message: 'where would you like to put this component?',
basePath: plop.getPlopfilePath()
}
],
actions: [
{
type: 'add',
path: '{{path}}/{{fileName}}.txt',
template: '{{path}}/{{fileName}} plopped!'
}
]
});
// test with dynamic actions, regarding responses to prompts
plop.setGenerator('test with dynamic actions', {
description: 'this is another test',
plop.setGenerator('dynamic actions', {
description: 'another test using an actions function',
prompts: [

@@ -105,0 +143,0 @@ {

module.exports = (function () {
'use strict';
var inquirer = require('inquirer');
var q = require('q');

@@ -30,3 +29,3 @@ var path = require('path');

inquirer.prompt(prompts, function (result) {
plop.inquirer.prompt(prompts, function (result) {
_d.resolve(result);

@@ -33,0 +32,0 @@ });

@@ -0,5 +1,7 @@

module.exports = (function () {
'use strict';
var inquirer = require('inquirer');
var handlebars = require('handlebars');
var changeCase = require('change-case');
var handlebars = require('handlebars');

@@ -26,2 +28,5 @@ var plopfilePath = '';

function addPrompt(name, prompt) {
inquirer.registerPrompt(name, prompt);
}

@@ -72,2 +77,3 @@ function addHelper(name, fn) { helpers[name] = fn; }

addPartial: addPartial,
addPrompt: addPrompt,
renderString: renderString,

@@ -80,4 +86,7 @@

setPlopfilePath: setPlopfilePath,
getPlopfilePath: getPlopfilePath
getPlopfilePath: getPlopfilePath,
inquirer: inquirer,
handlebars: handlebars
};
})();
{
"name": "plop",
"version": "1.3.0",
"description": "Micro-generator script for doing project specific scaffolding of code structures",
"main": "plop.js",
"repository": {
"type": "git",
"url": "https://github.com/amwmedia/plop.git"
},
"keywords": [
"generator",
"scaffolding",
"yeoman",
"make",
"build",
"generate",
"gen",
"plop"
],
"author": "Andrew Worcester <andrew@amwmedia.com> (http://amwmedia.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/amwmedia/plop/issues"
},
"homepage": "https://github.com/amwmedia/plop",
"dependencies": {
"change-case": "^2.1.5",
"colors": "^1.0.2",
"findup-sync": "^0.1.3",
"handlebars": "^2.0.0",
"mkdirp": "^0.5.0",
"inquirer": "^0.10.0",
"q": "~1.0.1"
},
"preferGlobal": "true",
"bin": {
"plop": "plop.js"
}
"name": "plop",
"version": "1.4.0",
"description": "Micro-generator script for doing project specific scaffolding of code structures",
"main": "plop.js",
"repository": {
"type": "git",
"url": "https://github.com/amwmedia/plop.git"
},
"keywords": [
"generator",
"scaffolding",
"yeoman",
"make",
"build",
"generate",
"gen",
"plop"
],
"author": "Andrew Worcester <andrew@amwmedia.com> (http://amwmedia.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/amwmedia/plop/issues"
},
"homepage": "https://github.com/amwmedia/plop",
"dependencies": {
"change-case": "^2.1.5",
"colors": "^1.0.2",
"handlebars": "^2.0.0",
"inquirer": "^0.10.0",
"interpret": "^1.0.0",
"liftoff": "^2.2.0",
"minimist": "^1.2.0",
"mkdirp": "^0.5.0",
"q": "~1.0.1",
"v8flags": "^2.0.10"
},
"devDependencies": {
"inquirer-directory": "^1.1.1"
},
"preferGlobal": "true",
"bin": {
"plop": "plop.js"
}
}

@@ -1,2 +0,2 @@

#!/usr/bin/env node --harmony
#!/usr/bin/env node

@@ -6,3 +6,7 @@ 'use strict';

var path = require('path');
var findup = require('findup-sync');
var Liftoff = require('liftoff');
var argv = require('minimist')(process.argv.slice(2));
var v8flags = require('v8flags');
var interpret = require('interpret');
var colors = require('colors');

@@ -12,9 +16,40 @@ var plop = require('./mod/plop-base');

var out = require('./mod/console-out');
var args = process.argv.slice(2);
var generator = args.length && args.shift() || '';
var globalPkg = require('./package.json');
var generator = argv._[0] || null;
function run(plopfilePath) {
var generators;
var Plop = new Liftoff({
name: 'plop',
extensions: interpret.jsVariants,
v8flags: v8flags
});
Plop.launch({
cwd: argv.cwd,
configPath: argv.plopfile,
require: argv.require,
completion: argv.completion,
verbose: argv.verbose
}, run);
function run(env) {
var generators, plopfilePath;
// handle request for version number
if (argv.version || argv.v) {
if (env.modulePackage.version !== globalPkg.version) {
console.log('CLI version'.yellow, globalPkg.version);
console.log('Local version'.yellow, env.modulePackage.version);
} else {
console.log(globalPkg.version);
}
return;
}
// set the default base path to the plopfile directory
plopfilePath = env.configPath;
// abort if there's no plopfile found
if (plopfilePath == null) {
console.error(colors.red('[PLOP] ') + 'No plopfile found');
process.exit(1);
}
plop.setPlopfilePath(path.dirname(plopfilePath));

@@ -31,3 +66,4 @@

} else {
throw Error('Generator ' + generator + ' not found in plopfile');
console.error(colors.red('[PLOP] ') + 'Generator "' + generator + '" not found in plopfile');
process.exit(1);
}

@@ -41,25 +77,12 @@ }

result.changes.forEach(function(line) {
console.log('SUCCESS'.green + ':', line.type, line.path);
console.log('[SUCCESS]'.green, line.type, line.path);
});
result.failures.forEach(function(line) {
console.log('FAILED'.red + ':', line.type, line.path, line.error);
console.log('[FAILED]'.red, line.type, line.path, line.error);
});
})
.fail(function (err) {
console.error('ERROR', err.message, err.stack);
console.error('[ERROR]'.red, err.message, err.stack);
process.exit(1);
});
}
// locate the plopfile
try {
var plopfilePath = findup('plopfile.js', {nocase: true});
if (plopfilePath) {
run(plopfilePath);
} else {
throw Error('No plopfile found.');
}
} catch (e) {
console.error(e.message);
process.exit(1);
}

@@ -10,10 +10,24 @@ Plop

## Install
# Getting Started
## 1. Install plop globally
```
npm install -g plop
$ npm install -g plop
```
## 2. Install plop in your project's devDependencies
```
$ npm install --save-dev plop
```
## 3. Create a plopfile.js at the root of your project
``` javascript
module.exports = function (plop) {
// create your generators here
plop.setGenerator('basics', {
description: 'this is a skeleton plopfile',
prompts: [],
actions: []
});
};
```
---
## Setup
# Anatomy of a Plop Generator
The main parts of a plop generator are the plop file (`plopfile.js`) and the templates. Templates can either be inline, or in separate files.

@@ -25,6 +39,4 @@

```
The `plop` object offers three main functions (`addHelper`, `addPartial`, `setGenerator`).
The `plop` object offers four main functions (`addHelper`, `addPartial`, `addPrompt`, `setGenerator`).
---
## plop.addHelper(name, helper)

@@ -57,6 +69,16 @@ - name {String}

## plop.addPrompt(name, inquirerPlugin)
- name {String}
- inquirerPlugin {Constructor}
`addPrompt` is a shortcut method to inquirer's `prompt.registerPrompt` function. If inquirer's built in prompt types don't quite cut the mustard for you, you can write your own or look at [this list of custom prompts](inquirer-prompts.md) that other plop users have found useful.
``` javascript
module.exports = function (plop) {
plop.addPrompt('directory', require('inquirer-directory'));
};
```
Next we need to setup a generator using `plop.setGenerator`
---
## plop.setGenerator(name, config);

@@ -89,3 +111,4 @@ - name {String}

```
## Actions Array
---
# The Actions Array
The `plop.setGenerator` config object includes an array of actions to take. There are two types of actions you can include (add and modify). Both types of actions require a path to take action on (all paths are based on the location of the plopfile), and a template to use.

@@ -157,3 +180,31 @@

## Baked-In Helpers
# Other Plop Methods/Attributes
These methods and attributes are available off the `plop` object. They are mostly used by plop internally, but some can come in handy when you're doing something a little more custom.
#### plop.renderString(template, data)
- template {String}
- data {Object}
Renders the handlebars `template` using the `data` passed in. Returns the rendered template.
#### plop.getGenerator(name)
- name {String}
Gets a generator config object by name.
#### plop.getGeneratorList()
Gets an array of generator names and descriptions.
#### plop.getPlopfilePath
Returns the absolute path to the plopfile in use.
#### plop.inquirer
The instance of inquirer that plop is using internally.
#### plop.handlebars
The instance of handlebars that plop is using internally.
---
# Baked-In Helpers
There are a few helpers that I have found useful enough to include with plop. They are mostly case modifiers, but here is the complete list.

@@ -175,3 +226,3 @@

## Usage
# Usage
Once plop is installed, and you have created a generator, you are ready to run plop from the terminal. Running `plop` with no parameters will present you with a list of generators to pick from. You can also run `plop [generatorName]` to trigger a generator directly.

@@ -181,3 +232,3 @@

## Why?
# Why?
Because when you create your boilerplate separate from your code, you naturally put more time and thought into it.

@@ -189,5 +240,5 @@

## Why Not Yeoman?
### Why Not Yeoman?
Yeoman is great and it does a fantastic job of scaffolding out an initial codebase for you. However, the initial codebase is just the beginning. I believe the true benefit to generators is not realized by saving a developer 40 hours in the beginning, but by saving a team days of work over the life of the project. Yes, yeoman has sub generators that do a similar job. However, if you're like me, you will continually tweak structure and code throughout the project till the sub generators that came built into your yeoman seed are no longer valid. These structures change as requirements change and code is refactored. Plop allows your generator code to live INSIDE your project and be versioned right along with the code it generates.
If you already have another generator that your organization uses and loves, use it :-). If you don't, try plop. It will make your code more consistent, save you lots of time, and (if you've read this far) you already know how to use it.

Sorry, the diff of this file is not supported yet

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