UNPKG

994 BJavaScriptView Raw
1function removePage (removeAt) {
2 'use strong'
3
4 const chalk = require('chalk')
5 const path = require('path')
6 const manuscript = require(path.join('..', 'scripts', 'deletePage.js'))
7 const stack = require(path.join('..', 'scripts', 'pushStackUp.js'))
8 const fse = require('fs-extra')
9
10 const book = require('book-length')
11
12 let bookLength = book.length()
13
14 process.stdout.write(chalk.yellow(`Deleting page @[ ${chalk.blue(removeAt)} ]… :`))
15
16 manuscript.deletePage(removeAt, () => {
17 stack.pushStackUp(parseInt(removeAt), bookLength, () => {
18 fse.readJson(path.join('.', '.bookrc'))
19 .then(bookrc => {
20 const pulp = require(path.join('..', 'generators', 'addPages.js'))
21
22 let { mode } = bookrc
23 let pages = 1
24
25 pulp.addPages({ bookLength, pages, mode })
26 }).catch((err) => {
27 if (err) return console.log(chalk.red('Could not read book mode:', err))
28 })
29 })
30 })
31}
32
33module.exports.removePage = removePage