From 542e156d4d945242cc3e6f38df9e473648a2f893 Mon Sep 17 00:00:00 2001 From: Luke Schlather Date: Mon, 14 Oct 2019 17:00:52 -0700 Subject: [PATCH 1/5] Some changes to make it clearer (to me at least) how to build this thing. --- .gitignore | 2 +- README.md | 18 +++++++---- build/BuildExtension.ps1 | 33 ++++++++++---------- build/BuildFunctions.psm1 | 63 ++++++++++++++++++++------------------- package.json | 28 +++++++++++++++++ 5 files changed, 91 insertions(+), 53 deletions(-) create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 22f3a5c..9e0b378 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ obj/ *.taskkey bin/ -*/node_modules/ +node_modules typings.json */typings/ deploy-gae-build-task/#task.json# diff --git a/README.md b/README.md index 2997441..f1c3e45 100644 --- a/README.md +++ b/README.md @@ -35,15 +35,21 @@ Questions can be asked on StackOverflow - [PowerShell][PowerShell]: Installed by default on modern windows platforms. - [Node.js][Node]: Download and install from the website. - [npm][npm]: Installed along with Node.js. - - [TypeScript][TypeScript]: Install with `npm install -g typescript` - - [tfx][tfs-cli]: The tfs cli. Install with `npm install -g tfx-cli` - - [mocha][mocha]: A JavaScript test runner. `npm install -g mocha` - - [ts-node]: Used by mocha to run TypeScript directly. `npm install -g ts-node` - - [nyc][nyc]: The Istanbul code coverage tool. Install with `npm install -g nyc` + - [MSBuild][https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2019]: Installed with Visual Studio. Visual Studio does not add MSBuild to the path. You can make msbuild resolve in powershell by doing this: + +``` +New-Alias vswhere "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" +$msbuildPath = (ls ((vswhere -latest -property InstallationPath) + "\MSBuild\*\Bin\MSBuild.exe"))[0].FullName +New-Alias msbuild $msbuildPath +``` + +### Node Modules + +Install the required node modules by running `npm install` in this directory. ### Build Script -Execute build script `./build/BuildExtension.ps1`. It will download needed +Execute build script `pwsh ./build/BuildExtension.ps1`. It will download needed modules, build the common files and build tasks, and then package everything into `./bin/Google Cloud Tools.google-cloud-tfs-.vsix`. diff --git a/build/BuildExtension.ps1 b/build/BuildExtension.ps1 index 69086d3..c719893 100644 --- a/build/BuildExtension.ps1 +++ b/build/BuildExtension.ps1 @@ -1,18 +1,16 @@ -<## - # Copyright 2017 Google Inc. - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ##> +# Copyright 2017 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. [CmdletBinding()] Param( @@ -20,10 +18,14 @@ Param( [switch]$SkipInit, [switch]$SkipCompile, [switch]$SkipTest, + [switch]$SkipPackage, [string]$Publisher, [string]$Version ) +Set-StrictMode -Version 3.0 +$ErrorActionPreference = "Stop" +$env:PATH = "$PSScriptRoot\..\node_modules\.bin\;${env:PATH}" pushd (Join-Path $MyInvocation.MyCommand.Path ..) $functionsModule = Import-Module ./BuildFunctions.psm1 -PassThru -Verbose:$false -ArgumentList $VerbosePreference @@ -67,5 +69,4 @@ try { } } finally { popd - $functionsModule | Remove-Module -Verbose:$false } diff --git a/build/BuildFunctions.psm1 b/build/BuildFunctions.psm1 index 9d07fbc..55a2862 100644 --- a/build/BuildFunctions.psm1 +++ b/build/BuildFunctions.psm1 @@ -1,22 +1,23 @@ -<## - # Copyright 2017 Google Inc. - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ##> +# Copyright 2017 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + Param( $VerbosePreference ) +$env:PATH = "$PSScriptRoot\..\node_modules\.bin\;${env:PATH}" + function Initialize-All([string[]]$tasks) { Write-Host "Initialize modules and tasks" Initialize-PsTask "install-cloud-sdk-build-task" @@ -70,21 +71,23 @@ function Invoke-AllMochaTests([string[]]$tasks, [string]$reporter, [switch]$thro function Invoke-MochaTest([string]$task, [string]$reporter) { Write-Host "Testing TypeScript task $task" pushd $task - try { - # nyc is the javascript code coverage checker. - # mocha is the javascript test runner. - $nycArgs = "--reporter", "json", "mocha" - if ($reporter) { - $nycArgs += "--reporter", $reporter - } - Write-Verbose "Running: nyc $nycArgs" - nyc $nycArgs - if ($LASTEXITCODE -ne 0) { - throw "mocha failed for task $task" - } - } finally { - popd + echo $env:path + which mocha + which nyc + + # nyc is the javascript code coverage checker. + # mocha is the javascript test runner. + $nycArgs = "--reporter", "json", "mocha" + if ($reporter) { + $nycArgs += "--reporter", $reporter + } + pwd + Write-Host "Running: nyc $nycArgs" + nyc @nycArgs + + if ($LASTEXITCODE -ne 0) { + throw "mocha failed for task $task" } } @@ -178,7 +181,7 @@ function Merge-ExtensionPackage([string] $publisher, [string] $version) { $tfxArgs += "--overrides-file", $overridesFile } Write-Verbose "Running: tfx $tfxArgs" - tfx $tfxArgs + & tfx @tfxArgs if ($overridesFile) { rm $overridesFile } diff --git a/package.json b/package.json new file mode 100644 index 0000000..4498033 --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "GoogleCloudPlatform.google-cloud-tfs", + "version": "0.0.9", + "description": "A collection of TFS build tasks to run Google Cloud Platform tools.", + "license": "Apache-2.0", + "author": "Google Cloud Tools", + "repository": "https://github.com/GoogleCloudPlatform/google-cloud-tfs.git", + "main": "run.js", + "dependencies": { + "typescript": "^3.6.4" + }, + "scripts": { + "build": "pwsh ./build/BuildExtension.ps1" + }, + "devDependencies": { + "typescript": "^3.6.4", + "tfx-cli": "^0.7", + "ts-node": "^8.4.1", + "@types/mocha": "^2.2.40", + "@types/mockery": "^1.4.29", + "@types/node": "^7.0.6", + "@types/q": "0.0.32", + "mocha": "^3.2.0", + "mockery": "^2.1.0", + "typemoq": "^2.0.1", + "nyc": "^14.1.1" + } +} From 9e85432686878cd245d776eeaf25b419a4dc2235 Mon Sep 17 00:00:00 2001 From: Luke Schlather Date: Tue, 15 Oct 2019 07:23:58 -0700 Subject: [PATCH 2/5] just run the build script --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index f1c3e45..26490ee 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,9 @@ $msbuildPath = (ls ((vswhere -latest -property InstallationPath) + "\MSBuild\*\B New-Alias msbuild $msbuildPath ``` -### Node Modules - -Install the required node modules by running `npm install` in this directory. - ### Build Script -Execute build script `pwsh ./build/BuildExtension.ps1`. It will download needed +Execute build script `npm run-script build`. It will download needed modules, build the common files and build tasks, and then package everything into `./bin/Google Cloud Tools.google-cloud-tfs-.vsix`. From 6f08ab158b8e2cf9a94237c5e8d6fef30fbc69d7 Mon Sep 17 00:00:00 2001 From: Luke Schlather Date: Tue, 15 Oct 2019 17:08:22 -0700 Subject: [PATCH 3/5] Clean up debugging code --- build/BuildFunctions.psm1 | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/build/BuildFunctions.psm1 b/build/BuildFunctions.psm1 index 55a2862..606894a 100644 --- a/build/BuildFunctions.psm1 +++ b/build/BuildFunctions.psm1 @@ -1,11 +1,11 @@ # Copyright 2017 Google Inc. -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -71,21 +71,20 @@ function Invoke-AllMochaTests([string[]]$tasks, [string]$reporter, [switch]$thro function Invoke-MochaTest([string]$task, [string]$reporter) { Write-Host "Testing TypeScript task $task" pushd $task + try { + # nyc is the javascript code coverage checker. + # mocha is the javascript test runner. + $nycArgs = "--reporter", "json", "mocha" + if ($reporter) { + $nycArgs += "--reporter", $reporter + } - echo $env:path - which mocha - which nyc - - # nyc is the javascript code coverage checker. - # mocha is the javascript test runner. - $nycArgs = "--reporter", "json", "mocha" - if ($reporter) { - $nycArgs += "--reporter", $reporter + Write-Host "Running: nyc $nycArgs" + nyc @nycArgs + } finally { + popd } - pwd - Write-Host "Running: nyc $nycArgs" - nyc @nycArgs - + if ($LASTEXITCODE -ne 0) { throw "mocha failed for task $task" } From 77e34c820a7a78e32f19c8252887fbb104d87fe2 Mon Sep 17 00:00:00 2001 From: Luke Schlather Date: Tue, 15 Oct 2019 17:10:29 -0700 Subject: [PATCH 4/5] formatting, ordering --- build/BuildFunctions.psm1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/build/BuildFunctions.psm1 b/build/BuildFunctions.psm1 index 606894a..6dfb453 100644 --- a/build/BuildFunctions.psm1 +++ b/build/BuildFunctions.psm1 @@ -79,14 +79,13 @@ function Invoke-MochaTest([string]$task, [string]$reporter) { $nycArgs += "--reporter", $reporter } + if ($LASTEXITCODE -ne 0) { + throw "mocha failed for task $task" + } Write-Host "Running: nyc $nycArgs" nyc @nycArgs } finally { - popd - } - - if ($LASTEXITCODE -ne 0) { - throw "mocha failed for task $task" + popd } } From 6204e249ebe76b1a98100af04db812c4c143add6 Mon Sep 17 00:00:00 2001 From: Luke Schlather Date: Tue, 15 Oct 2019 17:11:44 -0700 Subject: [PATCH 5/5] fix ordering --- build/BuildFunctions.psm1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/BuildFunctions.psm1 b/build/BuildFunctions.psm1 index 6dfb453..eb40268 100644 --- a/build/BuildFunctions.psm1 +++ b/build/BuildFunctions.psm1 @@ -79,11 +79,12 @@ function Invoke-MochaTest([string]$task, [string]$reporter) { $nycArgs += "--reporter", $reporter } + Write-Host "Running: nyc $nycArgs" + nyc @nycArgs + if ($LASTEXITCODE -ne 0) { throw "mocha failed for task $task" } - Write-Host "Running: nyc $nycArgs" - nyc @nycArgs } finally { popd }