From 7248b76f71de8ba2afa097d129367d784c371159 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Thu, 14 Nov 2019 21:44:06 -0700 Subject: [PATCH] Add Expand-Template.cmd stub --- Expand-Template.cmd | 4 ++++ Expand-Template.ps1 | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Expand-Template.cmd diff --git a/Expand-Template.cmd b/Expand-Template.cmd new file mode 100644 index 00000000..970285c2 --- /dev/null +++ b/Expand-Template.cmd @@ -0,0 +1,4 @@ +@echo off +SETLOCAL +set PS1UnderCmd=1 +powershell.exe -NoProfile -NoLogo -ExecutionPolicy bypass -Command "try { & '%~dpn0.ps1' %*; exit $LASTEXITCODE } catch { write-host $_; exit 1 }" diff --git a/Expand-Template.ps1 b/Expand-Template.ps1 index 89614a2d..5225f878 100644 --- a/Expand-Template.ps1 +++ b/Expand-Template.ps1 @@ -149,11 +149,11 @@ try { # Self destruct $Invocation = (Get-Variable MyInvocation -Scope 1).Value - git rm Expand-Template.ps1 + git rm Expand-Template.* git rm :/azure-pipelines/expand-template.yml # Self-integrity check - Get-ChildItem -Recurse -File -Exclude bin,obj,README.md,Expand-Template.ps1 |? { -not $_.FullName.Contains("obj") } |% { + Get-ChildItem -Recurse -File -Exclude bin,obj,README.md,Expand-Template.* |? { -not $_.FullName.Contains("obj") } |% { $PLACEHOLDERS = Get-Content -Path $_.FullName |? { $_.Contains('PLACEHOLDER') } if ($PLACEHOLDERS) { Write-Error "PLACEHOLDER discovered in $($_.FullName)" @@ -162,6 +162,15 @@ try { # Commit the changes git commit -qm "Expanded template for $LibraryName" -m "This expansion done by the (now removed) Expand-Template.ps1 script." + + Write-Host -ForegroundColor Green "Template successfully expanded." + + if ($env:PS1UnderCmd) { + # We're running under the Expand-Template.cmd script. + # Since we just deleted it from disk cmd.exe will complain. Just advise the user it's OK. + Write-Host -ForegroundColor Green 'Disregard an error you may see: "The batch file cannot be found." We just cleaned up after ourselves.' + } + } finally { Pop-Location }