mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 02:53:29 +00:00
Add lex sub-command to gitbook binary
The lex command is useful for debugging files and seeing how they are parsed
This commit is contained in:
@@ -5,8 +5,11 @@ var _ = require('lodash');
|
||||
var path = require('path');
|
||||
var prog = require('commander');
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var pkg = require('../package.json');
|
||||
var generate = require("../lib/generate");
|
||||
var parse = require("../lib/parse");
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
@@ -53,6 +56,16 @@ prog
|
||||
});
|
||||
});
|
||||
|
||||
prog
|
||||
.command('lex <page_file>')
|
||||
.description('Parse a page file into sections, display JSON dump')
|
||||
.action(function(page_file) {
|
||||
var parsed = parse.page(fs.readFileSync(page_file, 'utf-8'));
|
||||
|
||||
console.log(JSON.stringify(parsed, null, 4));
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Parse and fallback to help if no args
|
||||
if(_.isEmpty(prog.parse(process.argv).args) && process.argv.length === 2) {
|
||||
|
||||
Reference in New Issue
Block a user