diff --git a/build.yaml b/build.yaml new file mode 100644 index 0000000..40b7a88 --- /dev/null +++ b/build.yaml @@ -0,0 +1,7 @@ +build: + source: .\src + output: .\output\bob + stages: + - clean + - copy + - test diff --git a/readme.md b/readme.md index 6dd1ba8..6f5805d 100644 --- a/readme.md +++ b/readme.md @@ -40,6 +40,13 @@ BuildJob src dst { TestStg } | Select stages +Stages +------ +{Clean, Copy, Test} + +# YAML Config +PS> New-BuildFromYaml .\build.yaml | Select stages + Stages ------ {Clean, Copy, Test} diff --git a/src/New-BuildFromYaml.ps1 b/src/New-BuildFromYaml.ps1 new file mode 100644 index 0000000..8fcc65c --- /dev/null +++ b/src/New-BuildFromYaml.ps1 @@ -0,0 +1,28 @@ +function New-BuildFromYaml { + [CmdletBinding()] + param ( + # Specifies a path to one or more locations. + [Parameter(Mandatory=$true, + Position=0, + ParameterSetName="ParameterSetName", + ValueFromPipeline=$true, + ValueFromPipelineByPropertyName=$true, + HelpMessage="Path to one or more locations.")] + [Alias("PSPath")] + [ValidateNotNullOrEmpty()] + [string[]] + $Path + ) + + + $config = Get-Content -Path $Path -Raw | ConvertFrom-Yaml + + $b = New-BuildJob -Path $config.build.source -Output $config.build.output + + ForEach ($stageName in $config.build.stages) { + $stageObject = New-Object -TypeName $stageName + $b | Add-BuildStage -Stage $stageObject | Out-Null + } + + Write-Output -InputObject $b +} \ No newline at end of file diff --git a/src/bob.psd1 b/src/bob.psd1 index 649bc2e..48e6017 100644 Binary files a/src/bob.psd1 and b/src/bob.psd1 differ diff --git a/src/bob.psm1 b/src/bob.psm1 index 26d4198..0d07ecc 100644 --- a/src/bob.psm1 +++ b/src/bob.psm1 @@ -136,6 +136,7 @@ $global:BUILDER = New-Object -TypeName Object . $PSScriptRoot\Invoke-Builder.ps1 . $PSScriptRoot\Write-BuilderResults.ps1 . $PSScriptRoot\DSL.ps1 +. $PSScriptRoot\New-BuildFromYaml.ps1 # Aliases if (!(Get-Alias -Name :Clean -ErrorAction SilentlyContinue)) { New-Alias -Name :Clean -Value Add-StageClean } diff --git a/testStrategy.ps1 b/testStrategy.ps1 new file mode 100644 index 0000000..acb9feb --- /dev/null +++ b/testStrategy.ps1 @@ -0,0 +1,34 @@ +<# + open/close principle + be open for extension, but closed for modification + an entity can allow its behaviour to be extended without modifying its source code +#> + +Import-Module .\src\bob.psd1 -Force + +function testStrategy { + param($p) + + $name = "Invoke-Build{0}" -f $p.gettype().name + + if (!(Get-Command $name -ErrorAction SilentlyContinue)) { + return "$name not found" + } + + "begin" + "call $name" + "end" + "" +} + +function Invoke-BuildScriptBlock {} +function Invoke-BuildString {} +function Invoke-BuildTestThis {} + +class TestThis {} +class TestThis1 {} + +testStrategy {} +testStrategy .\quotes.xml +testStrategy ([TestThis]::new()) +testStrategy ([TestThis1]::new()) \ No newline at end of file