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",