Last active
August 9, 2023 21:14
-
-
Save noahwc/d4fcd73e7a989b2189b8cdf2d7c3ad0b to your computer and use it in GitHub Desktop.
Multi Layer Package Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
Help() | |
{ | |
# Display Help | |
echo "This script is intended to improve the development experience of packages with multiple layers of dependencies that are built locally" | |
echo "All upstream packages must have valid "build" scripts" | |
echo "Usage: ./multi-layer-link.sh A B C" | |
echo "Result: In the case above of A -> B -> C the script will build A, install A downstream to B, build B, install B downstream to C" | |
echo "Note: Performance is heavily dependent of the build times of upstream packages, try to use a performant build tool like vite on upstream packages" | |
} | |
while getopts ":h" opt; do | |
case $opt in | |
h) | |
Help | |
exit; | |
esac | |
done | |
if [[ $# -lt 2 ]] | |
then | |
echo Invalid number of arguments | |
exit 1 | |
fi | |
prev_tarball="" | |
for path in $@ | |
do | |
cd "$path" || { echo "$path" not found ; exit 1 ; } | |
if [[ $prev_tarball != "" ]] | |
then | |
echo Installing "$prev_tarball" to "$path" | |
npm i --silent "$prev_tarball" &>/dev/null || echo An error occurred while installing "$prev_tarball" to "$path" | |
echo Install complete | |
fi | |
if [[ $path != "${*: -1:1}" ]] | |
then | |
echo Building "$path" | |
npm run --quiet build &>/dev/null || echo "A build error occurred" | |
prev_tarball="$path"/"$(npm pack --quiet | tail -1)" | |
echo Built "$prev_tarball" | |
fi | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment