|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +PLATFORM=${PLATFORM:-'linux'} |
| 5 | +ARCH=${ARCH:-'x64'} |
| 6 | +LIBC=${LIBC:-''} |
| 7 | +#FILENAME="Redis-Insight-$PLATFORM.$VERSION.$ARCH.zip" |
| 8 | +FILENAME="Redis-Insight-web-$PLATFORM" |
| 9 | +if [ ! -z $LIBC ] |
| 10 | +then |
| 11 | + FILENAME="$FILENAME-$LIBC.$ARCH.tar.gz" |
| 12 | + export npm_config_target_libc="$LIBC" |
| 13 | +else |
| 14 | + FILENAME="$FILENAME.$ARCH.tar.gz" |
| 15 | +fi |
| 16 | + |
| 17 | +echo "Building node modules..." |
| 18 | +echo "Platform: $PLATFORM" |
| 19 | +echo "Arch: $ARCH" |
| 20 | +echo "Libc: $LIBC" |
| 21 | +echo "npm target libc: $npm_config_target_libc" |
| 22 | +echo "Filname: $FILENAME" |
| 23 | + |
| 24 | +rm -rf redisinsight/api/node_modules |
| 25 | + |
| 26 | +npm_config_arch="$ARCH" \ |
| 27 | +npm_config_target_arch="$ARCH" \ |
| 28 | +npm_config_platform="$PLATFORM" \ |
| 29 | +npm_config_target_platform="$PLATFORM" \ |
| 30 | +yarn --cwd ./redisinsight/api install --production |
| 31 | + |
| 32 | +cp redisinsight/api/.yarnclean.prod redisinsight/api/.yarnclean |
| 33 | +yarn --cwd ./redisinsight/api autoclean --force |
| 34 | + |
| 35 | +rm -rf redisinsight/build.zip |
| 36 | + |
| 37 | +cp LICENSE ./redisinsight |
| 38 | + |
| 39 | +cd redisinsight && tar -czf build.tar.gz \ |
| 40 | +--exclude="api/node_modules/**/build/node_gyp_bins/python3" \ |
| 41 | +api/node_modules \ |
| 42 | +api/dist \ |
| 43 | +ui/dist \ |
| 44 | +LICENSE \ |
| 45 | +&& cd .. |
| 46 | + |
| 47 | +mkdir -p release/web |
| 48 | +cp redisinsight/build.tar.gz release/web/"$FILENAME" |
| 49 | + |
| 50 | +# Minify build via esbuild |
| 51 | +echo "Start minifing workflow" |
| 52 | +npm_config_arch="$ARCH" \ |
| 53 | +npm_config_target_arch="$ARCH" \ |
| 54 | +npm_config_platform="$PLATFORM" \ |
| 55 | +npm_config_target_platform="$PLATFORM" \ |
| 56 | +yarn --cwd ./redisinsight/api install |
| 57 | +yarn --cwd ./redisinsight/api minify:prod |
| 58 | + |
| 59 | + |
| 60 | +PACKAGE_JSON_PATH="./redisinsight/api/package.json" |
| 61 | +APP_PACKAGE_JSON_PATH="./redisinsight/package.json" |
| 62 | + |
| 63 | +# Extract dependencies from the app package.json |
| 64 | +BINARY_PACKAGES=$(jq -r '.dependencies | keys[]' "$APP_PACKAGE_JSON_PATH" | jq -R -s -c 'split("\n")[:-1]') |
| 65 | + |
| 66 | +echo "Binary packages to exclude during minify: $BINARY_PACKAGES" |
| 67 | + |
| 68 | +# Modify the package.json |
| 69 | +jq --argjson keep "$BINARY_PACKAGES" \ |
| 70 | + 'del(.devDependencies) | .dependencies |= with_entries(select(.key as $k | $keep | index($k)))' \ |
| 71 | + "$PACKAGE_JSON_PATH" > temp.json && mv temp.json "$PACKAGE_JSON_PATH" |
| 72 | + |
| 73 | +npm_config_arch="$ARCH" \ |
| 74 | +npm_config_target_arch="$ARCH" \ |
| 75 | +npm_config_platform="$PLATFORM" \ |
| 76 | +npm_config_target_platform="$PLATFORM" \ |
| 77 | +yarn --cwd ./redisinsight/api install --production |
| 78 | +yarn --cwd ./redisinsight/api autoclean --force |
| 79 | + |
| 80 | +# Compress minified build |
| 81 | +cd redisinsight && tar -czf build-mini.tar.gz \ |
| 82 | +--exclude="api/node_modules/**/build/node_gyp_bins/python3" \ |
| 83 | +api/node_modules \ |
| 84 | +api/dist-minified \ |
| 85 | +ui/dist \ |
| 86 | +LICENSE \ |
| 87 | +&& cd .. |
| 88 | + |
| 89 | +mkdir -p release/web-mini |
| 90 | +cp redisinsight/build-mini.tar.gz release/web-mini/"$FILENAME" |
| 91 | + |
| 92 | +# Restore the original package.json and yarn.lock |
| 93 | +git restore redisinsight/api/yarn.lock redisinsight/api/package.json |
| 94 | + |
0 commit comments