powershell.Build.ps1.mustache Maven / Gradle / Ivy
function Get-FunctionsToExport {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[Alias('FullName')]
$Path
)
Process {
$Token = $null
$ParserErr = $null
$Ast = [System.Management.Automation.Language.Parser]::ParseFile(
$Path,
[ref]$Token,
[ref]$ParserErr
)
if ($ParserErr) {
throw $ParserErr
} else {
foreach ($name in 'Begin', 'Process', 'End') {
foreach ($Statement in $Ast."${name}Block".Statements) {
if (
[String]::IsNullOrWhiteSpace($Statement.Name) -or
$Statement.Extent.ToString() -notmatch
('function\W+{0}' -f $Statement.Name)
) {
continue
}
$Statement.Name
}
}
}
}
}
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
$ClientPath = ("{{{csharpClientPath}}}" | Resolve-Path).ProviderPath
$FunctionPath = 'API', 'Model' | ForEach-Object {Join-Path "$ScriptDir\src\{{{packageName}}}\" $_}
$BinPath = "$ScriptDir\src\{{{packageName}}}\Bin"
Start-Process -FilePath "$ClientPath\build.bat" -WorkingDirectory $ClientPath -Wait -NoNewWindow
if (!(Test-Path "$ScriptDir\src\{{{packageName}}}\Bin" -PathType Container)) {
New-Item "$ScriptDir\src\{{{packageName}}}\Bin" -ItemType Directory > $null
}
Copy-Item "$ClientPath\bin\*.dll" $BinPath
$Manifest = @{
Path = "$ScriptDir\src\{{{packageName}}}\{{{packageName}}}.psd1"
Author = 'OpenAPI Generator Team'
CompanyName = 'openapitools.org'
Description = '{{{packageName}}} - the PowerShell module for {{{appName}}}'
RootModule = '{{{packageName}}}.psm1'
Guid = '{{packageGuid}}' # Has to be static, otherwise each new build will be considered different module
PowerShellVersion = '3.0'
RequiredAssemblies = Get-ChildItem "$BinPath\*.dll" | ForEach-Object {
Join-Path $_.Directory.Name $_.Name
}
FunctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-FunctionsToExport
VariablesToExport = @()
AliasesToExport = @()
CmdletsToExport = @()
# Should we use prefix to prevent command name collisions?
# https://www.sapien.com/blog/2016/02/15/use-prefixes-to-prevent-command-name-collision/
#
# Kirk Munro recommends against it:
# https://www.sapien.com/blog/2016/02/15/use-prefixes-to-prevent-command-name-collision/#comment-20820
#
# If not, we'd need to generate functions name with prefix.
#
# DefaultCommandPrefix = 'PetStore'
}
New-ModuleManifest @Manifest