From 750e22c0f03a5243b5842696c753b2d54cda525c Mon Sep 17 00:00:00 2001 From: Andrew Worcester Date: Fri, 18 Nov 2016 12:39:56 -0500 Subject: [PATCH] added plop.load example code --- example/plopfile.js | 21 ++++++++++++++++++--- example/templates/burger.txt | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/example/plopfile.js b/example/plopfile.js index 456fdee7..e937ffd0 100644 --- a/example/plopfile.js +++ b/example/plopfile.js @@ -1,4 +1,5 @@ 'use strict'; +const path = require('path'); module.exports = function (plop) { // helpers are passed through to handlebars and made @@ -13,9 +14,20 @@ module.exports = function (plop) { return words.join(', ').replace(/(:?.*),/, '$1, and'); }); + plop.addHelper('absPath', function (p) { + return path.resolve(plop.getPlopfilePath(), p); + }); + // greet the user using a partial plop.addPartial('salutation', '{{ greeting }}, my name is {{ properCase name }} and I am {{ age }}.'); + // load some additional helpers from a module I "npm install"ed + plop.load('plop-pack-fancy-comments', { + prefix: '', + upperCaseHeaders: true, + commentStart: '', + commentEnd: '' + }); // setGenerator creates a generator that can be run with "plop generatorName" plop.setGenerator('test', { @@ -125,10 +137,13 @@ module.exports = function (plop) { } ], actions: [ - { + function(data) { + console.log(data); + return 'yay'; + }, { type: 'add', - path: '{{path}}/{{fileName}}.txt', - template: '{{path}}/{{fileName}} plopped!' + path: '{{absPath path}}/{{fileName}}.txt', + template: '{{absPath path}}/{{fileName}} plopped!' } ] }); diff --git a/example/templates/burger.txt b/example/templates/burger.txt index acd80075..7c3a7f1e 100644 --- a/example/templates/burger.txt +++ b/example/templates/burger.txt @@ -1 +1,3 @@ +{{ header 'Hello Burger Lover!' }} + Here's your burger {{ properCase name }}!