Skip to content

Commit

Permalink
Merge pull request #29 from AArnott/fix25
Browse files Browse the repository at this point in the history
Add Expand-Template.cmd stub
  • Loading branch information
AArnott authored Nov 15, 2019
2 parents d6fe240 + 7248b76 commit ea9aac0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Expand-Template.cmd
Original file line number Diff line number Diff line change
@@ -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 }"
13 changes: 11 additions & 2 deletions Expand-Template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions init.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@set PS1UnderCmd=1
powershell.exe -ExecutionPolicy bypass -Command "& '%~dpn0.ps1'" %*
@set PS1UnderCmd=
@echo off
SETLOCAL
set PS1UnderCmd=1
powershell.exe -NoProfile -NoLogo -ExecutionPolicy bypass -Command "try { & '%~dpn0.ps1' %*; exit $LASTEXITCODE } catch { write-host $_; exit 1 }"

0 comments on commit ea9aac0

Please sign in to comment.