-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbookly2.js
executable file
·122 lines (108 loc) · 3.1 KB
/
bookly2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
GLOBAL.__base = require('path').dirname(require.main.filename) + "/";
GLOBAL.__cwd = process.cwd() + "/";
/* Utilities */
GLOBAL.__blogger = require('./lib/helpers/blogger');
/* core */
var app = require('./lib/config');
var fs = require('fs-extra');
var program = require('commander');
var action = require('./lib/action');
/* Commands */
var init = require('./lib/actions/init');
var builder = require("./lib/actions/builder");
var concat = require("./lib/actions/concat");
/* global settings */
var global = { keyword: process.argv[2] };
/* program */
program
.version(app.version)
.usage("<command> [options]")
.option("-f, --formats <formats>", "File format to convert to: `pdf, epub, html, mobi, md`")
.option("-c, --config <config file>", "The config file containing book name, input and output paths")
.option("-a, --all-formats", "If present, it will build the book in all formats")
.option("-e, --chapters-only", "If you only want to build each chapter (pdf and html)")
.option("-r, --render", "Can be executed after build -e. Converts each chapter to pdf with phantomjs")
.option("-p, --patterns <patterns>", "Input patterns to use: eg. '**/*.markdown, **/**/*.md'")
.option("-n, --version-number <versionnumber>", "Specifies a version for the book")
.option("-m, --manuscript <folder name>", "Folder name for the manuscript")
// .on("--help", function(){ __blogger.printHelp() }) // for custom help
action.add(
{
name: "build",
// arg: "format",
description: "Create the book in different formats"
},
function(prompt, converTo) {
builder.build({
formats: prompt.formats,
config: prompt.config,
isRender: prompt.render,
isChaptersOnly: prompt.chaptersOnly,
patterns: prompt.patterns ,
isAll: prompt.allFormats,
version: prompt.versionNumber
});
});
action.add(
{
name: "new",
arg: "name",
description: "Start a new project"
},
function(prompt, projectName) {
init.run({name: projectName});
});
action.add(
{
name: "concat",
// arg: "name",
description: "Concats files in each chapter folder into one"
},
function(prompt, projectName) {
concat({
config: prompt.config,
patterns: prompt.patterns,
manuscript: prompt.manuscript
});
});
action.add(
{
name: "help",
description: "Provides overview of the options and actions/keywords"
},
function(bookly) {
bookly.help();
});
action.add(
{
name: "docs",
description: "Prints the docs to the console with examples."
},
function(data) {
__blogger.printHelp();
});
action.add(
{
name: "docsfor",
arg: "command_name",
description: "Print the help for a given action or command: eg: bookly docsfor build"
},
function(data, what) {
__blogger.docsFor(what);
});
/* catch invalid commands */
action.add(
{
name: "*",
description: "Catch invalid tasks"
},
function(data){
__blogger.warn("Comand Doesn't exist");
__blogger.info("See the available options and tasks below:");
program.help();
});
/* read args */
program.parse(process.argv);
/* if no args, show help */
if(!global.keyword) { program.help(); }