Skip to content

Commit

Permalink
small adjustments to help screen layout and code location
Browse files Browse the repository at this point in the history
  • Loading branch information
amwmedia committed Feb 7, 2016
1 parent 1281537 commit b73920b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : true, // Prohibit variable use before definition.
"latedef" : "nofunc", // Prohibit variable use before definition.
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"loopfunc" : false, // Allow functions to be defined within loops.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Plop

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

[![npm](https://img.shields.io/npm/dm/plop.svg)]()
[![npm](https://img.shields.io/npm/v/plop.svg)]()

![plop demo](http://i.imgur.com/penUFkr.gif)

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.
Expand Down Expand Up @@ -127,14 +130,14 @@ The `Add` and `Modify` actions will take care of almost every case that plop is

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

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

This allows you to adapt actions to provided answers:

``` javascript
module.exports = function (plop) {
plop.setGenerator('test', {
plop.setGenerator('test', {
description: 'this is a test',
prompts: [{
type: 'input',
Expand Down
32 changes: 31 additions & 1 deletion mod/console-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

var colors = require('colors');
var inquirer = require('inquirer');
var fs = require('fs');
var q = require('q');

module.exports = (function () {

function chooseOptionFromList(plopList) {
var _d = q.defer();

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

function displayHelpScreen() {
console.log(
'\n' +
'USAGE:\n' +
' $ plop <name>\t\tRun a generator registered under that name\n' +

'\n' +
'OPTIONS:\n' +
' -h, --help\t\tShow this help display\n' +
' -i, --init\t\tGenerate initial plopfile.js\n' +
' -v, --version\t\tPrint current version\n'
);
}

function createInitPlopfile(cwd, callback){
var initString = 'module.exports = function (plop) {\n\n' +
'\tplop.setGenerator(\'basics\', {\n' +
'\t\tdescription: \'this is a skeleton plopfile\',\n' +
'\t\tprompts: [],\n' +
'\t\tactions: []\n' +
'\t});\n\n' +
'};';

fs.writeFile( + '/plopfile.js', initString, callback);
}

return {
chooseOptionFromList: chooseOptionFromList
chooseOptionFromList: chooseOptionFromList,
displayHelpScreen: displayHelpScreen,
createInitPlopfile: createInitPlopfile
};
})();
44 changes: 9 additions & 35 deletions plop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
'use strict';

var path = require('path');
var fs = require('fs');
var Liftoff = require('liftoff');
var argv = require('minimist')(process.argv.slice(2));
var v8flags = require('v8flags');
Expand Down Expand Up @@ -35,18 +34,17 @@ function run(env) {

// handle request for usage and options
if (argv.help || argv.h) {
displayHelpScreen();
out.displayHelpScreen();
process.exit(0);
}


// handle request for initializing a new plopfile
if (argv.init || argv.i) {
return createInitPlopfile(function(err){
return out.createInitPlopfile(env.cwd, function(err){
if (err){
console.log(err);

process.exit(1);
}

process.exit(0);
});
}
Expand All @@ -66,7 +64,7 @@ function run(env) {
// abort if there's no plopfile found
if (plopfilePath == null) {
console.error(colors.red('[PLOP] ') + 'No plopfile found');
displayHelpScreen();
out.displayHelpScreen();
process.exit(1);
}

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

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

function displayHelpScreen(){
console.log('\n' +
'\tUsage\n' +
'\t\t$ plop <name>\t\tRun a generator registered under that name\n' +

'\n' +
'\tOptions\n' +
'\t\t-h, --help\t\tShow this help display\n' +
'\t\t-i, --init\t\tGenerate initial plopfile.js\n' +
'\t\t-v, --version\t\tPrint current version\n');
}

function createInitPlopfile(callback){
var initString = 'module.exports = function (plop) {\n\n' +
'\tplop.setGenerator(\'basics\', {\n' +
'\t\tdescription: \'this is a skeleton plopfile\',\n' +
'\t\tprompts: [],\n' +
'\t\tactions: []\n' +
'\t});\n\n' +
'};';

fs.writeFile(env.cwd + '/plopfile.js', initString, callback);
}

}

function go(generator) {
function doThePlop(generator) {
logic.getPlopData(generator)
.then(logic.executePlop)
.then(function (result) {
Expand All @@ -127,4 +101,4 @@ function go(generator) {
console.error('[ERROR]'.red, err.message, err.stack);
process.exit(1);
});
}
}

0 comments on commit b73920b

Please sign in to comment.