|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # Codesphere Patch Generator |
3 | | -# This script generates the codesphere-brand.patch file by applying branding changes |
4 | | -# to a clean VSCodium vscode checkout and creating a git diff. |
| 3 | +# Generates codesphere-brand.patch by applying branding to a clean VSCodium checkout. |
| 4 | +# Uses a temporary directory to avoid modifying the VSCodium submodule source. |
5 | 5 |
|
6 | 6 | set -e |
7 | 7 |
|
8 | 8 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
9 | 9 | REPO_ROOT="$SCRIPT_DIR/.." |
10 | | -VSCODIUM_DIR="$REPO_ROOT/vendor/vscodium" |
11 | | -VSCODE_DIR="$VSCODIUM_DIR/vscode" |
| 10 | +VSCODIUM_SUBMODULE="$REPO_ROOT/vendor/vscodium" |
12 | 11 | PATCH_OUTPUT="$SCRIPT_DIR/patches/codesphere-brand.patch" |
13 | 12 |
|
| 13 | +# Load central environment (if not already loaded) |
| 14 | +if [ -f "$REPO_ROOT/ci/env.sh" ]; then |
| 15 | + . "$REPO_ROOT/ci/env.sh" |
| 16 | +fi |
| 17 | + |
| 18 | +# Temporary workspace vars |
| 19 | +TEMP_ROOT="$REPO_ROOT/build_temp" |
| 20 | +TEMP_VSCODIUM="$TEMP_ROOT/vscodium" |
| 21 | +TEMP_VSCODE="$TEMP_VSCODIUM/vscode" |
| 22 | + |
14 | 23 | echo "🔧 Codesphere Brand Patch Generator" |
15 | 24 | echo "====================================" |
16 | | -echo "" |
| 25 | +echo "Working directory: $TEMP_ROOT" |
17 | 26 |
|
18 | | -# Ensure we're in a git repo |
19 | | -if [ ! -d "$VSCODE_DIR/.git" ]; then |
20 | | - echo "❌ Error: $VSCODE_DIR is not a git repository" |
21 | | - echo "Please run vendor/vscodium/get_repo.sh first to initialize the vscode directory" |
22 | | - exit 1 |
23 | | -fi |
| 27 | +# Cleanup any previous run |
| 28 | +rm -rf "$TEMP_ROOT" |
| 29 | +mkdir -p "$TEMP_VSCODIUM" |
24 | 30 |
|
25 | | -cd "$VSCODE_DIR" || exit 1 |
| 31 | +# 1. Copy VSCodium scripts to temp dir (so we can fix CRLF safely) |
| 32 | +echo "📦 Copying VSCodium scripts to temp workspace..." |
| 33 | +cp -r "$VSCODIUM_SUBMODULE/"* "$TEMP_VSCODIUM/" |
26 | 34 |
|
27 | | -# Make sure the working directory is clean |
28 | | -if [ -n "$(git status --porcelain)" ]; then |
29 | | - echo "⚠️ Warning: vscode directory has uncommitted changes" |
30 | | - echo "Resetting to clean state..." |
31 | | - git reset --hard HEAD |
32 | | - git clean -fd |
| 35 | +# 2. Fix CRLF line endings in the temp scripts (crucial for Windows/WSL) |
| 36 | +echo "🔧 Fixing CRLF line endings in temp scripts..." |
| 37 | +find "$TEMP_VSCODIUM" -name "*.sh" -type f -exec sed -i 's/\r$//' {} + |
| 38 | + |
| 39 | +# 3. Fetch VS Code source using the temp scripts |
| 40 | +echo "📥 Fetching VS Code source (this may take time)..." |
| 41 | +cd "$TEMP_VSCODIUM" || exit 1 |
| 42 | +# Force bash usage to ensuring expected behavior |
| 43 | +bash ./get_repo.sh |
| 44 | + |
| 45 | +# 4. Verify fetch success |
| 46 | +if [ ! -d "$TEMP_VSCODE/.git" ]; then |
| 47 | + echo "❌ Error: Failed to fetch vscode source in temp dir" |
| 48 | + exit 1 |
33 | 49 | fi |
34 | 50 |
|
35 | | -echo "✅ Clean vscode checkout ready" |
| 51 | +echo "✅ Clean vscode checkout ready in temp dir" |
36 | 52 | echo "" |
37 | 53 | echo "🎨 Applying Codesphere branding changes..." |
38 | 54 |
|
39 | | -# Apply all the branding replacements that were in enforce-branding.sh |
40 | | -# First, github.com/VSCodium -> github.com/Codesphere |
| 55 | +cd "$TEMP_VSCODE" || exit 1 |
| 56 | + |
| 57 | +# Apply branding replacements (Regex logic from original enforce-branding.sh) |
| 58 | + |
| 59 | +# github.com/VSCodium -> github.com/Codesphere |
41 | 60 | find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.html" -o -name "*.json" -o -name "*.md" -o -name "*.iss" -o -name "*.xml" -o -name "*.spec.template" -o -name "*.yaml" -o -name "*.template" -o -name "*.rs" -o -name "*.isl" -o -name "*.txt" -o -name "*.toml" \) \ |
42 | 61 | -not -path "*/node_modules/*" -not -path "*/.git/*" \ |
43 | 62 | -exec perl -pi -e 's/github\.com\/VSCodium/github.com\/Codesphere/g' {} + 2>/dev/null || true |
@@ -72,24 +91,26 @@ find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.html" -o -name "*.jso |
72 | 91 | -not -path "*/node_modules/*" -not -path "*/.git/*" \ |
73 | 92 | -exec perl -pi -e 's/code\.visualstudio\.com/codesphere.com/g' {} + 2>/dev/null || true |
74 | 93 |
|
75 | | -echo "✅ Branding changes applied" |
| 94 | +echo "✅ Branding changes applied to temp source" |
76 | 95 | echo "" |
77 | 96 | echo "📝 Generating patch file..." |
78 | 97 |
|
79 | | -# Generate the patch |
| 98 | +# Generate the patch from the temp repo |
80 | 99 | git add -A |
81 | 100 | git diff --cached > "$PATCH_OUTPUT" |
82 | 101 |
|
83 | | -# Reset the changes |
84 | | -git reset --hard HEAD |
85 | | -git clean -fd |
86 | | - |
87 | 102 | echo "" |
88 | 103 | if [ -s "$PATCH_OUTPUT" ]; then |
89 | 104 | PATCH_LINES=$(wc -l < "$PATCH_OUTPUT") |
90 | 105 | echo "✅ Patch generated successfully!" |
91 | 106 | echo " File: $PATCH_OUTPUT" |
92 | 107 | echo " Lines: $PATCH_LINES" |
| 108 | + |
| 109 | + # Cleanup |
| 110 | + echo "🧹 Cleaning up temp workspace..." |
| 111 | + cd "$REPO_ROOT" |
| 112 | + rm -rf "$TEMP_ROOT" |
| 113 | + echo "✨ Done." |
93 | 114 | else |
94 | 115 | echo "❌ No changes detected - patch file is empty" |
95 | 116 | exit 1 |
|
0 commit comments