Skip to content

Commit b73920b

Browse files
committed
small adjustments to help screen layout and code location
1 parent 1281537 commit b73920b

File tree

4 files changed

+47
-40
lines changed

4 files changed

+47
-40
lines changed

.jshintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
5252
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
5353
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
54-
"latedef" : true, // Prohibit variable use before definition.
54+
"latedef" : "nofunc", // Prohibit variable use before definition.
5555
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
5656
"loopfunc" : false, // Allow functions to be defined within loops.
5757
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Plop
33

44
Micro-generator framework that makes it easy for an entire team to create files with a level or uniformity.
55

6+
[![npm](https://img.shields.io/npm/dm/plop.svg)]()
7+
[![npm](https://img.shields.io/npm/v/plop.svg)]()
8+
69
![plop demo](http://i.imgur.com/penUFkr.gif)
710

811
Plop is essentially glue code between [inquirer](https://github.com/SBoudrias/Inquirer.js/) prompts and [handlebar](https://github.com/wycats/handlebars.js/) templates. You can also add your own handlebar helper methods and use them in your templates.
@@ -127,14 +130,14 @@ The `Add` and `Modify` actions will take care of almost every case that plop is
127130

128131
_See the [example plopfile](https://github.com/amwmedia/plop/blob/master/example/plopfile.js) for a sample synchronous custom action._
129132

130-
### Using an Actions Function
131-
Alternatively, `actions` can be a function that takes responses `data` as a parameter and should return an array of actions.
133+
### Using a Dynamic Action Array
134+
Alternatively, `actions` can itself be a function that takes responses `data` as a parameter and should return the actions array.
132135

133136
This allows you to adapt actions to provided answers:
134137

135138
``` javascript
136139
module.exports = function (plop) {
137-
plop.setGenerator('test', {
140+
plop.setGenerator('test', {
138141
description: 'this is a test',
139142
prompts: [{
140143
type: 'input',

mod/console-out.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
var colors = require('colors');
44
var inquirer = require('inquirer');
5+
var fs = require('fs');
56
var q = require('q');
67

78
module.exports = (function () {
9+
810
function chooseOptionFromList(plopList) {
911
var _d = q.defer();
1012

@@ -27,7 +29,35 @@ module.exports = (function () {
2729
return _d.promise;
2830
}
2931

32+
function displayHelpScreen() {
33+
console.log(
34+
'\n' +
35+
'USAGE:\n' +
36+
' $ plop <name>\t\tRun a generator registered under that name\n' +
37+
38+
'\n' +
39+
'OPTIONS:\n' +
40+
' -h, --help\t\tShow this help display\n' +
41+
' -i, --init\t\tGenerate initial plopfile.js\n' +
42+
' -v, --version\t\tPrint current version\n'
43+
);
44+
}
45+
46+
function createInitPlopfile(cwd, callback){
47+
var initString = 'module.exports = function (plop) {\n\n' +
48+
'\tplop.setGenerator(\'basics\', {\n' +
49+
'\t\tdescription: \'this is a skeleton plopfile\',\n' +
50+
'\t\tprompts: [],\n' +
51+
'\t\tactions: []\n' +
52+
'\t});\n\n' +
53+
'};';
54+
55+
fs.writeFile( + '/plopfile.js', initString, callback);
56+
}
57+
3058
return {
31-
chooseOptionFromList: chooseOptionFromList
59+
chooseOptionFromList: chooseOptionFromList,
60+
displayHelpScreen: displayHelpScreen,
61+
createInitPlopfile: createInitPlopfile
3262
};
3363
})();

plop.js

+9-35
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
'use strict';
44

55
var path = require('path');
6-
var fs = require('fs');
76
var Liftoff = require('liftoff');
87
var argv = require('minimist')(process.argv.slice(2));
98
var v8flags = require('v8flags');
@@ -35,18 +34,17 @@ function run(env) {
3534

3635
// handle request for usage and options
3736
if (argv.help || argv.h) {
38-
displayHelpScreen();
37+
out.displayHelpScreen();
3938
process.exit(0);
4039
}
41-
40+
41+
// handle request for initializing a new plopfile
4242
if (argv.init || argv.i) {
43-
return createInitPlopfile(function(err){
43+
return out.createInitPlopfile(env.cwd, function(err){
4444
if (err){
4545
console.log(err);
46-
4746
process.exit(1);
4847
}
49-
5048
process.exit(0);
5149
});
5250
}
@@ -66,7 +64,7 @@ function run(env) {
6664
// abort if there's no plopfile found
6765
if (plopfilePath == null) {
6866
console.error(colors.red('[PLOP] ') + 'No plopfile found');
69-
displayHelpScreen();
67+
out.displayHelpScreen();
7068
process.exit(1);
7169
}
7270

@@ -78,41 +76,17 @@ function run(env) {
7876

7977
generators = plop.getGeneratorList();
8078
if (!generator) {
81-
out.chooseOptionFromList(generators).then(go);
79+
out.chooseOptionFromList(generators).then(doThePlop);
8280
}else if (generators.map(function (v) { return v.name; }).indexOf(generator) > -1) {
83-
go(generator);
81+
doThePlop(generator);
8482
} else {
8583
console.error(colors.red('[PLOP] ') + 'Generator "' + generator + '" not found in plopfile');
8684
process.exit(1);
8785
}
8886

89-
function displayHelpScreen(){
90-
console.log('\n' +
91-
'\tUsage\n' +
92-
'\t\t$ plop <name>\t\tRun a generator registered under that name\n' +
93-
94-
'\n' +
95-
'\tOptions\n' +
96-
'\t\t-h, --help\t\tShow this help display\n' +
97-
'\t\t-i, --init\t\tGenerate initial plopfile.js\n' +
98-
'\t\t-v, --version\t\tPrint current version\n');
99-
}
100-
101-
function createInitPlopfile(callback){
102-
var initString = 'module.exports = function (plop) {\n\n' +
103-
'\tplop.setGenerator(\'basics\', {\n' +
104-
'\t\tdescription: \'this is a skeleton plopfile\',\n' +
105-
'\t\tprompts: [],\n' +
106-
'\t\tactions: []\n' +
107-
'\t});\n\n' +
108-
'};';
109-
110-
fs.writeFile(env.cwd + '/plopfile.js', initString, callback);
111-
}
112-
11387
}
11488

115-
function go(generator) {
89+
function doThePlop(generator) {
11690
logic.getPlopData(generator)
11791
.then(logic.executePlop)
11892
.then(function (result) {
@@ -127,4 +101,4 @@ function go(generator) {
127101
console.error('[ERROR]'.red, err.message, err.stack);
128102
process.exit(1);
129103
});
130-
}
104+
}

0 commit comments

Comments
 (0)