Created
September 2, 2022 11:55
-
-
Save J4n1X/aa721134f2ea9ba39cf07bfba2a0dc29 to your computer and use it in GitHub Desktop.
Creates a new Haxe project from the suggested template, including some bonuses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
MAIN_HX="class Main { | |
static function main() { | |
trace(\"Haxe is great!\"); | |
} | |
}" | |
NODE_CONFIG="-lib hxnodejs | |
-cp src | |
-main Main | |
-js bin/js/main.js" | |
CS_CONFIG="-cp src | |
-main Main | |
-cs bin/cs" | |
JAVA_CONFIG="-cp src | |
-main Main | |
-java bin/java" | |
PY_CONFIG="-cp src | |
-main Main | |
-python bin/python/main.py" | |
PHP_CONFIG="-cp src | |
-main Main | |
-php bin/php" | |
JS_CONFIG="-cp src | |
-main Main | |
-js bin/js/main.js" | |
JS_INDEX_HTML="<!DOCTYPE html> | |
<html lang=\"en\"> | |
<head> | |
<meta charset=\"utf-8\"> | |
<title></title> | |
</head> | |
<body> | |
<script src=\"main.js\"></script> | |
</body> | |
</html>" | |
if [ -z $1 ]; then | |
echo "Please specify the directory where to create the project!" | |
exit 1 | |
elif [ ! -d $1 ]; then | |
echo "$1 is not a directory!" | |
exit 1 | |
fi | |
if [ -z $2 ]; then | |
echo "Please specify the name of the project!" | |
exit 1 | |
fi | |
if [ -z $3 ]; then | |
echo "Please specify the target code (Example: Javascript -> js)" | |
exit 1 | |
fi | |
TARGET_CONF="" | |
BIN_DIR="" | |
TARGET_LIB="" | |
case $3 in | |
"nodejs") | |
TARGET_CONF=$NODE_CONFIG | |
TARGET_LIB="hxnodejs" | |
BIN_DIR="js" | |
;; | |
"cs") | |
TARGET_CONF=$CS_CONFIG | |
TARGET_LIB="hxcs" | |
BIN_DIR="cs" | |
;; | |
"java") | |
TARGET_CONF=$JAVA_CONFIG | |
TARGET_LIB="hxjava" | |
BIN_DIR="java" | |
;; | |
"py") | |
TARGET_CONF=$PY_CONFIG | |
BIN_DIR="python" | |
;; | |
"php") | |
TARGET_CONF=$PHP_CONFIG | |
BIN_DIR="php" | |
;; | |
"js") | |
TARGET_CONF=$JS_CONFIG | |
BIN_DIR="js" | |
;; | |
*) | |
echo "Invalid target specified! Valid targets are: nodejs, cs, java, py, php, js" | |
exit 1 | |
esac | |
if [ "$TARGET_LIB" != "" ]; then | |
if [ -z "$(haxelib list | grep $TARGET_LIB)" ]; then | |
echo "Library $TARGET_LIB is not installed. Please install it with \"haxelib install $TARGET_LIB\"" | |
exit 1 | |
fi | |
fi | |
mkdir -p $1/$2/src $1/$2/bin/$BIN_DIR | |
if [ $3 = "js" ]; then | |
# provide index.html and a python webserver launcher | |
echo -n "$JS_INDEX_HTML" > $1/$2/bin/$BIN_DIR/index.html | |
echo -n "#!/bin/bash | |
pushd ./bin/$BIN_DIR; python3 -m http.server 8000; popd" > $1/$2/httpServer.sh | |
fi | |
echo -n "$MAIN_HX" > $1/$2/src/Main.hx | |
echo -n "$TARGET_CONF" > $1/$2/build.hxml | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment