Comparing version 1.3.0 to 1.4.0
{ | ||
"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" | ||
} | ||
} |
69
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34712
18
598
237
10
1
5
+ Addedinterpret@^1.0.0
+ Addedliftoff@^2.2.0
+ Addedminimist@^1.2.0
+ Addedv8flags@^2.0.10
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-each@1.0.1(transitive)
+ Addedarray-slice@1.1.0(transitive)
+ Addedarray-unique@0.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbraces@2.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addeddetect-file@1.0.0(transitive)
+ Addedexpand-brackets@2.1.4(transitive)
+ Addedexpand-tilde@2.0.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@2.0.4(transitive)
+ Addedfill-range@4.0.0(transitive)
+ Addedfindup-sync@2.0.0(transitive)
+ Addedfined@1.2.0(transitive)
+ Addedflagged-respawn@1.0.1(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@1.0.0(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglobal-modules@1.0.0(transitive)
+ Addedglobal-prefix@1.0.2(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhomedir-polyfill@1.0.3(transitive)
+ Addedini@1.3.8(transitive)
+ Addedinterpret@1.4.0(transitive)
+ Addedis-absolute@1.0.0(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@3.1.0(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-relative@1.0.0(transitive)
+ Addedis-unc-path@1.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedliftoff@2.5.0(transitive)
+ Addedmake-iterator@1.0.1(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmicromatch@3.1.10(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedms@2.0.0(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.defaults@1.1.0(transitive)
+ Addedobject.map@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedparse-filepath@1.0.2(transitive)
+ Addedparse-passwd@1.0.0(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-root@0.1.1(transitive)
+ Addedpath-root-regex@0.1.2(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedrechoir@0.6.2(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedresolve-dir@1.0.1(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunc-path-regex@0.1.2(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
+ Addeduser-home@1.1.1(transitive)
+ Addedv8flags@2.1.1(transitive)
+ Addedwhich@1.3.1(transitive)
- Removedfindup-sync@^0.1.3
- Removedfindup-sync@0.1.3(transitive)
- Removedglob@3.2.11(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlodash@2.4.2(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.3.0(transitive)
- Removedsigmund@1.0.1(transitive)