11#! /bin/bash
22# This script builds and publishes all packages in the workspace
33
4- # cd to git root
5- git_root=$( git rev-parse --show-toplevel)
6- cd " $git_root " || exit 1
4+ # Parse command line arguments
5+ DRY_RUN=false
6+
7+ show_help () {
8+ cat << EOF
9+ Usage: $0 [OPTIONS]
10+
11+ Builds and publishes all packages in the workspace.
12+
13+ OPTIONS:
14+ --dry-run, -n Build packages and show what would be published without actually publishing
15+ --help, -h Show this help message
16+
17+ EXAMPLES:
18+ $0 # Build and publish all packages
19+ $0 --dry-run # Build packages and show what would be published
20+ $0 -n # Same as --dry-run
21+ EOF
22+ }
23+
24+ while [[ $# -gt 0 ]]; do
25+ case $1 in
26+ --dry-run|-n)
27+ DRY_RUN=true
28+ shift
29+ ;;
30+ --help|-h)
31+ show_help
32+ exit 0
33+ ;;
34+ * )
35+ echo " Unknown option: $1 "
36+ show_help
37+ exit 1
38+ ;;
39+ esac
40+ done
741
842# Colors for output
943RED=' \033[0;31m'
1044GREEN=' \033[0;32m'
1145YELLOW=' \033[1;33m'
46+ PURPLE=' \033[0;35m'
1247NC=' \033[0m' # No Color
1348
49+ # cd to git root
50+ git_root=$( git rev-parse --show-toplevel)
51+ cd " $git_root " || exit 1
52+
53+
1454get_package_dirs () {
15- # Get all package directories that contain package.json files
16- find packages -name " package.json" -exec dirname {} \; | sort
55+ # Get specific package directories (core, v5, v6, v7)
56+ for dir in packages/core packages/v5 packages/v6 packages/v7; do
57+ if [[ -f " $dir /package.json" ]]; then
58+ echo " $dir "
59+ fi
60+ done | sort
1761}
1862
1963get_package_info () {
@@ -77,15 +121,22 @@ publish_package() {
77121}
78122
79123main () {
80- echo -e " ${YELLOW} 🚀 Starting package publishing process...${NC} "
124+ echo -e " ${YELLOW} Starting package publishing process...${NC} "
81125 echo " "
82126
127+ # print dry run status
128+ if [[ " $DRY_RUN " == " true" ]]; then
129+ echo -e " ${PURPLE} *** Dry-run mode, no packages will be published${NC} "
130+ echo " "
131+ fi
132+
83133 # Check authentication
84134 check_npm_auth
85135 echo " "
86136
87- # Build all packages
88- build_all
137+ echo -e " ${YELLOW} Building all packages...${NC} "
138+ # Build all packages (quietly)
139+ build_all > /dev/null 2>&1
89140 echo " "
90141
91142 # Get all packages to publish
@@ -119,7 +170,11 @@ main() {
119170 fi
120171
121172 echo " "
122- echo -e " ${YELLOW} Publishing ${# publishable_packages[@]} packages...${NC} "
173+ if [[ " $DRY_RUN " == " true" ]]; then
174+ echo -e " ${PURPLE} [DRY-RUN] Publishing ${# publishable_packages[@]} packages...${NC} "
175+ else
176+ echo -e " ${YELLOW} Publishing ${# publishable_packages[@]} packages...${NC} "
177+ fi
123178 echo " "
124179
125180 # Publish each package
@@ -129,21 +184,29 @@ main() {
129184 for package_info in " ${publishable_packages[@]} " ; do
130185 IFS=' |' read -r package_dir name version <<< " $package_info"
131186
132- if publish_package " $package_dir " " $name " " $version " ; then
187+ if [[ " $DRY_RUN " == " true" ]]; then
188+ echo -e " ${PURPLE} [DRY-RUN] Would publish $name @$version ${NC} "
133189 (( published_count++ ))
134190 else
135- (( failed_count++ ))
191+ if publish_package " $package_dir " " $name " " $version " ; then
192+ (( published_count++ ))
193+ else
194+ (( failed_count++ ))
195+ fi
136196 fi
137197 done
138198
139199 echo " "
140- echo -e " ${GREEN} 📊 Publishing Summary:${NC} "
141- echo " ✅ Successfully published: $published_count "
142- if [[ $failed_count -gt 0 ]]; then
143- echo " ❌ Failed: $failed_count "
144- exit 1
200+ echo -e " ${YELLOW} Done:${NC} "
201+ if [[ " $DRY_RUN " == " true" ]]; then
202+ echo -e " ${PURPLE} [DRY-RUN] No packages were actually published${NC} "
145203 else
146- echo -e " ${GREEN} 🎉 All packages published successfully!${NC} "
204+ if [[ $failed_count -gt 0 ]]; then
205+ echo -e " ${RED} ✗ Failed: $failed_count ${NC} "
206+ exit 1
207+ else
208+ echo -e " ${GREEN} ✓ Successfully published: $published_count ${NC} "
209+ fi
147210 fi
148211}
149212
0 commit comments