|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to copy workspace Cargo.lock to all example template directories |
| 4 | +# This ensures templates have up-to-date lock files for cargo generate |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# Define paths |
| 9 | +WORKSPACE_LOCK="examples/Cargo.lock" |
| 10 | +EXAMPLES_DIR="examples" |
| 11 | + |
| 12 | +# Check if workspace lock file exists |
| 13 | +if [[ ! -f "$WORKSPACE_LOCK" ]]; then |
| 14 | + echo "Error: Workspace Cargo.lock not found at $WORKSPACE_LOCK" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +# Check if examples directory exists |
| 19 | +if [[ ! -d "$EXAMPLES_DIR" ]]; then |
| 20 | + echo "Error: Examples directory not found at $EXAMPLES_DIR" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# Find all subdirectories in examples/ that contain a Cargo.toml (excluding target) |
| 25 | +example_dirs=() |
| 26 | +while IFS= read -r -d '' dir; do |
| 27 | + # Skip the target directory |
| 28 | + if [[ "$(basename "$dir")" == "target" ]]; then |
| 29 | + continue |
| 30 | + fi |
| 31 | + |
| 32 | + # Check if the directory contains a Cargo.toml file |
| 33 | + if [[ -f "$dir/Cargo.toml" ]]; then |
| 34 | + example_dirs+=("$dir") |
| 35 | + fi |
| 36 | +done < <(find "$EXAMPLES_DIR" -mindepth 1 -maxdepth 1 -type d -print0) |
| 37 | + |
| 38 | +# Check if we found any example directories |
| 39 | +if [[ ${#example_dirs[@]} -eq 0 ]]; then |
| 40 | + echo "No example directories with Cargo.toml found in $EXAMPLES_DIR" |
| 41 | + exit 0 |
| 42 | +fi |
| 43 | + |
| 44 | +# Copy workspace lock to each example directory |
| 45 | +copied_count=0 |
| 46 | +for example_dir in "${example_dirs[@]}"; do |
| 47 | + target_lock="$example_dir/Cargo.lock" |
| 48 | + cp "$WORKSPACE_LOCK" "$target_lock" |
| 49 | + echo "Copied $WORKSPACE_LOCK to $target_lock" |
| 50 | + ((copied_count++)) |
| 51 | +done |
| 52 | + |
| 53 | +echo "Successfully copied Cargo.lock to $copied_count example template(s)" |
0 commit comments