Add command 'parse' for gitbook-cli

This commit is contained in:
Samy Pessé
2016-02-17 10:11:33 +01:00
parent db3d21db49
commit 8141bcb3b6
5 changed files with 98 additions and 37 deletions
+50
View File
@@ -0,0 +1,50 @@
var _ = require('lodash');
var Book = require('../book');
var NodeFS = require('../fs/node');
var Logger = require('../utils/logger');
var LOG_OPTION = {
name: 'log',
description: 'Minimum log level to display',
values: _.chain(Logger.LEVELS)
.keys()
.map(function(s) {
return s.toLowerCase();
})
.value(),
defaults: 'info'
};
// Commands which is processing a book
// the root of the book is the first argument (or current directory)
function bookCmd(fn) {
return function(args, kwargs) {
var input = args[0] || process.cwd();
var book = new Book({
fs: new NodeFS(),
root: input,
logLevel: kwargs.log
});
return fn(book, args.slice(1));
};
}
// Commands which is working on a Output instance
function outputCmd(Out, fn) {
return bookCmd(function(book, args) {
return fn(new Out(book), args);
});
}
module.exports = {
bookCmd: bookCmd,
outputCmd: outputCmd,
options: {
log: LOG_OPTION
}
};
+44
View File
@@ -0,0 +1,44 @@
var Output = require('../output/base');
var helper = require('./helper');
module.exports = {
commands: [
{
name: 'parse [book]',
description: 'parse and returns debug information for a book',
options: [
helper.options.log
],
exec: helper.bookCmd(function(book) {
return book.parse()
.then(function() {
book.log.info.ln('');
if (book.config.exists()) book.log.info.ln('Configuration:', book.config.path);
if (book.isMultilingual()) {
book.log.info.ln('Multilingual book detected:', book.langs.path);
} else {
book.log.info.ln('Readme:', book.readme.path);
book.log.info.ln('Summary:', book.summary.path);
if (book.glossary.exists()) book.log.info.ln('Glossary:', book.glossary.path);
}
});
})
},
{
name: 'install [book]',
description: 'install all plugins dependencies',
options: [
helper.options.log
],
exec: helper.outputCmd(Output, function(output, args) {
})
}
]
};
+1 -1
View File
@@ -19,7 +19,7 @@ function Config(book, baseConfig) {
this.book = book;
this.fs = book.fs;
this.log = book.log;
this.path = null;
this.path = '';
this.replace(baseConfig || {});
}
+2 -35
View File
@@ -1,40 +1,7 @@
var Book = require('./book');
var Output = require('./output');
var NodeFS = require('./fs/node');
// Setup a Book for the arguments
function setupBook(args) {
var input = args[0] || process.cwd();
return new Book({
fs: new NodeFS(),
root: input
});
}
// Setup an Output for the arguments
function setupOutput(Out, args) {
return new Out(setupBook(args));
}
var cli = require('./cli');
module.exports = {
Book: Book,
commands: [
{
name: 'install [book]',
description: 'install all plugins dependencies',
exec: function(args) {
var book = setupBook(args);
return book.config.load()
.then(function() {
return book.plugins.install();
})
.then(function(){
console.log('');
console.log(color.green('Done, without error'));
});
}
},
]
commands: cli.commands
};
+1 -1
View File
@@ -20,7 +20,7 @@ function Output(book) {
this.log = this.book.log;
// Create plugins manager
this.plugins = new PluginsManager(book);
this.plugins = new PluginsManager(this);
// Create template engine
this.template = new TemplateEngine(this);