Created
August 20, 2024 14:34
-
-
Save naveedmurtuza/b9257a8001ebf8ac4699d6aa08713606 to your computer and use it in GitHub Desktop.
This file contains 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
# Define paths | |
$pathX = "C:\path\to\x" | |
$pathY = "C:\path\to\y" | |
$pathZ = "C:\path\to\z" | |
# Define filenames | |
$fileName = "w.js" | |
$backupExtension = ".bk" | |
# Run 'npm run build' at path X | |
Write-Output "Running 'npm run build' at $pathX..." | |
Set-Location $pathX | |
npm run build | |
# Check if the file exists in /x/dist | |
if (Test-Path "$pathX\dist\$fileName") { | |
Write-Output "$fileName found in $pathX\dist" | |
# Run 'npm run build' at path Y | |
Write-Output "Running 'npm run build' at $pathY..." | |
Set-Location $pathY | |
npm run build | |
# Check if the file exists in /y/dist | |
if (Test-Path "$pathY\dist\$fileName") { | |
Write-Output "$fileName found in $pathY\dist" | |
# Define the target file paths | |
$targetFile = "$pathZ\dist\$fileName" | |
$backupFile = "$targetFile$backupExtension" | |
# Check if the backup file already exists and delete it if it does | |
if (Test-Path $backupFile) { | |
Write-Output "Backup file $backupFile already exists. Deleting..." | |
Remove-Item $backupFile | |
} | |
# Rename the current file to the backup name if it exists | |
if (Test-Path $targetFile) { | |
Write-Output "Backing up existing $fileName to $fileName$backupExtension..." | |
Rename-Item $targetFile $backupFile | |
} | |
# Copy the file from Y to Z | |
Write-Output "Copying $fileName from $pathY\dist to $pathZ\dist..." | |
Copy-Item "$pathY\dist\$fileName" $targetFile | |
} | |
else { | |
Write-Output "$fileName not found in $pathY\dist" | |
} | |
} | |
else { | |
Write-Output "$fileName not found in $pathX\dist" | |
} | |
# Reset the location to the original path | |
Set-Location -Path $pwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment