1
+ LANG := en
2
+ LANG_FILE := $(shell test -f .langs && echo .langs || echo LANGS.md)
3
+ LANG_DATA := $(shell grep "$(LANG ) /" $(LANG_FILE ) )
4
+ LANG_NAME := $(shell echo "$(LANG_DATA ) " | sed 's/.* \[\(.* \) \].*/\1/')
5
+
6
+ define ebook_support
7
+ @if which ebook-convert 1> /dev/null; then\
8
+ npx honkit $(1 ) ./ ./djangogirls.$(1 ) ;\
9
+ else\
10
+ echo "Error: ebook-convert is not found";\
11
+ echo " * Follow the guide at https://honkit.netlify.app/ebook";\
12
+ echo " - For Debian/Ubuntu, Try: sudo apt install calibre";\
13
+ echo " - For MacOS, Try: brew install --cask calibre";\
14
+ echo " - For Windows and any other OS, Download from https://github.com/kovidgoyal/calibre/releases";\
15
+ false;\
16
+ fi
17
+ endef
18
+
19
+ help :
20
+ @echo
21
+ @echo " Usage: make command [LANG=<language_short_code>]"
22
+ @echo
23
+ @echo " LANG: Language shortcodes are found in LANGS.md. Default is 'en'(English)."
24
+ @echo " ( Refer $( LANG_FILE) for shortcodes of Languages available. )"
25
+ @echo
26
+ @echo " Commands:"
27
+ @echo " help - Display make command list."
28
+ @echo " dev - Setup the project and start the development server with debugging enabled."
29
+ @echo " check - Check for the root directory for various dependencies."
30
+ @echo " setup - Setup the temporary language and install node dependencies for the development."
31
+ @echo " build - Build the honkit project."
32
+ @echo " build-dev - Build the honkit project with debug log."
33
+ @echo " serve - Start honkit server locally for development."
34
+ @echo " pdf - Generate the PDF version of DjangoGirls tutorial-extensions."
35
+ @echo " epub - Generate the EPUB version of DjangoGirls tutorial-extensions."
36
+ @echo " mobi - Generate the MOBI version of DjangoGirls tutorial-extensions."
37
+ @echo " mode - Shows the development mode status."
38
+ @echo " exit - Exit development mode."
39
+ @echo
40
+ @echo " Example:"
41
+ @echo
42
+ @echo " $$ make dev LANG=es"
43
+ @echo
44
+ @echo " The above command will start the development server using the language Español."
45
+ @echo " 'LANG' argument is only required the first time until the exit command is executed."
46
+ @echo
47
+
48
+ .git/hooks/pre-commit :
49
+ @echo " #!/bin/sh\n\
50
+ \n\
51
+ if test -f \"./.langs\"; then\n\
52
+ echo \"Error : You can't commit without exiting development mode.\\\n\\\n\\\\\
53
+ \nTry the following command to exit development mode :\\\n\\\n\\\\\
54
+ \n$$ make exit\\\n\" 1>&2;\n\
55
+ exit 1\n\
56
+ fi\n" > ./.git/hooks/pre-commit
57
+ @chmod u+x ./.git/hooks/pre-commit
58
+
59
+ node_modules :
60
+ @npm install
61
+
62
+ check : package.json book.json LANGS.md
63
+ @if ! which node 1> /dev/null; then\
64
+ echo " Error: Node.js not found" ; \
65
+ echo " * Please install/reinstall NodeJS on your system." ; \
66
+ echo " * NVM is recommended for installation (https://github.com/nvm-sh/nvm)." ; \
67
+ false ; \
68
+ fi
69
+
70
+ setup : node_modules check .git/hooks/pre-commit
71
+ @if ! test -f " .langs" ; then\
72
+ cp LANGS.md .langs && \
73
+ echo " $( LANG_DATA) " > LANGS.md && \
74
+ echo " You are set to $( LANG_NAME) for development" ; \
75
+ fi
76
+
77
+ build : setup
78
+ @npx honkit build
79
+
80
+ build-dev : setup
81
+ @npx honkit build --log=debug
82
+
83
+ serve : setup
84
+ @npx honkit serve
85
+
86
+ dev : setup
87
+ @npx honkit serve --log=debug
88
+
89
+ mode :
90
+ @if test -f " .langs" ; then\
91
+ echo " You are in development mode using the language $( LANG_NAME) " ; \
92
+ else\
93
+ echo " You are not in development mode" ; \
94
+ fi
95
+
96
+ exit :
97
+ @if test -f " .langs" ; then\
98
+ mv -f .langs LANGS.md && echo " Language file is restored" ; \
99
+ rm -rf node_modules _book .git/hooks/pre-commit && echo " The project exited development mode." ; \
100
+ fi
101
+
102
+ pdf :
103
+ $(call ebook_support,pdf)
104
+
105
+ epub :
106
+ $(call ebook_support,epub)
107
+
108
+ mobi :
109
+ $(call ebook_support,mobi)
110
+
111
+ .PHONY : help check setup build build-dev serve dev pdf epub mobi mode exit
0 commit comments