diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..73159c40a4 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,115 @@ +#!/usr/bin/env pwsh +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +param( + [Parameter(ParameterSetName="Bootstrap")] + [switch] + $Bootstrap, + + [Parameter(ParameterSetName="Build")] + [switch] + $Clean, + + [Parameter(ParameterSetName="Build")] + [switch] + $Test +) + +$NeededTools = @{ + VSCode = "Visual Studio Code" + NodeJS = "Node.js 6.0 or higher" + PowerShellGet = "PowerShellGet latest" + InvokeBuild = "InvokeBuild latest" +} + +function needsVSCode () { + try { + $vscodeVersion = (code -v) + if (-not $vscodeVersion) { + Throw + } + } catch { + try { + $vscodeInsidersVersion = (code-insiders -v) + if (-not $vscodeInsidersVersion) { + Throw + } + } catch { + return $true + } + } + return $false +} + +function needsNodeJS () { + try { + $nodeJSVersion = (node -v) + + } catch { + return $true + } + return ($nodeJSVersion.Substring(1,1) -lt 6) +} + +function needsPowerShellGet () { + if (Get-Module -ListAvailable -Name PowerShellGet) { + return $false + } + return $true +} + +function needsInvokeBuild () { + if (Get-Module -ListAvailable -Name InvokeBuild) { + return $false + } + return $true +} + +function getMissingTools () { + $missingTools = @() + + if (needsVSCode) { + $missingTools += $NeededTools.VSCode + } + if (needsNodeJS) { + $missingTools += $NeededTools.NodeJS + } + if (needsPowerShellGet) { + $missingTools += $NeededTools.PowerShellGet + } + if (needsInvokeBuild) { + $missingTools += $NeededTools.InvokeBuild + } + + return $missingTools +} + +function hasMissingTools () { + return ((getMissingTools).Count -gt 0) +} + +if ($Bootstrap) { + $string = "Here is what your environment is missing:`n" + $missingTools = getMissingTools + if (($missingTools).Count -eq 0) { + $string += "* nothing!`n`n Run this script without a flag to build or a -Clean to clean." + } else { + $missingTools | ForEach-Object {$string += "* $_`n"} + $string += "`nAll instructions for installing these tools can be found on VSCode PowerShell's Github:`n" ` + + "https://github.com/PowerShell/vscode-powershell/blob/master/docs/development.md" + } + Write-Host "`n$string`n" +} elseif(hasMissingTools) { + Write-Host "You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are." +} else { + if($Clean) { + Invoke-Build Clean + } + + Invoke-Build Build + + if($Test) { + Invoke-Build Test + } +}