feat: move late modules

This commit is contained in:
Bjarke Sporring
2026-01-04 17:54:26 +01:00
parent 8920af4b5c
commit ceb5bd8031
12 changed files with 0 additions and 0 deletions

151
module-11-remotes/setup.ps1 Normal file
View File

@@ -0,0 +1,151 @@
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Sets up the remotes challenge environment.
.DESCRIPTION
Creates a simulated remote repository and working environment
for learning Git remote operations.
#>
# Remove existing challenge directory if present
if (Test-Path "challenge") {
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
Remove-Item -Path "challenge" -Recurse -Force
}
# Create challenge directory structure
Write-Host "Creating challenge environment..." -ForegroundColor Cyan
New-Item -ItemType Directory -Path "challenge" | Out-Null
Set-Location "challenge"
# Create a temporary workspace to build the initial repository
New-Item -ItemType Directory -Path "temp-workspace" | Out-Null
Set-Location "temp-workspace"
# Initialize and create initial commits
git init | Out-Null
git config user.name "Workshop User" | Out-Null
git config user.email "user@workshop.local" | Out-Null
# Create initial project files
$app = @"
class Application {
constructor() {
this.name = 'TeamProject';
this.version = '1.0.0';
}
start() {
console.log('Application started');
}
}
module.exports = Application;
"@
Set-Content -Path "app.js" -Value $app
git add app.js
git commit -m "Initial application" | Out-Null
$readme = @"
# Team Project
A collaborative project for learning Git remotes.
## Features
- Basic application structure
"@
Set-Content -Path "README.md" -Value $readme
git add README.md
git commit -m "Add README" | Out-Null
$package = @"
{
"name": "team-project",
"version": "1.0.0",
"description": "Learning Git remotes",
"main": "app.js"
}
"@
Set-Content -Path "package.json" -Value $package
git add package.json
git commit -m "Add package.json" | Out-Null
# Create the "remote" repository (bare repository)
Set-Location ..
git clone --bare temp-workspace remote-repo 2>$null | Out-Null
# Clean up temp workspace
Remove-Item -Path "temp-workspace" -Recurse -Force
# Create a helper script to simulate teammate changes
$simulateTeammateScript = @"
#!/usr/bin/env pwsh
# This script simulates a teammate making changes to the remote repository
Write-Host "Simulating teammate changes..." -ForegroundColor Cyan
# Create a temporary clone
if (Test-Path "temp-teammate") {
Remove-Item -Path "temp-teammate" -Recurse -Force
}
git clone remote-repo temp-teammate 2>>`$null | Out-Null
Set-Location temp-teammate
git config user.name "Teammate" 2>>`$null | Out-Null
git config user.email "teammate@workshop.local" 2>>`$null | Out-Null
# Make changes to main branch
`$appContent = Get-Content "app.js" -Raw
`$updatedApp = `$appContent -replace "start\(\) {", @"
start() {
console.log('Starting application...');
this.initialize();
}
initialize() {
"@
Set-Content -Path "app.js" -Value `$updatedApp
git add app.js 2>>`$null
git commit -m "Add initialization method" 2>>`$null | Out-Null
git push origin main 2>>`$null | Out-Null
Set-Location ..
Remove-Item -Path "temp-teammate" -Recurse -Force
Write-Host "Teammate pushed changes to remote repository!" -ForegroundColor Green
Write-Host "Use 'git fetch origin' to see the changes" -ForegroundColor Cyan
"@
Set-Content -Path "simulate-teammate.ps1" -Value $simulateTeammateScript
# Return to module directory
Set-Location ..
Write-Host "`n========================================" -ForegroundColor Green
Write-Host "Challenge environment created!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host "`nSetup complete! You have:" -ForegroundColor Cyan
Write-Host "- remote-repo/ - A 'remote' repository (simulates GitHub/GitLab)" -ForegroundColor White
Write-Host "- simulate-teammate.ps1 - Script to simulate teammate changes" -ForegroundColor White
Write-Host "`nYour task:" -ForegroundColor Yellow
Write-Host "1. Navigate to the challenge directory: cd challenge" -ForegroundColor White
Write-Host "2. Clone the remote: git clone remote-repo local-repo" -ForegroundColor White
Write-Host "3. Navigate to your clone: cd local-repo" -ForegroundColor White
Write-Host "4. Create a feature branch: git checkout -b add-feature" -ForegroundColor White
Write-Host "5. Add a new method to app.js (e.g., stop method)" -ForegroundColor White
Write-Host "6. Commit your changes" -ForegroundColor White
Write-Host "7. Push your branch: git push -u origin add-feature" -ForegroundColor White
Write-Host "8. Go back to challenge directory: cd .." -ForegroundColor White
Write-Host "9. Simulate teammate changes: pwsh simulate-teammate.ps1" -ForegroundColor White
Write-Host "10. Go back to local-repo: cd local-repo" -ForegroundColor White
Write-Host "11. Fetch updates: git fetch origin" -ForegroundColor White
Write-Host "12. Merge remote main: git merge origin/main" -ForegroundColor White
Write-Host "`nRun '../verify.ps1' from the challenge directory to check your solution.`n" -ForegroundColor Cyan