Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions bundle-size/pm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Check if command argument is provided
if [ "$1" = "" ]; then
echo "Please provide a command to run."
exit 1
echo "Please provide a command to run."
exit 1
fi

install_pnpm_if_not_present() {
Expand All @@ -15,31 +15,38 @@ install_pnpm_if_not_present() {
}

# Detect the package manager
current_dir=$(pwd)
cd $(git rev-parse --show-toplevel) # Navigate to the root of the git repository
if [ -f yarn.lock ]; then
pm="yarn"
pm="yarn"
elif [ -f package-lock.json ]; then
pm="npm"
pm="npm"
elif [ -f pnpm-lock.yaml ]; then
install_pnpm_if_not_present
pm="pnpm"
else
echo "Defaulting to pnpm for install command."
install_pnpm_if_not_present
pm="pnpm"
echo "No recognized package manager found in this project."
exit 1
fi
cd $current_dir # Navigate back to the original directory

# Detect the command to run build
if [ -f yarn.lock ]; then
pmb=("yarn" "build" "--profile" "--json" "pr-stats.json")
elif [ -f package-lock.json ]; then
pmb=("npm" "run" "build" "--" "--profile" "--json" "pr-stats.json")
if [ "$pm" = "yarn" ]; then
pmb=("yarn" "build" "--profile" "--json" "pr-stats.json")
elif [ "$pm" = "npm" ]; then
pmb=("npm" "run" "build" "--" "--profile" "--json" "pr-stats.json")
elif [ "$pm" = "pnpm" ]; then
install_pnpm_if_not_present
pmb=("pnpm" "build" "--profile" "--json" "pr-stats.json")
else
echo "Defaulting to pnpm for build command."
install_pnpm_if_not_present
pmb=("pnpm" "build" "--profile" "--json" "pr-stats.json")
echo "No recognized package manager found in this project."
exit 1
fi

# Run the provided command with the detected package manager
echo "Running '$1' with $pm..."
if [ "$1" = "install" ]; then
"$pm" install
"$pm" install
elif [ "$1" = "build" ]; then
"${pmb[@]}"
fi
"${pmb[@]}"
fi