forked from source-academy/sicp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo.sh
executable file
·73 lines (61 loc) · 1.89 KB
/
do.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env bash
# hand-paginated index file for LaTeX => PDF
HAND_PAGINATED="hand-paginated.ind"
# DOCS is the local target folder, before deployment
DOCS="docs_out"
# temp folders for different editions
LATEX_PDF="latex_pdf"
GENERATED_HTML="html_split"
GENERATED_JS="js_programs"
GENERATED_JSON="json"
PDF_FILE="sicpjs.pdf"
# RESOURCES
FAVICON="static/assets/sourcepower.ico"
STYLESHEET="static/assets/sourcepower.ico"
FONTS="static/fonts"
CSS="static/css"
IMAGES="static/images"
# NAMES OF GENERATED FILES
OUTPUT_FILE="sicpjs"
ZIP_FILE="sicpjs.zip"
main() {
if [ "$1" == "pdf" ]; then
pdf
elif [ "$1" == "clean" ]; then
clean
elif [ "$1" == "prepare" ]; then
prepare
else
echo "Please run this command from the git root directory."
false # exit 1
fi
}
pdf() {
yarn process pdf; yarn process pdf; \
cd ${LATEX_PDF}; \
cp -f ../mitpress/crop.sty .; \
latexmk -verbose -pdf -r ../scripts/latexmkrc -pdflatex="pdflatex --synctex=1" -f ${OUTPUT_FILE}
}
clean() {
rm -rf ${DOCS}/*
mv ${LATEX_PDF}/${HAND_PAGINATED} .
rm -rf ${LATEX_PDF}/*
mv ${HAND_PAGINATED} ${LATEX_PDF}
rm -rf ${GENERATED_HTML}/*
rm -rf ${GENERATED_JS}/*
rm -rf ${GENERATED_JSON}/*
rm -f ${ZIP_FILE}
}
prepare() {
[ ! -f ${FAVICON} ] || cp ${FAVICON} ${DOCS}/favicon.ico
[ ! -f ${STYLESHEET} ] || cp ${STYLESHEET} ${DOCS}/assets/stylesheet.css
[ ! -f ${LATEX_PDF}/${PDF_FILE} ] || cp ${LATEX_PDF}/${PDF_FILE} ${DOCS}
PDF_BASENAME="$(basename "${PDF_FILE}" .pdf)"
cp "${LATEX_PDF}/${PDF_BASENAME}."{log,ilg,ind,idx} ${DOCS} || :
[ ! -f ${GENERATED_HTML}/index.html ] || cp -rf ${GENERATED_HTML}/* ${DOCS}
[ ! -d ${GENERATED_JS} ] || ( zip -r ${ZIP_FILE} ${GENERATED_JS}; \
cp ${ZIP_FILE} ${DOCS} )
[ ! -d ${GENERATED_JSON} ] || ( rm -rf ${DOCS}/json; \
cp -rf ${GENERATED_JSON} ${DOCS}/json )
}
main $1