Mirrored from GitHub
github.com/roostorg/coop
1#!/bin/bash
2
3# Script to publish packages to @roostorg npm registry
4# Make sure you're logged into npm with proper permissions
5
6set -e
7
8echo "🚀 Publishing packages to @roostorg scope..."
9
10# Check if user is logged in to npm
11if ! npm whoami > /dev/null 2>&1; then
12 echo "❌ Not logged in to npm. Please run:"
13 echo " npm login"
14 echo " Use your npm username and password/token"
15 exit 1
16fi
17
18echo "✅ Logged in to npm as: $(npm whoami)"
19
20# Check if OTP is provided
21if [ -z "$NPM_OTP" ]; then
22 echo "⚠️ Two-factor authentication is enabled. Please provide OTP:"
23 echo " export NPM_OTP=<your-otp-code>"
24 echo " ./scripts/publish-packages.sh"
25 echo ""
26 echo "Or run with OTP directly:"
27 echo " NPM_OTP=<your-otp-code> ./scripts/publish-packages.sh"
28 exit 1
29fi
30
31# Function to check if package version exists
32check_version_exists() {
33 local package_name=$1
34 local version=$2
35
36 if npm view "$package_name@$version" version >/dev/null 2>&1; then
37 echo "⚠️ Version $version of $package_name already exists on npm"
38 return 0
39 else
40 echo "✅ Version $version of $package_name is available for publishing"
41 return 1
42 fi
43}
44
45# Function to publish package if version doesn't exist
46publish_if_needed() {
47 local package_dir=$1
48
49 cd "$package_dir"
50
51 # Derive name and version from package.json so the script stays in sync
52 # with whatever npm publish will actually publish (avoids drift if the
53 # package is renamed without updating this script).
54 # Declare and assign separately so `set -e` catches node -p failures
55 # (shellcheck SC2155: `local foo=$(...)` masks the subshell's exit status).
56 local package_name
57 package_name=$(node -p "require('./package.json').name")
58 local version
59 version=$(node -p "require('./package.json').version")
60
61 echo "📦 Checking $package_name@$version..."
62
63 if check_version_exists "$package_name" "$version"; then
64 echo "⏭️ Skipping $package_name@$version (already published)"
65 cd ..
66 return
67 fi
68
69 echo "📦 Publishing $package_name@$version..."
70 npm install
71 npm run build
72 npm publish --otp=$NPM_OTP
73 cd ..
74}
75
76# Publish packages
77publish_if_needed "types"
78publish_if_needed "migrator"
79
80echo "✅ All packages published successfully!"
81echo ""
82echo "Next steps:"
83echo "1. Run 'npm install' in server/ and client/ directories to update dependencies"
84echo "2. The GitHub Action will automatically publish future changes when you push to main/OSS branches"