/
create-package-archives.sh
executable file
路37 lines (28 loc) 路 1.26 KB
/
create-package-archives.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
#!/usr/bin/env bash
set -eu -o pipefail
readonly prNumber="$1"
readonly prLastSha="${2:0:7}"
readonly inputDir="$PROJECT_ROOT/$3"
readonly outputDir="$PROJECT_ROOT/$4"
readonly fileSuffix="-pr$prNumber-$prLastSha.tgz"
echo "Creating compressed archives for packages in '$inputDir'."
# Create or clean-up the output directory.
echo " Preparing output directory: $outputDir"
rm -rf "$outputDir"
mkdir -p "$outputDir"
# Create a compressed archive containing all packages.
# (This is useful for copying all packages into `node_modules/` (without changing `package.json`).)
outputFileName=all$fileSuffix
echo " Creating archive with all packages --> '$outputFileName'..."
tar --create --gzip --directory "$inputDir" --file "$outputDir/$outputFileName" --transform s/^\./packages/ .
# Create a compressed archive for each package.
# (This is useful for referencing the path/URL to the resulting archive in `package.json`.)
for dir in $inputDir/*
do
packageName=`basename "$dir"`
outputFileName="$packageName$fileSuffix"
outputFilePath="$outputDir/$outputFileName"
echo " Processing package '$packageName' --> '$outputFileName'..."
tar --create --gzip --directory "$dir" --file "$outputFilePath" --transform s/^\./package/ .
done
echo "Done creating compressed archives."