-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Description
This script verifies all the dependencies and installs all of them except the node environment. It also creates language isolation for fast build and server reload. It is compatible with all languages found inside the LANGS.md file. It can also reset the LANGS.md file after the development process to deploy or commit.
Structure
File Name: dev.sh (or dev)
Permission: -rwxr--r-- (744)
Location: Project root directory
Command: ./dev.sh [options] [language]
Options:
| Option | Parameter | Description |
|---|---|---|
| -h | Display usage and options. | |
| -l | Language short form from LANGS.md (en, es, fr, de, pl etc) | Set the temporary language for development. Default is 'en'. |
| -r | Reset the Language file to its original state. |
Script
#!/usr/bin/env bash
HONKIT_LANG=en
help() {
cat <<EOF
Usage: ./dev.sh [options]
Options:
-h : Display usage and options.
-l <es> : Set the temporary language for development. Default is 'en'.
-r : Reset the Language file to its original state.
EOF
}
reset_dev() {
unset HONKIT_LANG
unset -f help __reset_language __set_language serve __first_run main
}
__reset_language() {
if [ -f "LANGS.md.bak" ]; then
mv -f LANGS.md.bak LANGS.md && echo "Language file is reset"
else
echo "Language file backup is not found."
fi
}
__set_language() {
cp LANGS.md{,.bak} && echo "Language file backup is created."
HONKIT_LANG_NAME=$(grep "$HONKIT_LANG/" LANGS.md.bak | sed 's/.*\[\(.*\)\].*/\1/')
grep "$HONKIT_LANG/" LANGS.md.bak 1> LANGS.md && echo "Language list is reduced to $HONKIT_LANG_NAME for development"
echo "NOTE: You shold not commit 'LANGS.md.bak' in git. You can use './dev.sh -r' to reset the LANGS.md file."
}
__first_run() {
# Using 'LANGS.md.bak' as a marker to identify first time execution/reset condition
if [ ! -f "LANGS.md.bak" ]; then
if which node > /dev/null && which npx > /dev/null; then
__set_language
else
echo "Node.js/npx is not found. Try installing/reinstall Node.js(LTS) using nvm. (https://github.com/nvm-sh/nvm)"
exit 1
fi
fi
}
serve() {
npx honkit serve
if [[ $? == "1" ]]; then
npm install
npx honkit serve
fi
}
main() {
if [[ $1 == "-h" ]]; then
help
exit 0
elif [[ $1 == "-r" ]]; then
__reset_language
exit 0
elif [[ $1 == "-l" ]]; then
HONKIT_LANG=$2
__reset_language
fi
__first_run
serve
}
main "$@"Metadata
Metadata
Assignees
Labels
No labels