From b783736f4f0e9268c8fd1d6f90335aa72c5f7105 Mon Sep 17 00:00:00 2001 From: Kevin Ball Date: Wed, 2 Nov 2016 13:22:54 -0700 Subject: [PATCH 1/2] Add a pass on a CLI for panini --- bin/panini.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++ index.js | 4 ++++ lib/helpMessage.js | 19 +++++++++++++++ package.json | 11 ++++++--- 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100755 bin/panini.js create mode 100644 lib/helpMessage.js diff --git a/bin/panini.js b/bin/panini.js new file mode 100755 index 0000000..932a894 --- /dev/null +++ b/bin/panini.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node + +var nopt = require('nopt'); +var pkg = require('../package.json'); +var panini = require('../index'); +var vfs = require('vinyl-fs'); +var path = require('path'); + + +// Options that can be passed to commands +var options = { + "root": String, + "layouts": String, + "partials": String, + "data": String, + "helpers": String, + "output": String, + "version": String +} + +// Shorthands for the above commands +var shorthands = { + "r": "--root", + "l": "--layouts", + "p": "--partials", + "d": "--data", + "h": "--helpers", + "o": "--output", + "v": "--version" +} + +var parsed = nopt(options, shorthands); + +// cmd.args contains basic commands like "new" and "help" +// cmd.opts contains options, like --libsass and --version +var cmd = { + args: parsed.argv.remain, + opts: parsed +} + +// No other arguments given +if (typeof cmd.args[0] === 'undefined') { + // If -v or --version was passed, show the version of the CLI + if (typeof cmd.opts.version !== 'undefined') { + process.stdout.write("Panini version " + require('../package.json').version + '\n'); + } + // Otherwise, just show the help screen + else { + panini.help(); + } +} + +// Arguments given +else { + vfs.src(cmd.args). + pipe(panini(cmd.opts)). + pipe(vfs.dest(cmd.opts.output)); +} diff --git a/index.js b/index.js index 09c90de..3211c78 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ var panini; +var help = require('./lib/helpMessage'); /** * Initializes an instance of Panini. @@ -47,3 +48,6 @@ module.exports = function(options) { module.exports.Panini = Panini; module.exports.refresh = function() {} +module.exports.help = function() { + help(); +} diff --git a/lib/helpMessage.js b/lib/helpMessage.js new file mode 100644 index 0000000..05c7d5c --- /dev/null +++ b/lib/helpMessage.js @@ -0,0 +1,19 @@ + +module.exports = function() { + var txt = 'Usage: panini --layouts=[layoutdir] --root=[rootdir] --dest=[destdir] [other options] \'pagesglob\'\n' + + '\n' + + 'Options: \n' + + ' --layouts (required) path to a folder containing layouts\n' + + ' --root (required) path to the root folder all pages live in\n' + + ' --dest (required) path to the folder compiled pages should get sent to\n' + + ' --partials path to root folder for partials \n' + + ' --helpers path to folder for additional helpers \n' + + ' --data path to folder for additional data \n' + + '\n' + + 'the argument pagesglob should be a glob describing what pages you want to apply panini to.\n' + + '\n' + + 'Example: panini --root=src/pages --layouts=src/layouts --partials=src/partials --data=src/data --output=dist \'src/pages/**/*.html\''; + + + process.stdout.write(txt); +} diff --git a/package.json b/package.json index 6b9a112..23f2b8e 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,16 @@ { "name": "panini", - "version": "1.3.0", + "version": "1.3.1", "description": "A super tiny flat file compiler.", "main": "index.js", "scripts": { "test": "mocha --compilers js:babel-register --reporter nyan" }, - "author": "Geoff Kimball ", + "author": "ZURB (http://zurb.com)", "license": "MIT", + "bin": { + "panini": "./bin/panini.js" + }, "dependencies": { "deepmerge": "^0.2.10", "front-matter": "^2.0.5", @@ -16,7 +19,9 @@ "highlight.js": "^8.9.1", "js-yaml": "^3.5.2", "marked": "^0.3.5", - "through2": "^2.0.0" + "through2": "^2.0.0", + "nopt": "^3.0.6", + "vinyl-fs": "^2.4.4" }, "devDependencies": { "assert-dir-equal": "^1.0.1", From 4148b55cca04638b296064d23dad0a4d1c0b946b Mon Sep 17 00:00:00 2001 From: Kevin Ball Date: Thu, 3 Nov 2016 08:54:38 -0700 Subject: [PATCH 2/2] Add help message to readme --- lib/helpMessage.js | 2 +- readme.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/helpMessage.js b/lib/helpMessage.js index 05c7d5c..fa28f3e 100644 --- a/lib/helpMessage.js +++ b/lib/helpMessage.js @@ -12,7 +12,7 @@ module.exports = function() { '\n' + 'the argument pagesglob should be a glob describing what pages you want to apply panini to.\n' + '\n' + - 'Example: panini --root=src/pages --layouts=src/layouts --partials=src/partials --data=src/data --output=dist \'src/pages/**/*.html\''; + 'Example: panini --root=src/pages --layouts=src/layouts --partials=src/partials --data=src/data --output=dist \'src/pages/**/*.html\'\n'; process.stdout.write(txt); diff --git a/readme.md b/readme.md index 880810e..0c60df8 100644 --- a/readme.md +++ b/readme.md @@ -125,6 +125,26 @@ Data can also be inserted into the page itself with a Front Matter template at t Lastly, the reserved `page` variable is added to every page template as it renders. It contains the name of the page being rendered, without the extension. +## CLI + +You can also use panini via the CLI. + +``` +Usage: panini --layouts=[layoutdir] --root=[rootdir] --dest=[destdir] [other options] 'pagesglob' + +Options: + --layouts (required) path to a folder containing layouts + --root (required) path to the root folder all pages live in + --dest (required) path to the folder compiled pages should get sent to + --partials path to root folder for partials + --helpers path to folder for additional helpers + --data path to folder for additional data + +the argument pagesglob should be a glob describing what pages you want to apply panini to. + +Example: panini --root=src/pages --layouts=src/layouts --partials=src/partials --data=src/data --output=dist 'src/pages/**/*.html' +``` + ## Local Development ```bash