-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsync-examples.sh
More file actions
executable file
·302 lines (239 loc) · 8.99 KB
/
Copy pathsync-examples.sh
File metadata and controls
executable file
·302 lines (239 loc) · 8.99 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
#
# Syncs example code from client library repos into the docs repo.
# Assumes client repos are in the parent directory (../buttplug, ../buttplug-js, etc.)
#
# Usage: ./scripts/sync-examples.sh
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOCS_ROOT="$(dirname "$SCRIPT_DIR")"
EXAMPLES_DIR="$DOCS_ROOT/examples/v4"
# Parent directory containing client repos
CLIENT_REPOS_DIR="$(dirname "$DOCS_ROOT")"
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Create examples directory structure
mkdir -p "$EXAMPLES_DIR/rust"
mkdir -p "$EXAMPLES_DIR/javascript"
mkdir -p "$EXAMPLES_DIR/typescript"
mkdir -p "$EXAMPLES_DIR/csharp"
mkdir -p "$EXAMPLES_DIR/dart"
mkdir -p "$EXAMPLES_DIR/python"
# Write a manifest header
write_manifest() {
local lang="$1"
local manifest="$EXAMPLES_DIR/$lang/SYNC_MANIFEST.md"
cat > "$manifest" << EOF
# Synced Examples - $lang
These examples are synced from the upstream client library.
**Do not edit directly** - changes will be overwritten on next sync.
Last synced: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
## Source
EOF
}
# Sync Rust examples
sync_rust() {
local src_dir="$CLIENT_REPOS_DIR/buttplug/examples/src/bin"
local dest_dir="$EXAMPLES_DIR/rust"
if [[ ! -d "$src_dir" ]]; then
log_warn "Rust examples not found at $src_dir"
return
fi
log_info "Syncing Rust examples from $src_dir"
write_manifest "rust"
# Get git info from source repo
local git_sha=""
if [[ -d "$CLIENT_REPOS_DIR/buttplug/.git" ]]; then
git_sha=$(cd "$CLIENT_REPOS_DIR/buttplug" && git rev-parse --short HEAD)
echo "- Repository: buttplug (Rust)" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Commit: $git_sha" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Path: examples/src/bin/" >> "$dest_dir/SYNC_MANIFEST.md"
fi
echo -e "\n## Files\n" >> "$dest_dir/SYNC_MANIFEST.md"
# Copy each .rs file (excluding device_tester which is a dev tool, not an example)
for file in "$src_dir"/*.rs; do
if [[ -f "$file" ]]; then
local basename=$(basename "$file")
# Skip files that aren't really examples
if [[ "$basename" == "device_tester.rs" ]]; then
log_info " Skipping $basename (dev tool, not example)"
continue
fi
cp "$file" "$dest_dir/"
echo "- \`$basename\`" >> "$dest_dir/SYNC_MANIFEST.md"
log_info " Copied $basename"
fi
done
}
# Sync TypeScript examples from buttplug-js
sync_typescript() {
local src_dir="$CLIENT_REPOS_DIR/buttplug-js/examples/node"
local dest_dir="$EXAMPLES_DIR/typescript"
if [[ ! -d "$src_dir" ]]; then
log_warn "TypeScript examples not found at $src_dir (not yet created in upstream)"
cat > "$dest_dir/SYNC_MANIFEST.md" << EOF
# Synced Examples - TypeScript
No examples directory exists in buttplug-js yet.
When examples are added to \`buttplug-js/examples/node/\`, run this script to sync them.
EOF
return
fi
log_info "Syncing TypeScript examples from $src_dir"
write_manifest "TypeScript"
# Get git info from source repo
local git_sha=""
if [[ -d "$CLIENT_REPOS_DIR/buttplug-js/.git" ]]; then
git_sha=$(cd "$CLIENT_REPOS_DIR/buttplug-js" && git rev-parse --short HEAD)
echo "- Repository: buttplug-js (TypeScript)" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Commit: $git_sha" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Path: examples/node/" >> "$dest_dir/SYNC_MANIFEST.md"
fi
echo -e "\n## Files\n" >> "$dest_dir/SYNC_MANIFEST.md"
# Copy TypeScript files
for file in "$src_dir"/*.ts; do
if [[ -f "$file" ]]; then
local basename=$(basename "$file")
cp "$file" "$dest_dir/"
echo "- \`$basename\`" >> "$dest_dir/SYNC_MANIFEST.md"
log_info " Copied $basename"
fi
done
}
# Sync JavaScript web examples
sync_javascript() {
local src_dir="$CLIENT_REPOS_DIR/buttplug-js/examples/web"
local dest_dir="$EXAMPLES_DIR/javascript"
if [[ ! -d "$src_dir" ]]; then
log_warn "JavaScript web examples not found at $src_dir"
cat > "$dest_dir/SYNC_MANIFEST.md" << EOF
# Synced Examples - JavaScript (Web)
No web examples directory exists in buttplug-js yet.
EOF
return
fi
log_info "Syncing JavaScript web examples from $src_dir"
write_manifest "javascript"
local git_sha=""
if [[ -d "$CLIENT_REPOS_DIR/buttplug-js/.git" ]]; then
git_sha=$(cd "$CLIENT_REPOS_DIR/buttplug-js" && git rev-parse --short HEAD)
echo "- Repository: buttplug-js (JavaScript/TypeScript)" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Commit: $git_sha" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Path: examples/web/" >> "$dest_dir/SYNC_MANIFEST.md"
fi
echo -e "\n## Files\n" >> "$dest_dir/SYNC_MANIFEST.md"
for file in "$src_dir"/*.js; do
if [[ -f "$file" ]]; then
local basename=$(basename "$file")
cp "$file" "$dest_dir/"
echo "- \`$basename\`" >> "$dest_dir/SYNC_MANIFEST.md"
log_info " Copied $basename"
fi
done
}
# Sync C# examples
sync_csharp() {
local src_dir="$CLIENT_REPOS_DIR/buttplug-csharp/examples"
local dest_dir="$EXAMPLES_DIR/csharp"
if [[ ! -d "$src_dir" ]]; then
log_warn "C# examples not found at $src_dir (not yet created in upstream)"
cat > "$dest_dir/SYNC_MANIFEST.md" << EOF
# Synced Examples - C#
No examples directory exists in buttplug-csharp yet.
When examples are added to \`buttplug-csharp/examples/\`, run this script to sync them.
EOF
return
fi
log_info "Syncing C# examples from $src_dir"
write_manifest "csharp"
local git_sha=""
if [[ -d "$CLIENT_REPOS_DIR/buttplug-csharp/.git" ]]; then
git_sha=$(cd "$CLIENT_REPOS_DIR/buttplug-csharp" && git rev-parse --short HEAD)
echo "- Repository: buttplug-csharp (C#)" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Commit: $git_sha" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Path: examples/" >> "$dest_dir/SYNC_MANIFEST.md"
fi
echo -e "\n## Files\n" >> "$dest_dir/SYNC_MANIFEST.md"
# C# examples are in subdirectories (e.g., ConnectionExample/Program.cs)
# Copy entire directory structure
for example_dir in "$src_dir"/*Example; do
if [[ -d "$example_dir" ]]; then
local basename=$(basename "$example_dir")
# Remove old copy if exists
rm -rf "$dest_dir/$basename"
cp -r "$example_dir" "$dest_dir/"
echo "- \`$basename/\`" >> "$dest_dir/SYNC_MANIFEST.md"
log_info " Copied $basename/"
fi
done
}
# Sync Dart examples (placeholder for when they exist)
sync_dart() {
local src_dir="$CLIENT_REPOS_DIR/buttplug-dart/example"
local dest_dir="$EXAMPLES_DIR/dart"
if [[ ! -d "$src_dir" ]]; then
log_warn "Dart examples not found at $src_dir (not yet created in upstream)"
cat > "$dest_dir/SYNC_MANIFEST.md" << EOF
# Synced Examples - Dart
No example directory exists in buttplug-dart yet.
When examples are added to \`buttplug-dart/example/\`, run this script to sync them.
EOF
return
fi
log_info "Syncing Dart examples from $src_dir"
write_manifest "dart"
}
# Sync Python examples
sync_python() {
local src_dir="$CLIENT_REPOS_DIR/buttplug-py/examples"
local dest_dir="$EXAMPLES_DIR/python"
if [[ ! -d "$src_dir" ]]; then
log_warn "Python examples not found at $src_dir"
cat > "$dest_dir/SYNC_MANIFEST.md" << EOF
# Synced Examples - Python
No examples directory exists in buttplug-py yet.
EOF
return
fi
log_info "Syncing Python examples from $src_dir"
write_manifest "python"
local git_sha=""
if [[ -d "$CLIENT_REPOS_DIR/buttplug-py/.git" ]]; then
git_sha=$(cd "$CLIENT_REPOS_DIR/buttplug-py" && git rev-parse --short HEAD)
echo "- Repository: buttplug-py (Python)" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Commit: $git_sha" >> "$dest_dir/SYNC_MANIFEST.md"
echo "- Path: examples/" >> "$dest_dir/SYNC_MANIFEST.md"
fi
echo -e "\n## Files\n" >> "$dest_dir/SYNC_MANIFEST.md"
for file in "$src_dir"/*.py; do
if [[ -f "$file" ]]; then
local basename=$(basename "$file")
cp "$file" "$dest_dir/"
echo "- \`$basename\`" >> "$dest_dir/SYNC_MANIFEST.md"
log_info " Copied $basename"
fi
done
}
# Main
log_info "Starting example sync..."
log_info "Docs root: $DOCS_ROOT"
log_info "Client repos directory: $CLIENT_REPOS_DIR"
echo ""
sync_rust
sync_typescript
sync_javascript
sync_csharp
sync_dart
sync_python
echo ""
# Sync device config data for STPIHKAL remark plugin
echo "Syncing device config data..."
"$(dirname "$0")/sync-device-config.sh"
echo ""
log_info "Sync complete! Examples are in $EXAMPLES_DIR"