Last active
February 25, 2021 18:48
-
-
Save typeoneerror/13979e43a575e9fa9a122fb7d982c47d to your computer and use it in GitHub Desktop.
Helper for yarn linking PN node modules
This file contains hidden or 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 | |
## | |
# yarn-link-list.sh | |
# | |
# Does the work to rebuild dependencies and add yarn links. | |
# | |
# Displays the list of PN repos linked to the consuming application | |
# | |
# Use: | |
# | |
# `yarn-link-list.sh` | |
PREFIX="@precision-nutrition" | |
PROJECT_PATH=$(pwd) | |
NODE_MODULES="$PROJECT_PATH/node_modules" | |
BLUE="\033[0;34m" | |
RED="\033[0;31m" | |
RESET="\033[00m" | |
## | |
# writeln | |
# | |
# Write a success message in purple. | |
writeln() { | |
echo -e "$BLUE$1$RESET" | |
} | |
## | |
# writeerr | |
# | |
# Write a fail message in red | |
writeerr() { | |
echo -e "$RED$1$RESET" | |
} | |
if [[ ! -f "$PROJECT_PATH/package.json" ]]; then | |
writeerr "This does not appear to be an npm project!" | |
exit | |
fi | |
links=($(ls -l $NODE_MODULES/$PREFIX | grep ^l | sed 's/\(.*\)'$PREFIX'\///')) | |
writeln "The following packages are linked:" | |
for link in "${links[@]}" | |
do | |
echo -e "\t$link" | |
writeerr "\t\tyarn unlink $PREFIX/$link" | |
done |
This file contains hidden or 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 | |
## | |
# yarn-link.sh | |
# | |
# Does the work to rebuild dependencies and add yarn links. | |
# | |
# Nukes node_modules, yarn installs, then creates yarn links. | |
# | |
# Use one of two ways: | |
# | |
# 1. `yarn-link.sh` | |
# | |
# Creates a link to the current module for other modules to consume | |
# | |
# 2. `yarn-link.sh fullscreen-card-renderer render-markdown` | |
# | |
# With params, links the named modules to the current module | |
# | |
# To undo, use `yarn unlink <module-name>` as normal | |
PREFIX="@precision-nutrition" | |
PROJECT_PATH=$(pwd) | |
NODE_MODULES="$PROJECT_PATH/node_modules" | |
BLUE="\033[0;34m" | |
RED="\033[0;31m" | |
RESET="\033[00m" | |
## | |
# writeln | |
# | |
# Write a success message in purple. | |
writeln() { | |
echo -e "$BLUE$1$RESET" | |
} | |
## | |
# writeerr | |
# | |
# Write a fail message in red | |
writeerr() { | |
echo -e "$RED$1$RESET" | |
} | |
if [[ ! -f "$PROJECT_PATH/package.json" ]]; then | |
writeerr "This does not appear to be an npm project!" | |
exit | |
fi | |
argc=$# | |
writeln "Nuking node modules in $NODE_MODULES..." | |
rm -rf $NODE_MODULES | |
writeln "Installing dependencies..." | |
yarn | |
writeln "Linking dependencies..." | |
if [[ $argc != 0 ]]; then | |
for arg in "$@" | |
do | |
module=$PREFIX/$arg | |
writeln "Linking $module..." | |
yarn link "$module" | |
done | |
else | |
yarn link | |
fi | |
writeln "Linked." |
This file contains hidden or 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
curl https://gist.githubusercontent.com/typeoneerror/13979e43a575e9fa9a122fb7d982c47d/raw/bda196663074db24ba204c322604191cddfbeead/yarn-link.sh > /usr/local/bin/yarn-link.sh && chmod +x /usr/local/bin/yarn-link.sh | |
curl https://gist.githubusercontent.com/typeoneerror/13979e43a575e9fa9a122fb7d982c47d/raw/bda196663074db24ba204c322604191cddfbeead/yarn-link-list.sh > /usr/local/bin/yarn-link-list.sh && chmod +x /usr/local/bin/yarn-link-list.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment