-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·165 lines (134 loc) · 4.91 KB
/
sync.sh
File metadata and controls
executable file
·165 lines (134 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
################################################################################
# ONE Platform Documentation Sync Script
#
# This script syncs all documentation sources from their upstream repositories.
# Run this periodically to keep documentation up to date.
#
# Usage:
# ./sync.sh # Sync all sources
# ./sync.sh --dry-run # Preview changes without applying
#
################################################################################
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
DOCS_ROOT="/Users/toc/Server/ONE/docs"
LOG_FILE="$DOCS_ROOT/sync.log"
DRY_RUN=false
# Parse arguments
if [[ "$1" == "--dry-run" ]]; then
DRY_RUN=true
echo -e "${YELLOW}DRY RUN MODE - No changes will be applied${NC}"
fi
# Function to print section header
print_header() {
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
}
# Function to sync a repository
sync_repo() {
local repo_name="$1"
local repo_path="$2"
local branch="${3:-main}"
print_header "Syncing $repo_name"
if [[ ! -d "$repo_path" ]]; then
echo -e "${RED}✗ Repository not found: $repo_path${NC}"
return 1
fi
cd "$repo_path"
# Show current status
echo -e "${YELLOW}Repository:${NC} $repo_name"
echo -e "${YELLOW}Path:${NC} $repo_path"
echo -e "${YELLOW}Remote:${NC} $(git remote get-url origin)"
# Stash any local changes
if git diff --quiet && git diff --cached --quiet; then
echo -e "${GREEN}✓ Working directory clean${NC}"
else
echo -e "${YELLOW}⚠ Local changes detected, stashing...${NC}"
if [[ "$DRY_RUN" == false ]]; then
git stash push -m "Auto-stash before sync $(date +%Y%m%d-%H%M%S)"
fi
fi
# Fetch latest changes
echo -e "${YELLOW}Fetching latest changes...${NC}"
if [[ "$DRY_RUN" == false ]]; then
git fetch origin "$branch"
fi
# Show what would change
local commits_behind=$(git rev-list --count HEAD..origin/"$branch" 2>/dev/null || echo "0")
if [[ "$commits_behind" -gt 0 ]]; then
echo -e "${YELLOW}⚠ $commits_behind commits behind upstream${NC}"
echo -e "${YELLOW}Changes:${NC}"
git log --oneline HEAD..origin/"$branch" | head -5
if [[ "$DRY_RUN" == false ]]; then
echo -e "${YELLOW}Pulling changes...${NC}"
git pull origin "$branch" --rebase
echo -e "${GREEN}✓ Successfully synced $repo_name${NC}"
else
echo -e "${YELLOW}[DRY RUN] Would pull these changes${NC}"
fi
else
echo -e "${GREEN}✓ Already up to date${NC}"
fi
# Return to docs root
cd "$DOCS_ROOT"
}
# Main sync process
main() {
print_header "ONE Platform Documentation Sync"
echo "Started: $(date)"
# Record start time
START_TIME=$(date +%s)
# Sync each documentation source
sync_repo "Vercel AI SDK" "$DOCS_ROOT/ai-sdk" "main"
sync_repo "Astro Documentation" "$DOCS_ROOT/astro" "main"
sync_repo "Convex Backend" "$DOCS_ROOT/convex" "main"
sync_repo "Effect TypeScript" "$DOCS_ROOT/effectts" "main"
# Claude Code is maintained directly in this repo, so we don't sync it
print_header "Claude Code Documentation"
echo -e "${GREEN}✓ Claude Code docs maintained directly in this repository${NC}"
# Show summary
print_header "Sync Summary"
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
echo "Completed: $(date)"
echo "Duration: ${DURATION}s"
if [[ "$DRY_RUN" == false ]]; then
# Check if there are changes to commit
cd "$DOCS_ROOT"
if git diff --quiet && git diff --cached --quiet; then
echo -e "${GREEN}✓ No changes to commit${NC}"
else
echo -e "${YELLOW}⚠ Changes detected in main docs repository${NC}"
echo -e "${YELLOW}Run the following to commit:${NC}"
echo ""
echo " cd $DOCS_ROOT"
echo " git add -A"
echo " git commit -m \"docs: sync upstream documentation sources\""
echo " git push origin main"
fi
else
echo -e "${YELLOW}[DRY RUN] No changes were applied${NC}"
fi
print_header "Sync Complete"
# Log to file
if [[ "$DRY_RUN" == false ]]; then
echo "Sync completed at $(date)" >> "$LOG_FILE"
fi
}
# Verify we're in the docs directory
if [[ ! -d "$DOCS_ROOT" ]]; then
echo -e "${RED}Error: Docs directory not found: $DOCS_ROOT${NC}"
exit 1
fi
# Run main sync
main
exit 0