Created
July 14, 2023 17:23
-
-
Save JamieMagee/ed52c77cf5891bed120ff2bc75861745 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make an HTTP call to whatsprintisit.com to get the current sprint number | |
# and update the package.json files in the Tasks folder to use the correct | |
# Get the current sprint number | |
$res = Invoke-RestMethod -Headers @{"Accept" = "application/json" } -Uri "https://whatsprintisit.com" | |
$currentSprint = $res.sprint | |
# Find all directories under the Tasks folder | |
$tasks = Get-ChildItem -Path .\Tasks -Directory -Recurse | |
foreach ($task in $tasks) { | |
# find each package.json file | |
$files = Get-ChildItem -Path $task.FullName -Filter "package.json" -Recurse | Where-Object { $_.FullName -notmatch "node_modules" } | |
if ($files.Count -eq 0) { | |
Write-Host "No package.json files found in $task" | |
continue | |
} | |
$updated = $false | |
foreach ($file in $files) { | |
$path = $file.FullName | |
$directory = $file.DirectoryName | |
$content = [System.IO.File]::ReadAllText($path) | |
# Check if the package.json is using TypeScript 4.0.2 | |
if ($content -notmatch '"typescript": "4.0.2"') { | |
Write-Host "Skipping $path" | |
continue | |
} | |
$updated = $true | |
$content = $content -replace '"typescript": "4.0.2"', '"typescript": "4.0.8"' | |
[System.IO.File]::WriteAllText($path, $content) | |
# Run npm install | |
Write-Host "Running npm install in $directory" | |
$npmInstall = Start-Process -NoNewWindow -FilePath "npm" -ArgumentList "install --lockfile-version 1" -WorkingDirectory $directory -Wait -PassThru -RedirectStandardOutput ".\NUL" | |
if ($npmInstall.ExitCode -ne 0) { | |
Write-Error "npm install failed in $directory" | |
exit 1 | |
} | |
} | |
if ($updated -eq $false) { | |
Write-Host "No package.json updated in $task" | |
continue | |
} | |
$taskJson = Get-Content "$task\task.json" | ConvertFrom-Json | |
$taskVersion = $taskJson.version | |
if ($taskVersion.Minor -ne $currentSprint) { | |
$taskJson.version.Minor = $currentSprint | |
$taskJson.version.Patch = 0 | |
} | |
else { | |
$taskJson.version.Patch = $taskJson.version.Patch + 1 | |
} | |
# Update the task.json file | |
$taskJson | ConvertTo-Json -Depth 100 | Set-Content "$task\task.json" | |
$taskLocJson = Get-Content "$task\task.loc.json" | ConvertFrom-Json | |
$taskVersion = $taskLocJson.version | |
if ($taskVersion.Minor -ne $currentSprint) { | |
$taskLocJson.version.Minor = $currentSprint | |
$taskLocJson.version.Patch = 0 | |
} | |
else { | |
$taskLocJson.version.Patch = $taskLocJson.version.Patch + 1 | |
} | |
# Update the task.json file | |
$taskLocJson | ConvertTo-Json -Depth 100 | Set-Content "$task\task.loc.json" | |
# Commit the changes | |
git add $task.FullName | |
git commit -m "$($task.BaseName) updated to TypeScript 4.0.8" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment