最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】给crifan的gitbook的template添加debug时指定特定端口

gitbook crifan 836浏览 0评论
在用自己crifan的gitbook的template
https://github.com/crifan/gitbook_template
去同时弄2个book
导致,如果想要在两者之间切换
就要断开当前的
make debug
切换到另外一个目录,再去
make debug
因为两者都是同一个4000端口
无法同时运行,否则会冲突
所以希望是:
给自己的make debug中加上端口能单独指定
去研究看看
如何给
make debug
传入 比如 port=40001 之类的参数
make pass parameter
makefile – Passing additional variables from command line to make – Stack Overflow
FOO?=default_value_if_not_set_in_environment
make target FOO=bar
即:
  • makefile中定义 xxx ?= YYY
  • 命令行中指定值:make xxx=ZZZ
即可实现:
  • xxx参数的值
    • 如果没传参数,用默认YYY
    • 如果传了,用ZZZ
去看看此处自己的makefile内部逻辑
common/gitbook_makefile.mk
## Debug gitbook
debug: sync_content clean_debug create_folder_debug
    gitbook serve $(CURRENT_DIR) $(DEBUG_PATH) $(GITBOOK_COMMON_FLAGS)
原来是
gitbook serve
去找找能否指定port
gitbook serve port
node.js – How to change default listening port when use gitbook to serve a site? – Stack Overflow
gitbook --port 3000 serve

gitbook --lrport 35730 --port 4001 serve
gitbook --lrport 35731 --port 4002 serve
去看看gitbook的help:
 ~  gitbook --help

  Usage: gitbook [options] [command]


  Options:

    -v, --gitbook [version]  specify GitBook version to use
    -d, --debug              enable verbose error
    -V, --version            Display running versions of gitbook and gitbook-cli
    -h, --help               output usage information


  Commands:


    ls                        List versions installed locally
    current                   Display currently activated version
    ls-remote                 List remote versions available for install
    fetch [version]           Download and install a <version>
    alias [folder] [version]  Set an alias named <version> pointing to <folder>
    uninstall [version]       Uninstall a version
    update [tag]              Update to the latest version of GitBook
    help                      List commands for GitBook
    *                         run a command with a specific gitbook version
试了试:
~  gitbook serve --help


... Uhoh. Got error listen EADDRINUSE :::35729 ...
Error: listen EADDRINUSE :::35729
    at Server.setupListenHandle [as _listen2] (net.js:1360:14)
    at listenInCluster (net.js:1401:12)
    at Server.listen (net.js:1485:7)
    at Server.listen (/Users/xxx/.gitbook/versions/3.2.3/node_modules/tiny-lr/lib/server.js:164:15)
    at Promise.apply (/Users/xxx/.gitbook/versions/3.2.3/node_modules/q/q.js:1165:26)
    at Promise.promise.promiseDispatch (/Users/xxx/.gitbook/versions/3.2.3/node_modules/q/q.js:788:41)
    at /Users/xxx/.gitbook/versions/3.2.3/node_modules/q/q.js:1391:14
    at runSingle (/Users/xxx/.gitbook/versions/3.2.3/node_modules/q/q.js:137:13)
    at flush (/Users/xxx/.gitbook/versions/3.2.3/node_modules/q/q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)


You already have a server listening on 35729
You should stop it and try again.
发现没法给
gitbook serve
找单独的help语法
Gitbook命令行速览 | gitbook入门教程
gitbook help
就能看到了?
自己也去试试
~  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)
看到我们要的:
    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)
去改为:
# Gitbook Debug Port and LiveReload Port
GITBOOK_DEBUG_PORT ?= 4000
GITBOOK_DEBUG_LRPORT ?= 35729

debug: sync_content clean_debug create_folder_debug
    gitbook serve --port $(GITBOOK_DEBUG_PORT) --lrport $(GITBOOK_DEBUG_LRPORT) $(CURRENT_DIR) $(DEBUG_PATH) $(GITBOOK_COMMON_FLAGS)
去调试看看效果
可以看到log中输出了:
gitbook serve --port 4000 --lrport 35729 /Users/xxx/dev/crifan/gitbook/gitbook_template/books/5g_message_rcs_tech_summary /Users/xxx/dev/crifan/gitbook/gitbook_template/generated/books/5g_message_rcs_tech_summary/debug --log debug
是对的
另外
make debug GITBOOK_DEBUG_PORT=40001 GITBOOK_DEBUG_LRPORT=35730
输出效果:
gitbook serve --port 40001 --lrport 35730 /Users/xxx/dev/crifan/gitbook/gitbook_template/books/rcs_tech_dev_summary /Users/xxx/dev/crifan/gitbook/gitbook_template/generated/books/rcs_tech_dev_summary/debug --log debug
Live reload server started on port: 35730
。。。
Starting server ...
Serving book on http://localhost:40001
然后去打开试试
也是可以的。
然后同时去编辑2个gitbook的代码
看看livereload是否正常工作
后来看到别人都是把serve写到后面,才想起来,是应该先option再command的
  Usage: gitbook [options] [command]
所以改为:
gitbook --port $(GITBOOK_DEBUG_PORT) --lrport $(GITBOOK_DEBUG_LRPORT) serve 
更好。
【总结】
最后相关代码是:
# Gitbook Debug Port and LiveReload Port
GITBOOK_DEBUG_PORT ?= 4000
GITBOOK_DEBUG_LRPORT ?= 35729

## Debug gitbook
debug: sync_content clean_debug create_folder_debug
    gitbook --port $(GITBOOK_DEBUG_PORT) --lrport $(GITBOOK_DEBUG_LRPORT) serve $(CURRENT_DIR) $(DEBUG_PATH) $(GITBOOK_COMMON_FLAGS)
完整代码可以参考:
https://github.com/crifan/gitbook_template
中的:
https://github.com/crifan/gitbook_template/blob/master/common/gitbook_makefile.mk
【后记 20200916】
make debug

make debug GITBOOK_DEBUG_PORT=4001 GITBOOK_DEBUG_LRPORT=35730

make debug GITBOOK_DEBUG_PORT=4002 GITBOOK_DEBUG_LRPORT=35731

make debug GITBOOK_DEBUG_PORT=4003 GITBOOK_DEBUG_LRPORT=35732
即可同时调试多个book。

转载请注明:在路上 » 【已解决】给crifan的gitbook的template添加debug时指定特定端口

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.170 seconds, using 22.15MB memory