1+ # #####################################################################
2+ # # NAMESPACE IMPORTS
3+ # #####################################################################
4+ using namespace Cake.Bridge
5+ using namespace Cake.Common
6+ using namespace Cake.Common.Diagnostics
7+ using namespace Cake.Common.IO
8+ using namespace Cake.Common.Tools.DotNetCore
9+ using namespace Cake.Common.Tools.DotNetCore.Build
10+ using namespace Cake.Common.Tools.DotNetCore.Pack
11+ using namespace Cake.Core
12+ using namespace Cake.Core.IO
13+ using namespace Cake.Core.Scripting
14+ using namespace System
15+ using namespace System.Linq
16+ $ErrorActionPreference = " Stop"
17+
18+ # #####################################################################
19+ # # FETCH DEPENDENCIES
20+ # #####################################################################
21+ [string ] $CakeVersion = " 0.20.0"
22+ [string ] $BridgeVersion = " 0.0.5-alpha"
23+
24+ [string ] $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
25+ [string ] $ToolsPath = Join-Path $PSScriptRoot " tools"
26+ [string ] $CakeCorePath = Join-Path $ToolsPath " Cake.Core.$CakeVersion /lib/net45/Cake.Core.dll"
27+ [string ] $CakeCommonPath = Join-Path $ToolsPath " Cake.Common.$CakeVersion /lib/net45/Cake.Common.dll"
28+ [string ] $CakeBridgePath = Join-Path $ToolsPath " Cake.Bridge.$BridgeVersion /lib/net45/Cake.Bridge.dll"
29+
30+ Add-Type - AssemblyName System.IO.Compression.FileSystem
31+ Function Unzip
32+ {
33+ param ([string ]$zipfile , [string ]$outpath )
34+
35+ [System.IO.Compression.ZipFile ]::ExtractToDirectory($zipfile , $outpath )
36+ }
37+
38+ Function NugetInstall
39+ {
40+ param (
41+ [string ]$PackageId ,
42+ [string ]$PackageVersion ,
43+ [string ]$ToolsPath
44+ )
45+ (New-Object System.Net.WebClient).DownloadFile(" https://www.nuget.org/api/v2/package/$PackageId /$PackageVersion " , " $ToolsPath \$PackageId .zip" )
46+ Unzip " $ToolsPath \$PackageId .zip" " $ToolsPath /$PackageId .$PackageVersion "
47+ Remove-Item " $ToolsPath \$PackageId .zip"
48+ }
49+ if (! (Test-Path $ToolsPath ))
50+ {
51+ New-Item - Path $ToolsPath - Type directory | Out-Null
52+ }
53+
54+ if (! (Test-Path $CakeCorePath ))
55+ {
56+ NugetInstall ' Cake.Core' $CakeVersion $ToolsPath
57+ }
58+
59+ if (! (Test-Path $CakeCommonPath ))
60+ {
61+ NugetInstall ' Cake.Common' $CakeVersion $ToolsPath
62+ }
63+
64+ if (! (Test-Path $CakeBridgePath ))
65+ {
66+ NugetInstall ' Cake.Bridge' $BridgeVersion $ToolsPath
67+ }
68+
69+ # #####################################################################
70+ # # Reference DEPENDENCIES
71+ # #####################################################################
72+ Add-Type - Path $CakeCorePath
73+ Add-Type - Path $CakeCommonPath
74+ Add-Type - Path $CakeBridgePath
75+
76+ # #####################################################################
77+ # # GLOBALS / HELPERS
78+ # #####################################################################
79+ [IScriptHost ] $bridge = [CakeBridge ]::GetScriptHost()
80+ [ICakeContext ] $context = $bridge.Context
81+
82+ Function Task {
83+ [OutputType (' Cake.Core.CakeTaskBuilder' )]
84+ [cmdletbinding ()]
85+ Param (
86+ [parameter (ValueFromPipeline )]
87+ [String ]$TaskName
88+ )
89+
90+ return $bridge.Task ($TaskName )
91+ }
92+ Function Does {
93+ [OutputType (' Cake.Core.CakeTaskBuilder' )]
94+ [cmdletbinding ()]
95+ Param (
96+ [parameter (ValueFromPipeline )]
97+ $Task ,
98+ [System.Action ] $Action
99+ )
100+
101+ return [CakeTaskBuilderExtensions ]::Does($Task , $Action )
102+ }
103+
104+ Function IsDependentOn {
105+ [OutputType (' Cake.Core.CakeTaskBuilder' )]
106+ [cmdletbinding ()]
107+ Param (
108+ [parameter (ValueFromPipeline )]
109+ $Task ,
110+ $Dependency
111+ )
112+
113+ return [CakeTaskBuilderExtensions ]::IsDependentOn($Task , $Dependency )
114+ }
115+
116+ Function RunTarget {
117+ [cmdletbinding ()]
118+ Param (
119+ [parameter (ValueFromPipeline )]
120+ $Task
121+ )
122+
123+ $bridge.RunTarget ($Task.Task.Name ) | Out-Null
124+ }
125+
126+ Function Setup {
127+ param ([Action [ICakeContext ]] $action )
128+ $bridge.Setup ($action )
129+ }
130+
131+ Function Teardown {
132+ param ([Action [ITeardownContext ]] $action )
133+ $bridge.Teardown ($action )
134+ }
0 commit comments