Skip to content

Commit 6f9cbcf

Browse files
committed
Add Write-Build alias print, close #240
1 parent 999c2f1 commit 6f9cbcf

31 files changed

Lines changed: 96 additions & 102 deletions

.build.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ task module version, markdown, help, {
5858

5959
# copy the module folder
6060
$dir = "$BuildRoot\z\InvokeBuild"
61-
Copy-Item InvokeBuild $dir -Recurse
61+
Copy-Item Content $dir -Recurse
6262

6363
# copy files without Invoke-Build.ps1
6464
Copy-Item -Destination $dir $(
@@ -88,6 +88,9 @@ task module version, markdown, help, {
8888
Description = 'Build and test automation in PowerShell'
8989
PowerShellVersion = '3.0'
9090
AliasesToExport = 'Invoke-Build', 'Build-Checkpoint', 'Build-Parallel'
91+
VariablesToExport = @()
92+
FunctionsToExport = @()
93+
CmdletsToExport = @()
9194
PrivateData = @{
9295
PSData = @{
9396
Tags = 'Build', 'Test', 'Automation'

Build-Parallel.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ try {
133133
$work = $works[$iWork++]
134134
$stage.Add($work)
135135

136-
Write-Build Cyan "Start $($work.Title)"
136+
print Cyan "Start $($work.Title)"
137137
$work.Job = $work.PS.BeginInvoke()
138138
}
139139
if (!$stage) {break}
@@ -169,7 +169,7 @@ try {
169169

170170
### finish works
171171
foreach($work in $works) {
172-
Write-Build Cyan "Build $($work.Title):"
172+
print Cyan "Build $($work.Title):"
173173

174174
### get error and dispose
175175
$runtime = $false
@@ -223,16 +223,16 @@ try {
223223

224224
### result
225225
if ($_) {
226-
Write-Build Cyan "Build $($work.Title) FAILED."
226+
print Cyan "Build $($work.Title) FAILED."
227227
$_ = if ($_ -is [System.Management.Automation.ErrorRecord] -and $runtime) {*Msg $_ $_} else {"$_"}
228-
Write-Build Red "ERROR: $_"
228+
print Red "ERROR: $_"
229229
$failures += @{
230230
File = $work.Title
231231
Error = $_
232232
}
233233
}
234234
else {
235-
Write-Build Cyan "Build $($work.Title) succeeded."
235+
print Cyan "Build $($work.Title) succeeded."
236236
}
237237
}
238238

@@ -263,7 +263,7 @@ finally {
263263
elseif ($warnings) {14, 'Builds succeeded with warnings'}
264264
else {10, 'Builds succeeded'}
265265

266-
Write-Build $color @"
266+
print $color @"
267267
Tasks: $($info.Tasks.Count) tasks, $errors errors, $warnings warnings
268268
$text. $($Build.Count) builds, $($failures.Count) failed $($info.Elapsed)
269269
"@

Convert-psake.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Set-Alias TaskTearDown Write-TaskTearDown
177177
function Write-FormatTaskName([string]$format) {
178178
$format = $format.Replace("'", "''")
179179
'# TODO: Custom task headers, see the repository Tasks/Header for details.'
180-
"Set-BuildHeader { param(`$Path) Write-Build Cyan ('$format' -f `$Path) }"
180+
"Set-BuildHeader { param(`$Path) print Cyan ('$format' -f `$Path) }"
181181
}
182182

183183
function Write-Property([scriptblock]$properties) {

Help.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
assert (Assert-Build)
3636
equals (Assert-BuildEquals)
3737
remove (Remove-BuildItem)
38+
print (Write-Build)
3839
property (Get-BuildProperty)
3940
requires (Test-BuildAsset)
4041
use (Use-BuildAlias)
@@ -48,7 +49,6 @@
4849
Set-BuildFooter
4950
Set-BuildHeader
5051
Use-BuildEnv
51-
Write-Build
5252
Write-Warning [1]
5353
5454
[1] Write-Warning is redefined internally in order to count warnings in
@@ -363,6 +363,7 @@
363363
@{ text = 'assert (Assert-Build)' }
364364
@{ text = 'equals (Assert-BuildEquals)' }
365365
@{ text = 'remove (Remove-BuildItem)' }
366+
@{ text = 'print (Write-Build' }
366367
@{ text = 'property (Get-BuildProperty)' }
367368
@{ text = 'requires (Test-BuildAsset)' }
368369
@{ text = 'use (Use-BuildAlias)' }
@@ -373,7 +374,6 @@
373374
@{ text = 'Resolve-MSBuild' }
374375
@{ text = 'Set-BuildFooter' }
375376
@{ text = 'Set-BuildHeader' }
376-
@{ text = 'Write-Build' }
377377
)
378378
}
379379

@@ -798,7 +798,7 @@
798798
# Headers: print task paths as usual and synopses in addition
799799
Set-BuildHeader {
800800
param($Path)
801-
Write-Build Cyan "Task $Path : $(Get-BuildSynopsis $Task)"
801+
print Cyan "Task $Path : $(Get-BuildSynopsis $Task)"
802802
}
803803

804804
# Synopsis: This task prints its own synopsis.
@@ -945,7 +945,7 @@
945945
description = @'
946946
This build block is used in order to change the default task footer format.
947947
Use the automatic variable $Task in order to get the current task data.
948-
Use Write-Build in order to write with colors.
948+
Use Write-Build (print) in order to write with colors.
949949
'@
950950

951951
parameters = @{
@@ -963,7 +963,7 @@
963963
# Use the usual footer format but change the color
964964
Set-BuildFooter {
965965
param($Path)
966-
Write-Build DarkGray "Done $Path $($Task.Elapsed)"
966+
print DarkGray "Done $Path $($Task.Elapsed)"
967967
}
968968

969969
# Synopsis: Data for footers in addition to $Path and $Task.Elapsed
@@ -978,7 +978,7 @@
978978
links = @(
979979
@{ text = 'Get-BuildSynopsis' }
980980
@{ text = 'Set-BuildHeader' }
981-
@{ text = 'Write-Build' }
981+
@{ text = 'Write-Build (print)' }
982982
)
983983
}
984984

@@ -990,7 +990,7 @@
990990
description = @'
991991
This build block is used in order to change the default task header format.
992992
Use the automatic variable $Task in order to get the current task data.
993-
Use Write-Build in order to write with colors.
993+
Use Write-Build (print) in order to write with colors.
994994
'@
995995

996996
parameters = @{
@@ -1004,7 +1004,7 @@
10041004
# Headers: write task paths as usual and synopses in addition
10051005
Set-BuildHeader {
10061006
param($Path)
1007-
Write-Build Cyan "Task $Path --- $(Get-BuildSynopsis $Task)"
1007+
print Cyan "Task $Path --- $(Get-BuildSynopsis $Task)"
10081008
}
10091009

10101010
# Synopsis: Data for headers in addition to $Path and Get-BuildSynopsis
@@ -1019,7 +1019,7 @@
10191019
links = @(
10201020
@{ text = 'Get-BuildSynopsis' }
10211021
@{ text = 'Set-BuildFooter' }
1022-
@{ text = 'Write-Build' }
1022+
@{ text = 'Write-Build (print)' }
10231023
)
10241024
}
10251025

@@ -1158,7 +1158,7 @@ If it is omitted, the current task or script name is used.
11581158
### Write-Build
11591159
@{
11601160
command = 'Write-Build'
1161-
synopsis = 'Writes text using colors if they are supported.'
1161+
synopsis = '(print) Writes text using colors if they are supported.'
11621162

11631163
description = @'
11641164
This function is used in order to output colored text in a console or other

Invoke-Build.ps1

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function *Die($M, $C=0) {$PSCmdlet.ThrowTerminatingError((New-Object System.Mana
2828
Set-Alias assert Assert-Build
2929
Set-Alias equals Assert-BuildEquals
3030
Set-Alias exec Invoke-BuildExec
31+
Set-Alias print Write-Build
3132
Set-Alias property Get-BuildProperty
3233
Set-Alias remove Remove-BuildItem
3334
Set-Alias requires Test-BuildAsset
@@ -373,8 +374,8 @@ New-Variable * -Description IB ([PSCustomObject]@{
373374
B = 0
374375
Q = 0
375376
H = @{}
376-
Header = if (${*p}) {${*p}.Header} else {{Write-Build 11 "Task $($args[0])"}}
377-
Footer = if (${*p}) {${*p}.Footer} else {{Write-Build 11 "Done $($args[0]) $($Task.Elapsed)"}}
377+
Header = if (${*p}) {${*p}.Header} else {{print 11 "Task $($args[0])"}}
378+
Footer = if (${*p}) {${*p}.Footer} else {{print 11 "Done $($args[0]) $($Task.Elapsed)"}}
378379
Data = @{}
379380
XBuild = $null
380381
XCheck = $null
@@ -515,8 +516,8 @@ function *Check($J, $T, $P=@()) {
515516
function *Echo {
516517
${*c} = $args[0]
517518
${*t} = "${*c}".Replace("`t", ' ')
518-
Write-Build 3 "exec {$(if (${*t} -match '((?:\r\n|[\r\n]) *)\S') {"$(${*t}.TrimEnd().Replace($matches[1], "`n "))`n"} else {${*t}})}"
519-
Write-Build 8 "cd $global:pwd"
519+
print 3 "exec {$(if (${*t} -match '((?:\r\n|[\r\n]) *)\S') {"$(${*t}.TrimEnd().Replace($matches[1], "`n "))`n"} else {${*t}})}"
520+
print 8 "cd $global:pwd"
520521
foreach(${*v} in ${*c}.Ast.FindAll({$args[0] -is [System.Management.Automation.Language.VariableExpressionAst]}, $true)) {
521522
${*p} = ${*v}.Parent
522523
if (${*p} -is [System.Management.Automation.Language.MemberExpressionAst]) {
@@ -525,14 +526,14 @@ function *Echo {
525526
}
526527
if (${*v}.Parent -isnot [System.Management.Automation.Language.AssignmentStatementAst]) {
527528
${*t} = "${*v}" -replace '^@', '$'
528-
Write-Build 8 "${*t}: $(& ([scriptblock]::Create(${*t})))"
529+
print 8 "${*t}: $(& ([scriptblock]::Create(${*t})))"
529530
}
530531
}
531532
}
532533

533534
function *Err($T) {
534535
${*}.Errors.Add([PSCustomObject]@{Error = $_; File = $BuildFile; Task = $T})
535-
Write-Build 12 "ERROR: $(if (*My) {$_} else {*Msg $_ $_})"
536+
print 12 "ERROR: $(if (*My) {$_} else {*Msg $_ $_})"
536537
if ($T) {$T.Error = $_}
537538
}
538539

@@ -639,7 +640,7 @@ function *Task {
639640
New-Variable Task (${*}.Task = ${*}.All[${*n}]) -Option Constant
640641

641642
if ($Task.Elapsed) {
642-
Write-Build 8 "Done ${*p}"
643+
print 8 "Done ${*p}"
643644
return
644645
}
645646

@@ -652,14 +653,14 @@ function *Task {
652653
}
653654
catch {
654655
*Err $Task
655-
Write-Build 8 (*At $Task)
656+
print 8 (*At $Task)
656657
${*}.Tasks.Add($Task)
657658
$Task.Elapsed = [TimeSpan]::Zero
658659
throw
659660
}
660661
}
661662
if (!${*x}) {
662-
Write-Build 8 "Task ${*p} skipped."
663+
print 8 "Task ${*p} skipped."
663664
return
664665
}
665666

@@ -687,7 +688,7 @@ function *Task {
687688
*Err $Task
688689
throw
689690
}
690-
Write-Build 8 ${*i}[1]
691+
print 8 ${*i}[1]
691692
}
692693
if (${*i}[0]) {
693694
continue
@@ -716,7 +717,7 @@ function *Task {
716717
}
717718
catch {
718719
*Err $Task
719-
Write-Build 8 (*At $Task)
720+
print 8 (*At $Task)
720721
throw
721722
}
722723
finally {
@@ -828,9 +829,9 @@ try {
828829
exit
829830
}
830831

831-
Write-Build 11 "Build $($BuildTask -join ', ') $BuildFile"
832+
print 11 "Build $($BuildTask -join ', ') $BuildFile"
832833
foreach($_ in ${*}.Redefined) {
833-
if (($_ = $_.Name) -ne '.') {Write-Build 8 "Redefined task '$_'."}
834+
if (($_ = $_.Name) -ne '.') {print 8 "Redefined task '$_'."}
834835
}
835836
foreach($_ in ${*}.Doubles) {
836837
if (${*}.All[$_[1]].If -isnot [scriptblock]) {
@@ -882,18 +883,18 @@ finally {
882883
$t = ${*}.Tasks
883884
$e = ${*}.Errors
884885
if (${*}.Summary) {
885-
Write-Build 11 'Build summary:'
886+
print 11 'Build summary:'
886887
foreach($_ in $t) {
887888
'{0,-16} {1} - {2}:{3}' -f $_.Elapsed, $_.Name, $_.InvocationInfo.ScriptName, $_.InvocationInfo.ScriptLineNumber
888889
if ($_ = $_.Error) {
889-
Write-Build 12 "ERROR: $(if (*My) {$_} else {*Msg $_ $_})"
890+
print 12 "ERROR: $(if (*My) {$_} else {*Msg $_ $_})"
890891
}
891892
}
892893
}
893894
if ($w = ${*}.Warnings) {
894895
foreach($_ in $w) {
895896
"WARNING: $(if ($_.Task) {"/$($_.Task.Name) "})$($_.InvocationInfo.ScriptName):$($_.InvocationInfo.ScriptLineNumber)"
896-
Write-Build 14 $_.Message
897+
print 14 $_.Message
897898
}
898899
}
899900
if ($_ = ${*}.P) {
@@ -906,7 +907,7 @@ finally {
906907
elseif ($e) {14, 'Build completed with errors'}
907908
elseif ($w) {14, 'Build succeeded with warnings'}
908909
else {10, 'Build succeeded'}
909-
Write-Build $c "$m. $($t.Count) tasks, $($e.Count) errors, $($w.Count) warnings $((${*}.Elapsed = [DateTime]::Now - ${*}.Started))"
910+
print $c "$m. $($t.Count) tasks, $($e.Count) errors, $($w.Count) warnings $((${*}.Elapsed = [DateTime]::Now - ${*}.Started))"
910911
}
911912
}
912913
}

Release-Notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
[Issues](https://github.com/nightroman/Invoke-Build/issues) [Releases](https://github.com/nightroman/Invoke-Build/releases) [Discussions](https://github.com/nightroman/Invoke-Build/discussions)
44

5+
## v5.14.18
6+
7+
Add `Write-Build` alias `print`, #240
8+
59
## v5.14.17
610

711
Apply `Extends` prefixes to `After` and `Before` references, #239

Show-TaskHelp.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,39 +191,39 @@ function Add-TaskVariable($Jobs) {
191191
}
192192

193193
function Format-TaskHelp($TaskHelp) {
194-
Write-Build White Task:
194+
print White Task:
195195
foreach($r in $TaskHelp.Task) {
196196
if ($synopsis = $r.Synopsis) {
197-
Write-Build Gray (' {0} - {1}' -f $r.Name, $synopsis)
197+
print Gray (' {0} - {1}' -f $r.Name, $synopsis)
198198
}
199199
else {
200-
Write-Build Gray (' {0}' -f $r.Name)
200+
print Gray (' {0}' -f $r.Name)
201201
}
202202
}
203203

204-
Write-Build White Jobs:
204+
print White Jobs:
205205
foreach($r in $TaskHelp.Jobs) {
206206
if ($synopsis = Get-BuildSynopsis ($All[$r.Name]) $Hash) {
207-
Write-Build Gray (' {0} - {1} At {2}' -f $r.Name, $synopsis, $r.Location)
207+
print Gray (' {0} - {1} At {2}' -f $r.Name, $synopsis, $r.Location)
208208
}
209209
else {
210-
Write-Build Gray (' {0} - At {1}' -f $r.Name, $r.Location)
210+
print Gray (' {0} - At {1}' -f $r.Name, $r.Location)
211211
}
212212
}
213213

214214
if ($TaskHelp.Parameters) {
215-
Write-Build White Parameters:
215+
print White Parameters:
216216
foreach($p in $TaskHelp.Parameters) {
217-
Write-Build Gray (' [{0}] {1}' -f $p.Type, $p.Name)
217+
print Gray (' [{0}] {1}' -f $p.Type, $p.Name)
218218
if ($p.Description) {
219-
Write-Build Gray (' {0}' -f $p.Description)
219+
print Gray (' {0}' -f $p.Description)
220220
}
221221
}
222222
}
223223

224224
if ($TaskHelp.Environment) {
225-
Write-Build White Environment:
226-
Write-Build Gray (' {0}' -f ($TaskHelp.Environment -join ', '))
225+
print White Environment:
226+
print Gray (' {0}' -f ($TaskHelp.Environment -join ', '))
227227
}
228228
}
229229

Tasks/Header/1.build.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
Set-BuildHeader {
55
param($Path)
66
# separator line
7-
Write-Build Green ('=' * 79)
7+
print Green ('=' * 79)
88
# default header + synopsis
9-
Write-Build Green "Task $Path : $(Get-BuildSynopsis $Task)"
9+
print Green "Task $Path : $(Get-BuildSynopsis $Task)"
1010
# task location in a script
11-
Write-Build Green "At $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)"
11+
print Green "At $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)"
1212
}
1313

1414
# Define footers similar to default but change the color to DarkGray.
1515
Set-BuildFooter {
1616
param($Path)
17-
Write-Build DarkGray "Done $Path, $($Task.Elapsed)"
17+
print DarkGray "Done $Path, $($Task.Elapsed)"
1818
}
1919

2020
# Synopsis: Some task description 1.

0 commit comments

Comments
 (0)