Skip to content

Commit 50d4642

Browse files
committed
refactor: Change how we delete the script to be more efficient
1 parent 06e7e30 commit 50d4642

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

_InitializeRepository.ps1

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you have made changes to any files you may want to commit them before continu
1414

1515
[string] $organizationName = Read-Host -Prompt "Enter your name, or the the name of your organization (e.g. 'My Company'). This will be used in the module manifest and repository license"
1616

17-
Write-Information "Copying template repository module files to a temporary location."
17+
Write-Information "Copying template repository module files to a temporary location to run it from."
1818
[string] $tempModuleDirectoryPath = CopyTemplateModuleFilesToTempDirectory -templateModuleDirectoryPath $TemplateModuleDirectoryPath
1919

2020
Write-Information "Removing all files from this repository so they can be replaced with template repository files."
@@ -28,7 +28,7 @@ If you have made changes to any files you may want to commit them before continu
2828
Write-Information "Removing the temporary template module files since we are done using it to create the template repository files."
2929
RemoveTemporaryModuleDirectory -tempModuleDirectoryPath $tempModuleDirectoryPath
3030

31-
Write-Information "Starting external process to delete this script."
31+
Write-Information "Deleting this script as it is no longer needed."
3232
DeleteThisScript
3333

3434
Write-Host -ForegroundColor Green "Repo initialization complete. You can now commit the changes to your repository."
@@ -77,16 +77,6 @@ Begin
7777
function DeleteThisScript
7878
{
7979
[string] $scriptPath = Join-Path -Path $PSScriptRoot -ChildPath '_InitializeRepository.ps1'
80-
[string] $deleteCommand = "-ExecutionPolicy Bypass -NoProfile -Command `"Start-Sleep -Seconds 1; Remove-Item -Path '$scriptPath' -Force`""
81-
82-
$powerShellVersion = $PSVersionTable.PSVersion.Major
83-
if ($powerShellVersion -le 5)
84-
{
85-
Invoke-Expression -Command "powershell $deleteCommand"
86-
}
87-
else
88-
{
89-
Invoke-Expression -Command "pwsh $deleteCommand"
90-
}
80+
Remove-Item -Path $scriptPath -Force
9181
}
9282
}

0 commit comments

Comments
 (0)