-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenDocumentTemplates.build.shared.ps1
115 lines (89 loc) · 3.36 KB
/
OpenDocumentTemplates.build.shared.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Copyright © 2020 Sergei S. Betke
#Requires -Version 5.0
Set-StrictMode -Version Latest;
$InvocationInfo = @( Get-PSCallStack )[0].InvocationInfo;
[System.String] $TemplateDir = $InvocationInfo.PSScriptRoot;
if ( -not ( Test-Path variable:TemplateName ) -or ( [System.String]::IsNullOrEmpty( $TemplateName ) ) )
{
$TemplateName = Split-Path -Path $TemplateDir -Leaf;
};
. $PSScriptRoot/../common.build.shared.ps1
[System.String] $DestinationTemplatePath = ( Join-Path -Path $DestinationTemplatesPath -ChildPath $TemplateName );
[System.String] $PreprocessedTemplatePath = ( Join-Path -Path $PreprocessedTemplatesPath -ChildPath $TemplateName );
[System.String] $SourceTemplatePath = ( Join-Path -Path $TemplateDir -ChildPath 'src' -Resolve );
$sources = @( Get-ChildItem -Path $SourceTemplatePath -File -Recurse -Exclude $MarkerFileName );
$marker = Join-Path -Path $SourceTemplatePath -ChildPath $MarkerFileName;
$targetFiles = @( $DestinationTemplatePath, $marker );
Set-Alias openDocumentTemplate Add-BuildOpenDocumentTemplateTask;
function Add-BuildOpenDocumentTemplateTask
(
[Parameter( Mandatory = $true, Position = 0 )]
[ValidateNotNullOrEmpty()]
[System.String] $Name,
[Parameter( Mandatory = $true )]
[Alias('PSPath')]
[Alias('Path')]
[ValidateNotNullOrEmpty()]
[System.String] $LiteralPath,
[Parameter( Mandatory = $false )]
[ValidateNotNullOrEmpty()]
[System.String] $PreprocessedPath,
[Parameter( Mandatory = $false )]
[Alias('LibPath')]
[ValidateNotNullOrEmpty()]
[System.String] $LibrariesPath,
[Parameter( Mandatory = $false )]
[System.String] $Version,
[Parameter( Mandatory = $true, Position = 1 )]
$Inputs,
[Parameter( Mandatory = $true, Position = 2 )]
$Outputs,
[Parameter()]
[Switch]
$OpenAfterBuild,
[System.Object[]] $Jobs = @(),
[System.String[]] $After,
[System.String[]] $Before,
$If = -9,
$Done,
$Source = $MyInvocation
)
{
$taskParams = @{ SourceTemplatePath = $LiteralPath };
if ( $PSBoundParameters.Keys.Contains( 'PreprocessedPath' ) )
{
$null = $taskParams.Add( 'PreprocessedTemplatePath', $PreprocessedPath );
};
if ( $PSBoundParameters.Keys.Contains( 'LibrariesPath' ) )
{
$null = $taskParams.Add( 'LibrariesPath', $LibrariesPath );
};
if ( $PSBoundParameters.Keys.Contains( 'Version' ) )
{
$null = $taskParams.Add( 'Version', $Version );
};
$taskJobs = @( 'XSLT-tools' ) + $Jobs;
$taskJobs += `
{
$destFile = $Outputs[0];
& $BuildOODocumentPath -LiteralPath $Task.Data.SourceTemplatePath -Destination $destFile -Force `
-PreprocessedPath $Task.Data.PreprocessedTemplatePath `
-LibrariesPath $Task.Data.LibrariesPath `
-Version $Task.Data.Version `
-WarningAction Continue `
-Verbose:( $VerbosePreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue ) `
-Debug:( $DebugPreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue );
$marker = $Outputs[1];
& $UpdateFileLastWriteTimePath -LiteralPath $marker `
-Verbose:( $VerbosePreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue ) `
-Debug:( $DebugPreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue );
};
if ( $OpenAfterBuild )
{
$taskJobs += $JobOpenFile;
};
task -Name $Name -Source $Source -Inputs $Inputs -Outputs $Outputs `
-If $If -Done $Done -Before $Before -After $After `
-Data $taskParams `
-Jobs $taskJobs;
}