|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# This script updates a dependency in all examples that are using pnpm. |
| 3 | +# This script updates the turbo dependency in all examples that are using any package manager. |
4 | 4 |
|
5 |
| -# Usage: ./scripts/update-examples-dep.sh <package> <version> |
6 |
| -# Example: ./scripts/update-examples-dep.sh typescript |
| 5 | +# Usage: ./scripts/update-examples-dep.sh |
| 6 | +# Example: ./scripts/update-examples-dep.sh |
7 | 7 |
|
8 | 8 | set -e
|
9 | 9 |
|
10 | 10 | # Change directory to the script's directory
|
11 | 11 | cd "$(dirname "$0")"
|
12 | 12 |
|
13 |
| -package="$1" |
14 |
| -version=${2:-latest} |
| 13 | +package="turbo" |
15 | 14 |
|
16 |
| -echo "Upgrading $package to $version in all examples..." |
| 15 | +# Fetch the latest version of the package from npm |
| 16 | +latest_version=$(npm show $package version) |
17 | 17 |
|
18 |
| -# Get the list of top-level directories |
19 |
| -examples=$(find ../examples -depth 1 -type d) |
20 |
| -lock="pnpm-lock.yaml" |
| 18 | +echo "Upgrading $package to version $latest_version in all examples..." |
21 | 19 |
|
22 |
| -for dir in $examples; do |
23 |
| - if [ "$dir" != "." ]; then |
| 20 | +# Get the list of example directories |
| 21 | +examples="../examples" |
| 22 | + |
| 23 | +for dir in "$examples"/*; do |
| 24 | + if [ -d "$dir" ]; then |
24 | 25 | cd "$dir"
|
25 | 26 | example=$(basename "$(pwd)")
|
26 | 27 | echo $example
|
27 |
| - if [ -e "$lock" ]; then |
28 |
| - echo "• Updating all workspaces to $package@$version" |
29 |
| - # pnpm upgrade $package@latest -r |
30 |
| - pnpm install |
| 28 | + if [ -e "pnpm-lock.yaml" ]; then |
| 29 | + echo "• Updating to $package@$latest_version using pnpm" |
| 30 | + pnpm up $package@$latest_version 2>&1 >/dev/null |
| 31 | + elif [ -e ".yarn" ]; then |
| 32 | + echo "• Updating to $package@$latest_version using yarn" |
| 33 | + yarn add $package@$latest_version 2>&1 >/dev/null |
| 34 | + elif [ -e "yarn.lock" ]; then |
| 35 | + echo "• Updating to $package@$latest_version using yarn" |
| 36 | + yarn upgrade $package@$latest_version --ignore-workspace-root-check 2>&1 >/dev/null |
| 37 | + elif [ -e "package-lock.json" ]; then |
| 38 | + echo "• Updating to $package@$latest_version using npm" |
| 39 | + npm install $package@$latest_version 2>&1 >/dev/null |
31 | 40 | else
|
32 |
| - # yarn doesn't have a nice recursive upgrade command, so we do those manually for now |
33 |
| - echo "• Not using pnpm - skipping." |
| 41 | + echo "• No recognized package manager - skipping." |
34 | 42 | fi
|
35 |
| - cd - > /dev/null |
| 43 | + cd - >/dev/null |
36 | 44 | echo ""
|
37 | 45 | fi
|
38 | 46 | done
|
0 commit comments