Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env pwsh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No copyright header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added. Wasn't sure which should be on top. Let me know if I have it wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My testing indicates that the shebang has to be on the first line of the script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, shebang must be first line. This would be the exception to the copyright header rule being first.

# 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
}
}