Skip to content

Commit

Permalink
#_require: Init nuget before install module
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Jul 25, 2024
1 parent 6359983 commit ccc125c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ReadScriptFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,14 @@ function Preprocessor($Content, $FilePath) {
$_
}
}
$NuGetIniter = "try{Import-PackageProvider NuGet}catch{Install-PackageProvider NuGet -Scope CurrentUser -Force -ea Ignore;Import-PackageProvider NuGet -ea Ignore}"
$LoadModuleScript = if ($requiredModules.Count -gt 1) {
(PSObjectToString $requiredModules -OneLine) + '|%{if(!(gmo $_ -ListAvailable -ea SilentlyContinue)){Install-Module $_ -Scope CurrentUser -Force -ea Stop}}'
(PSObjectToString $requiredModules -OneLine) + '|%{if(!(gmo $_ -ListAvailable -ea SilentlyContinue)){'+$NuGetIniter+';Install-Module $_ -Scope CurrentUser -Force -ea Stop}}'
}
elseif ($requiredModules.Count -eq 1) {
"if(!(gmo $requiredModules -ListAvailable -ea SilentlyContinue)){Install-Module $requiredModules -Scope CurrentUser -Force -ea Stop}"
"if(!(gmo $requiredModules -ListAvailable -ea SilentlyContinue)){$NuGetIniter;Install-Module $requiredModules -Scope CurrentUser -Force -ea Stop}"
}
$LoadModuleScript = $LoadModuleScript -join "`n"
if ($LoadModuleScript) {
$Content = $Content | ForEach-Object {
# 在第一次#_require的前方加入$LoadModuleScript
Expand Down

0 comments on commit ccc125c

Please sign in to comment.