How to install Gitbook-cli on Windows Computer

tuenhai.com 2018-12-03

🚌 How to Install NodeJs on Windows

https://nodejs.org/en/

Version 10.14.1, include npm

😼 Install Git for Windows

https://git-scm.com/download/win

🐠 Install gitbook-cli from git Bash

$ npm install gitbook-cli -g

C:\Users\tuenhai.com\AppData\Roaming\npm\gitbook -> C:\Users\tuenhai.com\AppData\Roaming\npm\node_modules\gitbook-cli\bin\gitbook.js
+ gitbook-cli@2.3.2
added 578 packages from 672 contributors in 94.104s

$ gitbook help
Installing GitBook 3.2.3


$ gitbook help
build [book] [output]       build a book
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
    --format                Format to build to (Default is website; Values are website, json, ebook)
    --[no-]timing           Print timing debug information (Default is false)

serve [book] [output]       serve the book as a website for testing
    --port                  Port for server to listen on (Default is 4000)
    --lrport                Port for livereload server to listen on (Default is 35729)
    --[no-]watch            Enable file watcher and live reloading (Default is true)
    --[no-]live             Enable live reloading (Default is true)
    --[no-]open             Enable opening book in browser (Default is false)
    --browser               Specify browser for opening book (Default is )
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
    --format                Format to build to (Default is website; Values are website, json, ebook)

install [book]              install all plugins dependencies
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

parse [book]                parse and print debug information about a book
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

init [book]                 setup and create files for chapters
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

pdf [book] [output]         build a book into an ebook file
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

epub [book] [output]        build a book into an ebook file
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

mobi [book] [output]        build a book into an ebook file
    --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)


$ gitbook -V
CLI version: 2.3.2
GitBook version: 3.2.3

gitbook-cli store GitBook's versions into ~/.gitbook, you can set the GITBOOK_DIR environment variable to use another directory

🚕 How to install ebook-converter

https://calibre-ebook.com/download

Restart git Bash after installation

🏈 Check NPM global node_modules location

$ npm config ls -l | grep prefix
prefix = "C:\\Users\\tuenhai.com\\AppData\\Roaming\\npm"
; prefix = "C:\\Program Files\\nodejs" (overridden)
save-prefix = "^"
tag-version-prefix = "v"

🎳 Install gitbook plugins to global node_modules folder

If you have a lot of e-book project, then there is a node_modules directory under each project, so there will be many duplicate packages

In order to solve many duplicate files, we can do this:

  • Install gitbook plugins to global location, for example:

    $ npm install gitbook-plugin-page-footer-ex -g

  • Create a soft link in each e-book project

Press Windows key, type command, then right-click on Command Prompt, Select Run ad administrator

$ cd C:\books\tuenhai.com
$ mklink /D node_modules C:\Users\tuenhai.com\AppData\Roaming\npm\node_modules

npm global package location is C:\Users\tuenhai.com\AppData\Roaming\npm\node_modules

🎃 Work with Dropbox

  • Create folder node_modules, _book in e-book project
  • Dropbox Selective Sync.., uncheck node_modules, _book
  • Delete folder node_modules
  • Create soft link folder node_modules in e-book project

😎 How to build ebook using gitbook-cli

book-build.sh:

#!/bin/bash

# build.sh by htps://www.tuenhai.com

cd ~/books/tuenhai.com

# install plugins
#gitbook install

# build static site
gitbook build

gitbook pdf . _book/tuenhai.com.pdf
gitbook epub . _book/tuenhai.com.epub
gitbook mobi . _book/tuenhai.com.mobi

👽 Fix disqus plugin error

info: loading plugin "disqus"... ERROR

Error: GitBook doesn't satisfy the requirements of this plugin: >=4.0.0-alpha

Fix it by:

$ npm install gitbook-plugin-disqus@0.1.0 -g

then set disqus version in book.json:

"disqus@0.1.0"

Reference:

results matching ""

    No results matching ""