refactor: move modules into levels
This commit is contained in:
247
01_essentials/02-history/setup.ps1
Normal file
247
01_essentials/02-history/setup.ps1
Normal file
@@ -0,0 +1,247 @@
|
||||
#!/usr/bin/env pwsh
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets up the Module 02 challenge environment with commit history.
|
||||
|
||||
.DESCRIPTION
|
||||
This script creates a challenge directory with a Git repository that
|
||||
contains multiple commits for students to explore using git log and git diff.
|
||||
#>
|
||||
|
||||
Write-Host "`n=== Setting up Module 02 Challenge ===" -ForegroundColor Cyan
|
||||
|
||||
# Remove existing challenge directory if it exists
|
||||
if (Test-Path "challenge") {
|
||||
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
||||
Remove-Item -Recurse -Force "challenge"
|
||||
}
|
||||
|
||||
# Create fresh challenge directory
|
||||
Write-Host "Creating challenge directory..." -ForegroundColor Green
|
||||
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
||||
Set-Location "challenge"
|
||||
|
||||
# Initialize Git repository
|
||||
Write-Host "Initializing Git repository..." -ForegroundColor Green
|
||||
git init | Out-Null
|
||||
|
||||
# Configure git for this repository
|
||||
git config user.name "Workshop Student"
|
||||
git config user.email "student@example.com"
|
||||
|
||||
# Commit 1: Initial project structure
|
||||
Write-Host "Creating initial project structure..." -ForegroundColor Green
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
# Application initialization code here
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Initial project structure" | Out-Null
|
||||
|
||||
# Commit 2: Add user authentication
|
||||
Write-Host "Adding user authentication..." -ForegroundColor Green
|
||||
$authContent = @"
|
||||
# auth.py - Authentication module
|
||||
|
||||
def login(username, password):
|
||||
# Authenticate user
|
||||
print(f"Logging in user: {username}")
|
||||
return True
|
||||
|
||||
def logout(username):
|
||||
# Log out user
|
||||
print(f"Logging out user: {username}")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "auth.py" -Value $authContent
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
from auth import login, logout
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
# Application initialization code here
|
||||
login("user", "password")
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Add user authentication" | Out-Null
|
||||
|
||||
# Commit 3: Add database connection
|
||||
Write-Host "Adding database connection..." -ForegroundColor Green
|
||||
$databaseContent = @"
|
||||
# database.py - Database connection module
|
||||
|
||||
def connect():
|
||||
# Connect to database
|
||||
print("Connecting to database...")
|
||||
return True
|
||||
|
||||
def disconnect():
|
||||
# Disconnect from database
|
||||
print("Disconnecting from database...")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "database.py" -Value $databaseContent
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
from auth import login, logout
|
||||
from database import connect, disconnect
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
connect()
|
||||
# Application initialization code here
|
||||
login("user", "password")
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Add database connection" | Out-Null
|
||||
|
||||
# Commit 4: Fix authentication bug
|
||||
Write-Host "Fixing authentication bug..." -ForegroundColor Green
|
||||
$authContent = @"
|
||||
# auth.py - Authentication module
|
||||
|
||||
def login(username, password):
|
||||
# Authenticate user
|
||||
if not username or not password:
|
||||
print("Error: Username and password required")
|
||||
return False
|
||||
print(f"Logging in user: {username}")
|
||||
return True
|
||||
|
||||
def logout(username):
|
||||
# Log out user
|
||||
print(f"Logging out user: {username}")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "auth.py" -Value $authContent
|
||||
|
||||
git add .
|
||||
git commit -m "Fix authentication bug" | Out-Null
|
||||
|
||||
# Commit 5: Add user profile feature
|
||||
Write-Host "Adding user profile feature..." -ForegroundColor Green
|
||||
$profileContent = @"
|
||||
# profile.py - User profile module
|
||||
|
||||
def get_profile(username):
|
||||
# Get user profile
|
||||
print(f"Fetching profile for: {username}")
|
||||
return {"username": username, "email": f"{username}@example.com"}
|
||||
|
||||
def update_profile(username, data):
|
||||
# Update user profile
|
||||
print(f"Updating profile for: {username}")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "profile.py" -Value $profileContent
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
from auth import login, logout
|
||||
from database import connect, disconnect
|
||||
from profile import get_profile
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
connect()
|
||||
# Application initialization code here
|
||||
if login("user", "password"):
|
||||
profile = get_profile("user")
|
||||
print(f"User profile: {profile}")
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Add user profile feature" | Out-Null
|
||||
|
||||
# Create answers.md template
|
||||
Write-Host "Creating answers.md template..." -ForegroundColor Green
|
||||
$answersTemplate = @"
|
||||
# Git History Exploration - Answers
|
||||
|
||||
Answer the following questions by exploring the Git repository history.
|
||||
|
||||
## Question 1: How many commits are in the repository?
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
|
||||
## Question 2: What was the commit message for the third commit?
|
||||
|
||||
(Counting from the first/oldest commit)
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
|
||||
## Question 3: Which file was modified in the "Fix authentication bug" commit?
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
|
||||
## Question 4: What changes were made to app.py between the first and last commits?
|
||||
|
||||
Briefly describe the main changes you observe.
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
|
||||
---
|
||||
|
||||
**Hints:**
|
||||
- Use `git log` or `git log --oneline` to view commit history
|
||||
- Use `git log --stat` to see which files were changed in each commit
|
||||
- Use `git show <commit-hash>` to view details of a specific commit
|
||||
- Use `git diff <commit1> <commit2> <file>` to compare changes between commits
|
||||
"@
|
||||
|
||||
Set-Content -Path "answers.md" -Value $answersTemplate
|
||||
|
||||
# Return to module directory
|
||||
Set-Location ..
|
||||
|
||||
Write-Host "`n=== Setup Complete! ===" -ForegroundColor Green
|
||||
Write-Host "`nYour challenge environment is ready in the 'challenge/' directory." -ForegroundColor Cyan
|
||||
Write-Host "`nNext steps:" -ForegroundColor Cyan
|
||||
Write-Host " 1. cd challenge" -ForegroundColor White
|
||||
Write-Host " 2. Open 'answers.md' to see the questions" -ForegroundColor White
|
||||
Write-Host " 3. Explore the commit history using 'git log'" -ForegroundColor White
|
||||
Write-Host " 4. Fill in your answers in 'answers.md'" -ForegroundColor White
|
||||
Write-Host " 5. Run '..\verify.ps1' to check your answers" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Reference in New Issue
Block a user