-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·143 lines (118 loc) · 4.51 KB
/
build.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
set -e
# USAGE:
# - Set PLUGINS_DIR to wherever OpenplanetNext/Plugins lives
# ./build.sh [dev|release]
# Defaults to `dev` build mode.
PLUGINS_DIR=${PLUGINS_DIR:-$HOME/win/OpenplanetNext/Plugins}
# https://greengumdrops.net/index.php/colorize-your-bash-scripts-bash-color-library/
source ./vendor/_colors.bash
_build_mode=${1:-dev}
case $_build_mode in
dev|release|prerelease|unittest)
;;
*)
_colortext16 red "⚠ Error: build mode of '$_build_mode' is not a valid option.\n\tOptions: dev, release.";
exit -1;
;;
esac
_colortext16 yellow "🚩 Build mode: $_build_mode"
pluginSources=( 'src' )
for pluginSrc in ${pluginSources[@]}; do
# if we don't have `dos2unix` below then we need to add `\r` to the `tr -d`
PLUGIN_PRETTY_NAME="$(cat ./info.toml | dos2unix | grep '^name' | cut -f 2 -d '=' | tr -d '\"\r' | sed 's/^[ ]*//')"
PLUGIN_VERSION="$(cat ./info.toml | dos2unix | grep '^version' | cut -f 2 -d '=' | tr -d '\"\r' | sed 's/^[ ]*//')"
echo "$PLUGIN_PRETTY_NAME"
if [[ "$PLUGIN_PRETTY_NAME" == "MLHook & Event Inspector" ]]; then
PLUGIN_PRETTY_NAME="MLHook"
fi
# # prelim stuff
# case $_build_mode in
# dev)
# # we will replicate this in the info.toml file later
# export PLUGIN_PRETTY_NAME="${PLUGIN_PRETTY_NAME:-} (Dev)"
# ;;
# prerelease)
# export PLUGIN_PRETTY_NAME="${PLUGIN_PRETTY_NAME:-} (Prerelease)"
# ;;
# unittest)
# export PLUGIN_PRETTY_NAME="${PLUGIN_PRETTY_NAME:-} (UnitTest)"
# ;;
# *)
# ;;
# esac
echo
_colortext16 green "✅ Building: ${PLUGIN_PRETTY_NAME}"
# remove parens, replace spaces with dashes, and uppercase characters with lowercase ones
# => `Never Give Up (Dev)` becomes `never-give-up-dev`
PLUGIN_NAME=$(echo "$PLUGIN_PRETTY_NAME" | tr -d '(),;&'\''"')
# echo $PLUGIN_NAME
_colortext16 green "✅ Output file/folder name: ${PLUGIN_NAME}"
BUILD_NAME="$PLUGIN_NAME-$(date +%s).zip"
RELEASE_NAME="$PLUGIN_NAME-$PLUGIN_VERSION.op"
PLUGIN_DEV_LOC="$PLUGINS_DIR/$PLUGIN_NAME"
PLUGIN_RELEASE_LOC="$PLUGINS_DIR/$RELEASE_NAME"
function buildPlugin {
7z a "./$BUILD_NAME" "./$pluginSrc/"* ./LICENSE ./README.md
cp -v "$BUILD_NAME" "$RELEASE_NAME"
_colortext16 green "\n✅ Built plugin as ${BUILD_NAME} and copied to ./${RELEASE_NAME}.\n"
}
# this case should set both _copy_exit_code and _build_dest
# common for non-release builds
case $_build_mode in
dev|prerelease|unittest)
# in case it doesn't exist
_build_dest=$PLUGIN_DEV_LOC
mkdir -p "$_build_dest/"
rm -vr "$_build_dest/"* || true
cp -LR -v "./$pluginSrc/"* "$_build_dest/"
# cp -LR -v ./external/* $_build_dest/
cp -LR -v ./info.toml "$_build_dest/"
_copy_exit_code="$?"
;;
esac
case $_build_mode in
dev)
sed -i 's/^\(name[ \t="]*\)\(.*\)"/\1\2 (Dev)"/' $_build_dest/info.toml
sed -i 's/^#__DEFINES__/defines = ["DEV"]/' $_build_dest/info.toml
;;
prerelease)
sed -i 's/^\(name[ \t="]*\)\(.*\)"/\1\2 (Prerelease)"/' $_build_dest/info.toml
sed -i 's/^#__DEFINES__/defines = ["RELEASE"]/' $_build_dest/info.toml
;;
unittest)
sed -i 's/^\(name[ \t="]*\)\(.*\)"/\1\2 (UnitTest)"/' $_build_dest/info.toml
sed -i 's/^#__DEFINES__/defines = ["UNIT_TEST"]/' $_build_dest/info.toml
;;
release)
cp ./info.toml ./$pluginSrc/info.toml
sed -i 's/^#__DEFINES__/defines = ["RELEASE"]/' ./$pluginSrc/info.toml
buildPlugin
rm ./$pluginSrc/info.toml
_build_dest=$PLUGIN_RELEASE_LOC
# cp -v $RELEASE_NAME $_build_dest
# todo: how do we do the release __defines thing?
_copy_exit_code="$?"
;;
*)
_colortext16 red "\n⚠ Error: unknown build mode: $_build_mode"
esac
echo ""
if [[ "$_copy_exit_code" != "0" ]]; then
echo $PLUGIN_PRETTY_NAME
_colortext16 red "⚠ Error: could not copy plugin to Trackmania directory. You might need to click\n\t\`F3 > Scripts > TogglePlugin > PLUGIN\`\nto unlock the file for writing."
_colortext16 red "⚠ Also, \"Stop Recent\" and \"Reload Recent\" should work, too, if the plugin is the \"recent\" plugin."
else
_colortext16 green "✅ Release file: ${RELEASE_NAME}"
fi
# # cleanup
# case $_build_mode in
# dev)
# # remove the build artifact b/c they'll just take up space
# (rm $BUILD_NAME && _colortext16 green "✅ Removed ${BUILD_NAME}") || _colortext16 red "Failed to remove ${BUILD_NAME}."
# ;;
# *)
# ;;
# esac
done
_colortext16 green "✅ Done."