|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# This assumes all of the OS-level configuration has been completed and git repo has already been cloned |
| 4 | +# |
| 5 | +# This script should be run from the repo's deployment directory |
| 6 | +# cd deployment |
| 7 | +# ./build-open-source-dist.sh solution-name |
| 8 | +# |
| 9 | +# Parameters: |
| 10 | +# - solution-name: name of the solution for consistency |
| 11 | + |
| 12 | +# Check to see if input has been provided: |
| 13 | +if [ -z "$1" ]; then |
| 14 | + echo "Please provide the trademark approved solution name for the open source package." |
| 15 | + echo "For example: ./build-open-source-dist.sh trademarked-solution-name" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Get reference for all important folders |
| 20 | +source_template_dir="$PWD" |
| 21 | +dist_dir="$source_template_dir/open-source" |
| 22 | +dist_template_dir="$dist_dir/deployment" |
| 23 | +source_dir="$source_template_dir/../source" |
| 24 | + |
| 25 | +echo "------------------------------------------------------------------------------" |
| 26 | +echo "[Init] Clean old open-source folder" |
| 27 | +echo "------------------------------------------------------------------------------" |
| 28 | +rm -rf $dist_dir |
| 29 | +mkdir -p $dist_dir |
| 30 | +mkdir -p $dist_template_dir |
| 31 | + |
| 32 | +echo "------------------------------------------------------------------------------" |
| 33 | +echo "[Packing] Build Script" |
| 34 | +echo "------------------------------------------------------------------------------" |
| 35 | +cp $source_template_dir/build-s3-dist.sh $dist_template_dir |
| 36 | +cp $source_template_dir/run-unit-tests.sh $dist_template_dir |
| 37 | + |
| 38 | +echo "------------------------------------------------------------------------------" |
| 39 | +echo "[Packing] Architecture diagram" |
| 40 | +echo "------------------------------------------------------------------------------" |
| 41 | +cp $source_template_dir/../architecture.png $dist_dir |
| 42 | + |
| 43 | +echo "------------------------------------------------------------------------------" |
| 44 | +echo "[Packing] Source folder and clean up the pacakge" |
| 45 | +echo "------------------------------------------------------------------------------" |
| 46 | +rsync -avq --progress $source_dir $dist_dir --exclude node_modules |
| 47 | +find $dist_dir -iname "dist" -type d -exec rm -rf "{}" \; 2>/dev/null |
| 48 | +find $dist_dir -iname "node_modules" -type d -exec rm -rf "{}" \; 2>/dev/null |
| 49 | +find $dist_dir -iname "coverage" -type d -exec rm -rf "{}" \; 2>/dev/null |
| 50 | +find $dist_dir -type f -name 'package-lock.json' -delete |
| 51 | +find $dist_dir/source/constructs -iname "cdk.out" -type d -exec rm -rf "{}" \; 2>/dev/null |
| 52 | +find $dist_dir -type f -name '.DS_Store' -delete |
| 53 | + |
| 54 | +echo "------------------------------------------------------------------------------" |
| 55 | +echo "Removing unit test coverage files used by SonarQube" |
| 56 | +echo "------------------------------------------------------------------------------" |
| 57 | +rm -rf $dist_dir/source/test |
| 58 | + |
| 59 | +echo "------------------------------------------------------------------------------" |
| 60 | +echo "[Packing] Root files" |
| 61 | +echo "------------------------------------------------------------------------------" |
| 62 | +cp $source_template_dir/../LICENSE.txt $dist_dir |
| 63 | +cp $source_template_dir/../NOTICE.txt $dist_dir |
| 64 | +cp $source_template_dir/../README.md $dist_dir |
| 65 | +cp $source_template_dir/../CODE_OF_CONDUCT.md $dist_dir |
| 66 | +cp $source_template_dir/../CONTRIBUTING.md $dist_dir |
| 67 | +cp $source_template_dir/../CHANGELOG.md $dist_dir |
| 68 | +cp $source_template_dir/../.gitignore $dist_dir |
| 69 | +cp -r $source_template_dir/../.github $dist_dir |
| 70 | + |
| 71 | +echo "------------------------------------------------------------------------------" |
| 72 | +echo "Creating GitHub (open-source) zip file" |
| 73 | +echo "------------------------------------------------------------------------------" |
| 74 | +cd $dist_dir |
| 75 | +zip -q -r9 ../$1.zip * .github .gitignore |
| 76 | +rm -rf * .github .gitignore |
| 77 | +mv ../$1.zip . |
| 78 | +echo "Completed building $1.zip" |
0 commit comments