Skip to content

Commit c573021

Browse files
committed
feat(build): implement comprehensive build artifact prevention and cleanup scripts
1 parent d147959 commit c573021

File tree

8 files changed

+294
-1
lines changed

8 files changed

+294
-1
lines changed

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,48 @@ thinkred-website.zip
2222
dist/
2323
**/dist/
2424

25+
# Build artifacts and source maps
26+
*.map
27+
**/*.map
28+
*.min.js
29+
**/*.min.js
30+
*.min.css
31+
**/*.min.css
32+
*.bundle.js
33+
**/*.bundle.js
34+
*.bundle.css
35+
**/*.bundle.css
36+
37+
# Vite build cache and temp files
38+
.vite/
39+
**/.vite/
40+
vite.config.js.timestamp-*
41+
**/vite.config.js.timestamp-*
42+
43+
# Build process temporary files
44+
*.tsbuildinfo
45+
**/*.tsbuildinfo
46+
.turbo/
47+
**/.turbo/
48+
.next/
49+
**/.next/
50+
.nuxt/
51+
**/.nuxt/
52+
.output/
53+
**/.output/
54+
.vercel/
55+
**/.vercel/
56+
.netlify/
57+
**/.netlify/
58+
59+
# Cache directories
60+
.cache/
61+
**/.cache/
62+
.parcel-cache/
63+
**/.parcel-cache/
64+
.rollup.cache/
65+
**/.rollup.cache/
66+
2567
# misc
2668
.DS_Store
2769
**/.DS_Store
@@ -45,6 +87,20 @@ clasp-credentials.json
4587
*.backup*
4688
*.tmp
4789
*.temp
90+
*~
91+
**/*~
92+
*.lock.tmp
93+
**/*.lock.tmp
94+
95+
# Build and deployment locks
96+
*.building
97+
**/*.building
98+
*.deploying
99+
**/*.deploying
100+
deploy.lock
101+
**/deploy.lock
102+
build.lock
103+
**/build.lock
48104

49105
# Logs
50106
npm-debug.log*

docs/GIT_BUILD_PREVENTION.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Git Build Artifacts Prevention
2+
3+
## Problem
4+
5+
Git was picking up build files during build/deployment processes, causing:
6+
- Unintended tracking of temporary files
7+
- Repository bloat with build artifacts
8+
- Conflicts during deployment
9+
- Source maps and minified files being committed
10+
11+
## Solution
12+
13+
### 1. Enhanced .gitignore
14+
15+
Updated `.gitignore` with comprehensive patterns for:
16+
- Build directories (`build/`, `dist/`, `hostinger-deploy/`)
17+
- Source maps (`*.map`)
18+
- Minified files (`*.min.js`, `*.min.css`)
19+
- Bundle files (`*.bundle.js`, `*.bundle.css`)
20+
- Cache directories (`.vite/`, `.cache/`, etc.)
21+
- Build process temporary files
22+
- Lock files created during builds
23+
24+
### 2. Build Process Scripts
25+
26+
#### Pre-build Script (`scripts/pre-build.sh`)
27+
28+
- Creates lock files to indicate build in progress
29+
- Stashes uncommitted changes to prevent conflicts
30+
- Cleans existing build directories
31+
- Sets up clean build environment
32+
33+
#### Post-build Script (`scripts/post-build.sh`)
34+
35+
- Removes build lock files
36+
- Restores any stashed changes
37+
- Validates no build artifacts are tracked
38+
- Shows final Git status
39+
40+
#### Cleanup Script (`scripts/clean-git-build-artifacts.sh`)
41+
42+
- Removes accidentally tracked build artifacts
43+
- Cleans up temporary lock files
44+
- Shows what was cleaned
45+
46+
### 3. Package.json Integration
47+
48+
Added npm script hooks:
49+
- `prebuild`: Runs automatically before build
50+
- `postbuild`: Runs automatically after build
51+
- `clean:git`: Manual cleanup of Git artifacts
52+
53+
## Usage
54+
55+
### Automatic (Recommended)
56+
57+
Just run your normal build command:
58+
```bash
59+
npm run build
60+
```
61+
The pre/post scripts will run automatically.
62+
63+
### Manual Cleanup
64+
65+
If you notice build files in Git:
66+
```bash
67+
npm run clean:git
68+
```
69+
70+
### Emergency Cleanup
71+
72+
If build artifacts were committed:
73+
```bash
74+
./scripts/clean-git-build-artifacts.sh
75+
git commit -m "Remove build artifacts from tracking"
76+
```
77+
78+
## Prevention Tips
79+
80+
1. **Always check Git status before committing:**
81+
```bash
82+
git status
83+
```
84+
85+
2. **Use .gitignore early** - Add patterns before first build
86+
87+
3. **Separate build and source directories** clearly
88+
89+
4. **Use CI/CD for builds** instead of local builds when possible
90+
91+
5. **Review .gitignore regularly** as build tools evolve
92+
93+
## Common Build Artifacts to Avoid
94+
95+
- `*.map` - Source maps
96+
- `*.min.js` - Minified JavaScript
97+
- `*.min.css` - Minified CSS
98+
- `*.bundle.*` - Webpack/Vite bundles
99+
- Build directories (`build/`, `dist/`, etc.)
100+
- Cache directories (`.vite/`, `.cache/`, etc.)
101+
- Temporary files (`*.tmp`, `*.temp`)
102+
- Lock files from build processes
103+
104+
## Troubleshooting
105+
106+
### Build files still appearing in Git?
107+
108+
1. Check if files were already tracked: `git ls-files | grep build`
109+
2. Run cleanup script: `npm run clean:git`
110+
3. Verify .gitignore patterns: `git check-ignore path/to/file`
111+
112+
### Build process failing after changes?
113+
114+
1. Ensure scripts are executable: `chmod +x scripts/*.sh`
115+
2. Check for shell compatibility (bash required)
116+
3. Verify no critical files were accidentally ignored
117+
118+
### Stashed changes not restored?
119+
120+
1. Check for `.build-stash-flag` file
121+
2. Manually restore: `git stash list` and `git stash pop`
122+
123+
## Monitoring
124+
125+
The post-build script automatically checks for tracked build artifacts and warns if any are found. Always review the output after builds.

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ The ThinkRED website is a modern React-based company website with a Google Apps
3030
|----------|---------|----------|
3131
| [ENVIRONMENT.md](./ENVIRONMENT.md) | Environment configuration | Developers, DevOps |
3232
| [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) | Common issues and solutions | Developers |
33+
| [GIT_BUILD_PREVENTION.md](./GIT_BUILD_PREVENTION.md) | Git build artifacts prevention | Developers, DevOps |
34+
35+
### Process and Guidelines
3336

3437
| Document | Purpose | Audience |
3538
|----------|---------|----------|
39+
| [WORKFLOW.md](./WORKFLOW.md) | Development workflow and Git practices | Developers |
3640
| [CONTRIBUTING.md](./CONTRIBUTING.md) | Contribution guidelines | Contributors |
41+
| [STYLE_GUIDE.md](./STYLE_GUIDE.md) | Code style and conventions | Developers |
3742

3843
## Getting Started
3944

docs/TROUBLESHOOTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ This guide provides solutions to common issues encountered during development an
118118
3. **Check Dependencies**:
119119
```bash
120120
npm audit
121-
npm audit fix
121+
```
122+
123+
4. **Git Build Artifacts Issues**:
124+
If you're seeing build files appearing in Git during builds, see [GIT_BUILD_PREVENTION.md](./GIT_BUILD_PREVENTION.md) for comprehensive solutions.
125+
126+
```bash
127+
# Quick fix for build artifacts in Git
128+
npm run clean:git
122129
```
123130

124131
### Styling Issues

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
"scripts": {
1111
"start": "cd frontend && npm run dev",
1212
"dev": "npm start",
13+
"prebuild": "./scripts/pre-build.sh",
1314
"build": "cd frontend && npm run build && cp -r dist ../build",
15+
"postbuild": "./scripts/post-build.sh",
1416
"clean": "npm run clean:frontend && npm run clean:backend && rm -rf build temp",
17+
"clean:git": "./scripts/clean-git-build-artifacts.sh",
1518
"clean:frontend": "cd frontend && npm run clean",
1619
"clean:backend": "rm -rf backend/node_modules backend/.clasp.json.bak",
1720
"test": "cd frontend && npm run test",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Script to clean up any build artifacts that might have been accidentally tracked by Git
4+
# Run this if you notice build files appearing in git status during builds
5+
6+
echo "🧹 Cleaning up Git build artifacts..."
7+
8+
# Remove any accidentally tracked build artifacts from Git index (without deleting files)
9+
echo "Removing build artifacts from Git tracking..."
10+
11+
# Common build artifacts that shouldn't be tracked
12+
git rm --cached -r build/ 2>/dev/null || true
13+
git rm --cached -r frontend/dist/ 2>/dev/null || true
14+
git rm --cached -r frontend/hostinger-deploy/ 2>/dev/null || true
15+
git rm --cached -r backend/dist/ 2>/dev/null || true
16+
git rm --cached **/*.map 2>/dev/null || true
17+
git rm --cached **/*.min.js 2>/dev/null || true
18+
git rm --cached **/*.min.css 2>/dev/null || true
19+
git rm --cached **/*.tmp 2>/dev/null || true
20+
git rm --cached **/*.temp 2>/dev/null || true
21+
git rm --cached **/*.building 2>/dev/null || true
22+
git rm --cached **/*.deploying 2>/dev/null || true
23+
24+
# Clean up any temporary lock files
25+
find . -name "*.lock.tmp" -delete 2>/dev/null || true
26+
find . -name "*.building" -delete 2>/dev/null || true
27+
find . -name "*.deploying" -delete 2>/dev/null || true
28+
29+
echo "✅ Build artifact cleanup complete!"
30+
echo "💡 If you had tracked build files, commit the removal with:"
31+
echo " git commit -m 'Remove build artifacts from tracking'"
32+
33+
# Show current status
34+
echo ""
35+
echo "📊 Current Git status:"
36+
git status --short

scripts/post-build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Post-build script to clean up after build process
4+
# This should be run after your build process completes
5+
6+
echo "🎯 Post-build cleanup..."
7+
8+
# Remove build lock files
9+
rm -f .building
10+
rm -f frontend/.building 2>/dev/null || true
11+
rm -f backend/.building 2>/dev/null || true
12+
13+
# Restore stashed changes if they exist
14+
if [ -f .build-stash-flag ]; then
15+
echo "📦 Restoring stashed changes..."
16+
git stash pop
17+
rm -f .build-stash-flag
18+
fi
19+
20+
# Double-check that no build artifacts are being tracked
21+
if git ls-files | grep -E "\.(map|min\.(js|css)|tmp|temp)$" > /dev/null; then
22+
echo "⚠️ Warning: Build artifacts detected in Git tracking!"
23+
echo " Run ./scripts/clean-git-build-artifacts.sh to fix this"
24+
fi
25+
26+
# Show final status
27+
echo "📊 Final Git status:"
28+
git status --short
29+
30+
echo "✅ Post-build cleanup complete!"

scripts/pre-build.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Pre-build script to prevent Git from picking up build artifacts
4+
# This can be run before your build process starts
5+
6+
echo "🔒 Setting up build isolation..."
7+
8+
# Create lock files to prevent Git operations during build
9+
touch .building
10+
touch frontend/.building 2>/dev/null || true
11+
touch backend/.building 2>/dev/null || true
12+
13+
# Stash any uncommitted changes to prevent conflicts during build
14+
if ! git diff --quiet || ! git diff --cached --quiet; then
15+
echo "📦 Stashing uncommitted changes..."
16+
git stash push -m "Auto-stash before build $(date)"
17+
echo "build-stashed" > .build-stash-flag
18+
fi
19+
20+
# Ensure build directories are clean and ignored
21+
echo "🧹 Cleaning build directories..."
22+
rm -rf build/ 2>/dev/null || true
23+
rm -rf frontend/dist/ 2>/dev/null || true
24+
rm -rf frontend/hostinger-deploy/ 2>/dev/null || true
25+
rm -rf backend/dist/ 2>/dev/null || true
26+
27+
# Create .gitkeep files to maintain directory structure if needed
28+
mkdir -p build && echo "# Build artifacts - ignored by Git" > build/.gitkeep 2>/dev/null || true
29+
30+
echo "✅ Build environment prepared!"
31+
echo "🔥 You can now run your build process safely"

0 commit comments

Comments
 (0)