From 0b2286f0edd7b3fbcb3360474b526666bfc18ddb Mon Sep 17 00:00:00 2001 From: Roman Kuzmin Date: Thu, 29 May 2014 19:40:05 +0100 Subject: [PATCH] v2.9.8 --- .build.ps1 | 1 + Invoke-Build.ps1 | 6 ++--- README.md | 12 +++++++++- Release-Notes.md | 17 ++++++++++++++ Tasks/File/File.build.ps1 | 48 ++++++++++++++++++++++++++++++++++++++ Tasks/File/File.tasks.ps1 | 49 +++++++++++++++++++++++++++++++++++++++ ib.cmd | 12 ++++++++++ 7 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 Tasks/File/File.build.ps1 create mode 100644 Tasks/File/File.tasks.ps1 create mode 100644 ib.cmd diff --git a/.build.ps1 b/.build.ps1 index 1583481..680b811 100644 --- a/.build.ps1 +++ b/.build.ps1 @@ -55,6 +55,7 @@ task Package ConvertMarkdown, Help, GitStatus, { # copy files Copy-Item -Destination z\tools ` Convert-psake.ps1, + ib.cmd, Invoke-Build.ps1, Invoke-Build-Help.xml, Invoke-Builds.ps1, diff --git a/Invoke-Build.ps1 b/Invoke-Build.ps1 index efd543a..2772d5b 100644 --- a/Invoke-Build.ps1 +++ b/Invoke-Build.ps1 @@ -227,11 +227,11 @@ function Write-Build([ConsoleColor]$Color, [string]$Text) { } #.ExternalHelp Invoke-Build-Help.xml -function Get-BuildVersion {[Version]'2.9.7'} +function Get-BuildVersion {[Version]'2.9.8'} if ($MyInvocation.InvocationName -eq '.') { return @' -Invoke-Build 2.9.7 +Invoke-Build 2.9.8 Copyright (c) 2011-2014 Roman Kuzmin Add-BuildTask (task) @@ -463,7 +463,7 @@ function *Task { if (1 -eq ${*i}) {${*i} = *IO} if (${*i}) { - Write-Build 11 ${*i} + Write-Build 8 ${*i} continue } diff --git a/README.md b/README.md index 7117a90..561140e 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ are for built-in help, parallel builds, task visualization, and etc. Extras +* *ib.cmd* is Invoke-Build helper for cmd.exe * *Convert-psake.ps1* converts psake build scripts * *Invoke-TaskFromISE.ps1* invokes a task from ISE * *Show-BuildTree.ps1* shows task trees as text @@ -60,7 +61,16 @@ subdirectory *"tools"*. Copy *Invoke-Build.ps1*, *Invoke-Build-Help.xml*, and optionally other scripts to a directory in the path. As a result, the engine is called from PowerShell -as `Invoke-Build` and help for `Get-Help` is available. +as `Invoke-Build` and help for `Get-Help` is available. Note that this is not +mandatory, any location is fine but in this case invocation requires a path, +absolute or relative. + +With cmd.exe use the helper *ib.cmd*. For similar experience in interactive +PowerShell use an alias `ib` defined in the PowerShell profile (`$Profile`) + + Set-Alias ib \Invoke-Build.ps1 + +`\` may be omitted in the script is in the system path. ## Getting help diff --git a/Release-Notes.md b/Release-Notes.md index 23962c0..fb018cc 100644 --- a/Release-Notes.md +++ b/Release-Notes.md @@ -2,6 +2,23 @@ Invoke-Build Release Notes ========================== +## v2.9.8 + +Users ask for a common cmd.exe helper. I was reluctant for some reasons but now +is a good time, perhaps. Here is the proposal based on my own practice. + +- *ib.cmd* is the proposed Invoke-Build helper for cmd.exe. +- For similar experience in interactive PowerShell use an alias `ib`. + +Note that scripts should continue to use the command `Invoke-Build`. The `ib` +commands should be used with cmd.exe (*ib.cmd*) and in interactive PowerShell +(alias of *Invoke-Build.ps1* defined in the profile). + +Custom tasks + +- Added the sample custom rake-like task `file`. It is not a big deal but it + still may be useful. Besides, it comes with examples of incremental tasks. + ## v2.9.7 Task help (*experimentally*). The *Jobs* is an array, not a text. With diff --git a/Tasks/File/File.build.ps1 b/Tasks/File/File.build.ps1 new file mode 100644 index 0000000..5930448 --- /dev/null +++ b/Tasks/File/File.build.ps1 @@ -0,0 +1,48 @@ + +<# +.Synopsis + Example of the custom file-task. + +.Description + This script is a demo of incremental tasks and custom file-tasks. + See "File.tasks.ps1" for the details of "file". + + A file-task is slightly easier to compose than similar "task". It is not a + big deal but if incremental tasks are used often then "file" may be useful. + +.Example + Invoke-Build * File.build.ps1 + + On the first run all tasks work and create "Task*.log" files. On next runs + tasks are either skipped or invoked as soon as temp files are updated. +#> + +# Import file-task. +. .\File.tasks.ps1 + +# Gets *.tmp files from the temp directory. Used in two tasks. +$GetTmpFiles = { [System.IO.Directory]::GetFiles($env:TEMP, '*.tmp') } + +# Synopsis: Log temp files using "task". +task Task1 -Inputs $GetTmpFiles -Outputs Task1.log { + "Doing $($Task.Name)..." + $Inputs > $Outputs +} + +# Synopsis: Log temp files using "file". +file Task2 $GetTmpFiles Task2.log { + "Doing $($Task.Name)..." + $Inputs > $Outputs +} + +# Synopsis: Partial "task" references "file" and uses its output as input. +task Task3 -Partial -Inputs Task2.log -Outputs Task3.log Task2, {process{ + "Doing $($Task.Name)..." + Get-Content $_ > $2 +}} + +# Synopsis: Partial "file" references "task" and uses its output as input. +file Task4 -Partial Task1.log Task4.log Task1, {process{ + "Doing $($Task.Name)..." + Get-Content $_ > $2 +}} diff --git a/Tasks/File/File.tasks.ps1 b/Tasks/File/File.tasks.ps1 new file mode 100644 index 0000000..45852ba --- /dev/null +++ b/Tasks/File/File.tasks.ps1 @@ -0,0 +1,49 @@ + +<# +.Synopsis + Defines the custom task "file". + +.Description + Build scripts dot-source this script in order to use the task "file". + + A file-task is a task with simplified syntax similar to Rake "file". Inputs + and Outputs are mandatory positional parameters, the names may be omitted. + + File-task parameters: + Name, Jobs, If, Partial, Data, Done, Source - as usual + Inputs, Outputs - as usual but mandatory positional + + Script scope names: + Alias: file + Function: Add-FileTask + +.Example + > + # Dot-source "file" definitions + . \File.tasks.ps1 + + # Add "file" tasks + file Task1 { + ... + } +#> + +# New DSL word. +Set-Alias file Add-FileTask + +# Wrapper of "task" which adds a customized task used as "file". +# Mind setting "Source" for error messages and help comments. +function Add-FileTask( + [Parameter(Position=0, Mandatory=1)][string]$Name, + [Parameter(Position=1, Mandatory=1)]$Inputs, + [Parameter(Position=2, Mandatory=1)]$Outputs, + [Parameter(Position=3)][object[]]$Jobs, + $If=1, + $Data, + $Done, + $Source = $MyInvocation, + [switch]$Partial +) +{ + task @PSBoundParameters +} diff --git a/ib.cmd b/ib.cmd new file mode 100644 index 0000000..487aca2 --- /dev/null +++ b/ib.cmd @@ -0,0 +1,12 @@ + +@echo off +rem ib.cmd - Invoke-Build helper for cmd.exe +rem ib.cmd must be in the same directory as Invoke-Build.ps1 + +if "%1"=="?" goto list + +PowerShell.exe -NoProfile -ExecutionPolicy Bypass "& '%~dp0\Invoke-Build.ps1'" %* +exit /B %errorlevel% + +:list +PowerShell.exe -NoProfile -ExecutionPolicy Bypass "& '%~dp0\Invoke-Build.ps1'" %* "| Format-Table -AutoSize"