Skip to content

Commit 50d6da3

Browse files
authored
Merge pull request #1729 from nikhiljohn10/dev-script
[Improvement] Makefile for Development
2 parents 2f498e1 + b91263f commit 50d6da3

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ node_modules
55
package-lock.json
66
.idea
77
.swp
8+
.langs
9+
.vscode/

Makefile

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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."
35+
@echo " epub - Generate the EPUB version of DjangoGirls tutorial."
36+
@echo " mobi - Generate the MOBI version of DjangoGirls tutorial."
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

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ First fork the [DjangoGirls/tutorial](https://github.com/DjangoGirls/tutorial) r
3232

3333
![Fork button](contributing/images/fork.png)
3434

35+
## CLI for Development
36+
37+
This command line tool use `make` to create development environment. It is optional to use this tool. While building the document, it builds the document for every language. The build process can be limited to any one language using this tool and reduce build time considerbly. Afterwards, the translation to other languages are done from crowdin localization process.
38+
39+
Usage instructions are available though `make help` command.
40+
41+
Try the command `make dev` to start development process.
42+
3543
# Editing chapter content
3644

3745
## Simple changes

0 commit comments

Comments
 (0)