UNPKG

1.31 kBJavaScriptView Raw
1function addLeafs(options) {
2 'use strong'
3
4 const co = require('co')
5 const prompt = require('co-prompt')
6 const path = require('path')
7 const fse = require('fs-extra')
8 const chalk = require('chalk')
9 const book = require('book-length')
10 const pulp = require(path.join('..', 'generators', 'addPages.js'))
11
12 co(function*() {
13 let leafs
14 if (options !== undefined && options.leafs % 1 === 0) {
15 leafs = options.leafs
16 } else {
17 leafs = yield prompt('No. of leafs?: ')
18 }
19 return leafs
20 }).then(leafs => {
21 fse.readJson(path.join('.', '.bookrc'))
22 .then(bookrc => {
23 let { mode } = bookrc
24
25 process.stdout.write(chalk.yellow(`${chalk.blue(JSON.stringify([mode.HTML, mode.CSS]))} : Adding [ ${chalk.magenta(leafs)} ] leaf(s)… : `))
26
27 let startAt = book.length() + 1
28 let pages = leafs * 2
29
30 pulp.addPages({ startAt, pages, mode }) // Spawn a process?
31 }).catch((err) => {
32 if (err) return console.log(chalk.red('Could not read book mode:', err))
33 })
34 }).catch(err => {
35 if (err) { return console.log(chalk.red('Adding leafs failed:', err)) }
36 })
37}
38
39module.exports.addLeafs = addLeafs
\No newline at end of file