Skip to content

Commit

Permalink
Added cake.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Jul 7, 2017
1 parent 42481c9 commit f61731a
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### New in 0.0.5 (Released 2017/06/30)
* Added cake.ps1

### New in 0.0.4 (Released 2017/06/30)
* Added GetScriptHost to get new instance of IScriptHost

Expand Down
4 changes: 3 additions & 1 deletion src/Cake.Bridge.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ VisualStudioVersion = 15.0.26228.9
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Bridge", "Cake.Bridge\Cake.Bridge.csproj", "{C99AE694-B461-49EC-9633-D72ADC4AAFE8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeConsoleRunner", "CakeConsoleRunner\CakeConsoleRunner.csproj", "{B806E492-A0E3-490C-96FA-E9DBFCD10CB1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CakeConsoleRunner", "CakeConsoleRunner\CakeConsoleRunner.csproj", "{B806E492-A0E3-490C-96FA-E9DBFCD10CB1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{67F8B8E2-34F7-4CCB-850C-8DC5651B1FB1}"
ProjectSection(SolutionItems) = preProject
..\build.csx = ..\build.csx
cake.fsx = cake.fsx
cake.ps1 = cake.ps1
EndProjectSection
EndProject
Global
Expand Down
4 changes: 4 additions & 0 deletions src/Cake.Bridge/Cake.Bridge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<Pack>true</Pack>
<PackagePath>content\</PackagePath>
</Content>
<Content Include="..\cake.ps1">
<Pack>true</Pack>
<PackagePath>content\</PackagePath>
</Content>
</ItemGroup>

</Project>
134 changes: 134 additions & 0 deletions src/cake.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
######################################################################
## NAMESPACE IMPORTS
######################################################################
using namespace Cake.Bridge
using namespace Cake.Common
using namespace Cake.Common.Diagnostics
using namespace Cake.Common.IO
using namespace Cake.Common.Tools.DotNetCore
using namespace Cake.Common.Tools.DotNetCore.Build
using namespace Cake.Common.Tools.DotNetCore.Pack
using namespace Cake.Core
using namespace Cake.Core.IO
using namespace Cake.Core.Scripting
using namespace System
using namespace System.Linq
$ErrorActionPreference = "Stop"

######################################################################
## FETCH DEPENDENCIES
######################################################################
[string] $CakeVersion = "0.20.0"
[string] $BridgeVersion = "0.0.5-alpha"

[string] $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
[string] $ToolsPath = Join-Path $PSScriptRoot "tools"
[string] $CakeCorePath = Join-Path $ToolsPath "Cake.Core.$CakeVersion/lib/net45/Cake.Core.dll"
[string] $CakeCommonPath = Join-Path $ToolsPath "Cake.Common.$CakeVersion/lib/net45/Cake.Common.dll"
[string] $CakeBridgePath = Join-Path $ToolsPath "Cake.Bridge.$BridgeVersion/lib/net45/Cake.Bridge.dll"

Add-Type -AssemblyName System.IO.Compression.FileSystem
Function Unzip
{
param([string]$zipfile, [string]$outpath)

[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

Function NugetInstall
{
param(
[string]$PackageId,
[string]$PackageVersion,
[string]$ToolsPath
)
(New-Object System.Net.WebClient).DownloadFile("https://www.nuget.org/api/v2/package/$PackageId/$PackageVersion", "$ToolsPath\$PackageId.zip")
Unzip "$ToolsPath\$PackageId.zip" "$ToolsPath/$PackageId.$PackageVersion"
Remove-Item "$ToolsPath\$PackageId.zip"
}
if (!(Test-Path $ToolsPath))
{
New-Item -Path $ToolsPath -Type directory | Out-Null
}

if (!(Test-Path $CakeCorePath))
{
NugetInstall 'Cake.Core' $CakeVersion $ToolsPath
}

if (!(Test-Path $CakeCommonPath))
{
NugetInstall 'Cake.Common' $CakeVersion $ToolsPath
}

if (!(Test-Path $CakeBridgePath))
{
NugetInstall 'Cake.Bridge' $BridgeVersion $ToolsPath
}

######################################################################
## Reference DEPENDENCIES
######################################################################
Add-Type -Path $CakeCorePath
Add-Type -Path $CakeCommonPath
Add-Type -Path $CakeBridgePath

######################################################################
## GLOBALS / HELPERS
######################################################################
[IScriptHost] $bridge = [CakeBridge]::GetScriptHost()
[ICakeContext] $context = $bridge.Context

Function Task {
[OutputType('Cake.Core.CakeTaskBuilder')]
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline)]
[String]$TaskName
)

return $bridge.Task($TaskName)
}
Function Does {
[OutputType('Cake.Core.CakeTaskBuilder')]
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline)]
$Task,
[System.Action] $Action
)

return [CakeTaskBuilderExtensions]::Does($Task, $Action)
}

Function IsDependentOn {
[OutputType('Cake.Core.CakeTaskBuilder')]
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline)]
$Task,
$Dependency
)

return [CakeTaskBuilderExtensions]::IsDependentOn($Task, $Dependency)
}

Function RunTarget {
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline)]
$Task
)

$bridge.RunTarget($Task.Task.Name) | Out-Null
}

Function Setup {
param([Action[ICakeContext]] $action)
$bridge.Setup($action)
}

Function Teardown {
param([Action[ITeardownContext]] $action)
$bridge.Teardown($action)
}

0 comments on commit f61731a

Please sign in to comment.