diff --git a/.atlasPsModulesPath b/.atlasPsModulesPath new file mode 100644 index 0000000000..33c38c7427 --- /dev/null +++ b/.atlasPsModulesPath @@ -0,0 +1 @@ +src\playbook\Executables\AtlasModules\Scripts\Modules \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 10ff03de6d..ba3c301a41 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "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": [] }, @@ -13,7 +13,7 @@ "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": [] }, @@ -21,7 +21,7 @@ "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": [] } diff --git a/src/local-build.ps1 b/src/local-build.ps1 index 11f76741d8..1d6a1700d2 100644 --- a/src/local-build.ps1 +++ b/src/local-build.ps1 @@ -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'