Skip to content

Commit

Permalink
feat(local build): add Atlas modules to profile
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Aug 26, 2024
1 parent 8e872e6 commit 04a26ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions .atlasPsModulesPath
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src\playbook\Executables\AtlasModules\Scripts\Modules
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
"type": "PowerShell",
"request": "launch",
"name": "Build Playbook (Test)",
"script": "& '${workspaceFolder}/src/local-build.ps1' -AddLiveLog -ReplaceOldPlaybook -Removals WinverRequirement, Verification",
"script": "& \"$(Join-Path '${workspaceFolder}' 'src/local-build.ps1')\" -AddLiveLog -ReplaceOldPlaybook -Removals WinverRequirement, Verification",
"cwd": "${workspaceFolder}/src/playbook",
"args": []
},
{
"type": "PowerShell",
"request": "launch",
"name": "Build Playbook (Test w/o deps)",
"script": "& '${workspaceFolder}/src/local-build.ps1' -AddLiveLog -ReplaceOldPlaybook -Removals Dependencies, WinverRequirement, Verification",
"script": "& \"$(Join-Path '${workspaceFolder}' 'src/local-build.ps1')\" -AddLiveLog -ReplaceOldPlaybook -Removals Dependencies, WinverRequirement, Verification",
"cwd": "${workspaceFolder}/src/playbook",
"args": []
},
{
"type": "PowerShell",
"request": "launch",
"name": "Build Playbook (Release)",
"script": "& '${workspaceFolder}/src/local-build.ps1'",
"script": "& \"$(Join-Path '${workspaceFolder}' 'src/local-build.ps1')\"",
"cwd": "${workspaceFolder}/src/playbook",
"args": []
}
Expand Down
42 changes: 42 additions & 0 deletions src/local-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,48 @@ function Seperator {
return $args -replace '\\', "$([IO.Path]::DirectorySeparatorChar)"
}

# Adds Atlas PSModulesPath to profile for the PowerShell Extension
$userEnv = [System.EnvironmentVariableTarget]::User
if ($psEditor.Workspace.Path -and ([Environment]::GetEnvironmentVariable('LOCALBUILD_DONT_ASK_FOR_MODULES', $userEnv) -ne "$true")) {
function DontAsk {
[Environment]::SetEnvironmentVariable('LOCALBUILD_DONT_ASK_FOR_MODULES', $true, $userEnv)
}

$title = 'Adding to PowerShell profile'
$description = @"
Atlas includes some PowerShell modules by default that aren't usually recognised by the VSCode PowerShell extension.
Would you like to add to your PowerShell profile to automatically recognise these modules when developing Atlas?`n`n
"@
switch ($host.ui.PromptForChoice($title, $description, ('&Yes', '&No', "&Don't ask me again"), 0)) {
0 {
if (!(Test-Path $PROFILE)) {
New-Item -Path $PROFILE -ItemType File -Force | Out-Null
}

Add-Content -Path $PROFILE -Value @'
#--LOCAL-BUILD-MODULES-START--#
$workspace = $psEditor.Workspace.Path
$modulesFile = "$workspace\.atlasPsModulesPath"
if ([bool](Test-Path 'Env:\VSCODE_*') -and (Test-Path $workspace) -and (Test-Path $modulesFile)) {
$modulePath = Join-Path $workspace (Get-Content $modulesFile -Raw)
if (!(Test-Path $modulePath -PathType Container)) {
Write-Warning "Couldn't find module path specified in '$modulesFile', no Atlas modules can be loaded."
} else {
$env:PSModulePath += [IO.Path]::PathSeparator + $modulePath
}
}
#--LOCAL-BUILD-MODULES-END--#
'@

DontAsk
& $PROFILE
}
2 {
DontAsk
}
}
}

# check 7z
if (Get-Command '7z' -EA 0) {
$7zPath = '7z'
Expand Down

0 comments on commit 04a26ac

Please sign in to comment.