2015-08-04 16:29:49 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
# Only GNU getopt supports long options. OS X comes bundled with the BSD getopt
|
|
|
|
|
# brew install gnu-getopt to get the GNU getopt on OS X
|
|
|
|
|
[[ $(uname -s) == "Darwin" ]] && GNU_GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" || GNU_GETOPT="getopt"
|
|
|
|
|
readonly GNU_GETOPT
|
|
|
|
|
|
2018-10-27 10:53:47 -07:00
|
|
|
args=$(${GNU_GETOPT} -o "" -l "output:,version:" -n "$0" -- "$@")
|
2015-08-04 16:29:49 -07:00
|
|
|
eval set -- "${args}"
|
|
|
|
|
|
2016-01-11 18:38:44 +01:00
|
|
|
readonly SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
2015-08-04 16:29:49 -07:00
|
|
|
|
|
|
|
|
bundle_file=""
|
2018-10-27 10:53:47 -07:00
|
|
|
version=""
|
2015-08-04 16:29:49 -07:00
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
case "$1" in
|
2018-10-31 08:41:47 +01:00
|
|
|
--output) bundle_file="$2"; shift 2;;
|
2018-10-27 10:53:47 -07:00
|
|
|
--version) version="$2"; shift 2;;
|
2015-08-04 16:29:49 -07:00
|
|
|
--) break;;
|
|
|
|
|
*) echo "Unknown option $1"; exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2018-10-27 10:53:47 -07:00
|
|
|
if [[ -z "${version}" ]]; then
|
|
|
|
|
echo "--version is required"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2015-08-04 16:29:49 -07:00
|
|
|
readonly TMPDIR=${TMPDIR:-/tmp} # why is this not set on mint?
|
|
|
|
|
|
2016-01-11 18:38:44 +01:00
|
|
|
if ! $(cd "${SOURCE_DIR}" && git diff --exit-code >/dev/null); then
|
2023-02-25 00:00:40 +01:00
|
|
|
echo "You have local changes, stash or commit them to proceed"
|
2015-08-04 16:29:49 -07:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-05-11 08:16:40 +02:00
|
|
|
if [[ "$(node --version)" != "v18.16.0" ]]; then
|
|
|
|
|
echo "This script requires node 18.16.0"
|
2016-01-14 10:55:26 -08:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2018-02-02 19:56:59 -08:00
|
|
|
box_version=$(cd "${SOURCE_DIR}" && git rev-parse "HEAD")
|
2015-08-04 16:29:49 -07:00
|
|
|
bundle_dir=$(mktemp -d -t box 2>/dev/null || mktemp -d box-XXXXXXXXXX --tmpdir=$TMPDIR)
|
2023-02-25 00:00:40 +01:00
|
|
|
[[ -z "$bundle_file" ]] && bundle_file="${TMPDIR}/box-${box_version:0:10}-${box_version:0:10}-${version}.tar.gz"
|
2015-08-04 16:29:49 -07:00
|
|
|
|
|
|
|
|
chmod "o+rx,g+rx" "${bundle_dir}" # otherwise extracted tarball director won't be readable by others/group
|
2023-02-25 00:00:40 +01:00
|
|
|
echo "==> Checking out code box version [${box_version}] into ${bundle_dir}"
|
2018-02-02 19:56:59 -08:00
|
|
|
(cd "${SOURCE_DIR}" && git archive --format=tar ${box_version} | (cd "${bundle_dir}" && tar xf -))
|
2018-10-27 10:53:47 -07:00
|
|
|
echo "${version}" > "${bundle_dir}/VERSION"
|
2015-08-04 16:29:49 -07:00
|
|
|
|
2018-04-09 20:49:55 +02:00
|
|
|
echo "==> Building dashboard assets"
|
2023-09-27 11:21:12 +05:30
|
|
|
(cd "${bundle_dir}/dashboard" && npm ci --omit=dev)
|
2023-02-25 00:00:40 +01:00
|
|
|
(cd "${bundle_dir}/dashboard" && ./node_modules/.bin/gulp --revision ${box_version})
|
2023-02-25 00:38:35 +01:00
|
|
|
rm -rf "${bundle_dir}/dashboard/node_modules"
|
2015-08-04 16:29:49 -07:00
|
|
|
|
2023-07-12 14:22:58 +02:00
|
|
|
echo "==> Building new frontend assets"
|
2023-09-27 11:21:12 +05:30
|
|
|
(cd "${bundle_dir}/frontend" && npm ci)
|
2023-07-12 14:22:58 +02:00
|
|
|
(cd "${bundle_dir}/frontend" && ./node_modules/.bin/vite build --base=/frontend/)
|
|
|
|
|
mv "${bundle_dir}/frontend/dist" "${bundle_dir}/dashboard/dist/frontend"
|
|
|
|
|
rm -rf "${bundle_dir}/frontend"
|
2023-04-16 18:08:58 +02:00
|
|
|
|
2018-04-09 20:49:55 +02:00
|
|
|
echo "==> Installing toplevel node modules"
|
2023-09-27 11:21:12 +05:30
|
|
|
(cd "${bundle_dir}" && npm ci --omit=dev --omit=optional)
|
2015-08-04 16:29:49 -07:00
|
|
|
|
2018-04-09 20:49:55 +02:00
|
|
|
echo "==> Create final tarball"
|
2015-08-04 16:29:49 -07:00
|
|
|
(cd "${bundle_dir}" && tar czf "${bundle_file}" .)
|
2018-04-10 14:05:26 +02:00
|
|
|
|
2018-04-09 20:49:55 +02:00
|
|
|
echo "==> Cleaning up ${bundle_dir}"
|
2015-08-04 16:29:49 -07:00
|
|
|
rm -rf "${bundle_dir}"
|
|
|
|
|
|
2018-04-09 20:49:55 +02:00
|
|
|
echo "==> Tarball saved at ${bundle_file}"
|