Skip to content

Commit

Permalink
Add a pass on a CLI for panini
Browse files Browse the repository at this point in the history
  • Loading branch information
kball committed Nov 2, 2016
1 parent f110fe4 commit b783736
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
58 changes: 58 additions & 0 deletions bin/panini.js
Original file line number Diff line number Diff line change
@@ -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));
}
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var panini;
var help = require('./lib/helpMessage');

/**
* Initializes an instance of Panini.
Expand Down Expand Up @@ -47,3 +48,6 @@ module.exports = function(options) {

module.exports.Panini = Panini;
module.exports.refresh = function() {}
module.exports.help = function() {
help();
}
19 changes: 19 additions & 0 deletions lib/helpMessage.js
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <geoff@zurb.com>",
"author": "ZURB <foundation@zurb.com> (http://zurb.com)",
"license": "MIT",
"bin": {
"panini": "./bin/panini.js"
},
"dependencies": {
"deepmerge": "^0.2.10",
"front-matter": "^2.0.5",
Expand All @@ -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",
Expand Down

0 comments on commit b783736

Please sign in to comment.