22set -e
33
44DOCSIFY_SERVE_PATH=" /usr/local/bin/docsify-serve"
5+ DOCSIFY_FALLBACK_PATH=" /usr/local/share/docsify-serve/fallback"
56
67DOCS_PATH=${DOCS_PATH:- docs}
78
89echo " Activating feature 'docsify-cli'..."
910
1011npm install -g docsify-cli
1112
12- # The fallback/default index.html file to use when the documents directory does
13- # not exist.
14- DEFAULT_INDEX_HTML=$( cat << EOF
15- <!DOCTYPE html>
16- <html lang="en">
17- <head>
18- <meta charset="UTF-8">
19- <title>Fake Site</title>
20- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
21- <meta name="description" content="Description">
22- <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
23- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
24- </head>
25- <body>
26- <div id="app"></div>
27- <script>
28- window.$docsify = {
29- name: 'fakesite',
30- repo: 'fakerepo'
31- }
32- </script>
33- <!-- Docsify v4 -->
34- <script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
35- </body>
36- </html>
37- EOF
38- )
39-
40- # The fallback/default README.md file to use when the documents directory does
41- # not exist.
42- DEFAULT_README_MD=$( cat << EOF
43- # Fake Site
13+ mkdir -p " ${DOCSIFY_FALLBACK_PATH} "
14+ cp fallback/index.html fallback/README.md " ${DOCSIFY_FALLBACK_PATH} "
4415
45- > An awesome fake site test.
46- EOF
47- )
48-
49- tee " ${DOCSIFY_SERVE_PATH} " > /dev/null \
50- << EOF
51- #!/usr/bin/env sh
16+ cat << EOF >"${DOCSIFY_SERVE_PATH} "
17+ #!/usr/bin/env bash
5218
5319# we need to explicitly "activate" (the current) node here, as otherwise
5420# devcontainers using our feature and also setting their remoteEnv PATH will
@@ -58,17 +24,23 @@ nvm use node
5824
5925mkdir -p "${DOCS_PATH} "
6026if [ ! -f "${DOCS_PATH} /index.html" ]; then
61- echo "${DEFAULT_INDEX_HTML} " > "${DOCS_PATH} /index.html"
62- echo "${DEFAULT_README_MD} " > "${DOCS_PATH} /README.md"
27+ cp ${DOCSIFY_FALLBACK_PATH} /* "${DOCS_PATH} "
6328fi
6429
65- nohup bash -c "\
30+ # since this script is going to be executed as this feature's
31+ # "postStartCommand" there is an important catch here: it is run via
32+ # "docker exec -it ...". Please notice the absence of "-d" as this is a
33+ # synchronous operation. Just using "nohup" as shown in several cases is
34+ # a bad idea: when postStartCommand finishes, it tears down the nohup.
35+ # Thus, use setsid(1) (https://man7.org/linux/man-pages/man1/setsid.1.html)
36+ # to run the docsify serve node process in a new session.
37+ setsid --fork bash -c "\
6638 docsify serve \
6739 -p=${PORT} \
6840 -P=${LIVERELOAD_PORT} \
6941 --no-open \
7042 ${DOCS_PATH} \
71- &" >/tmp/nohup-docsify.log 2>&1
43+ >/tmp/nohup-docsify.log 2>&1"
7244EOF
7345
7446chmod 0755 " ${DOCSIFY_SERVE_PATH} "
0 commit comments