Skip to content

Commit f32a8ff

Browse files
Lots of tuning
1 parent ddcea73 commit f32a8ff

File tree

6 files changed

+44
-27
lines changed

6 files changed

+44
-27
lines changed

templates/PSFProject/azFunctionResources/clientModule/function.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
process
66
{
77
$invokeParameters = Get-InternalConnectionData -Method '%method%' -Parameter $PSBoundParameters -FunctionName '%condensedname%'
8-
Invoke-RestMethod @invokeParameters
8+
Invoke-RestMethod @invokeParameters | ConvertFrom-PSFClixml
99
}
1010
}

templates/PSFProject/azFunctionResources/clientModule/functions/Connect-þnameþ.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
Set-PSFConfig -Module 'þnameþ' -Name 'Client.UnprotectedToken' -Value $UnprotectedToken
4848
if ($Register) { Register-PSFConfig -Module 'þnameþ' -Name 'Client.UnprotectedToken' }
4949
}
50-
if (Test-PSFParameterBinding -ParameterName Url)
50+
if (Test-PSFParameterBinding -ParameterName Uri)
5151
{
5252
Set-PSFConfig -Module 'þnameþ' -Name 'Client.Uri' -Value $Uri
5353
if ($Register) { Register-PSFConfig -Module 'þnameþ' -Name 'Client.Uri' }

templates/PSFProject/azFunctionResources/clientModule/internal/functions/Get-InternalConnectionData.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
Method = $Method
6262
Uri = $uri
6363
Headers = $header
64-
Body = @{
64+
Body = (@{
6565
__SerializedParameters = ($Parameters | ConvertTo-PSFHashtable | ConvertTo-PSFClixml)
6666
__PSSerialize = $true
67-
}
67+
} | ConvertTo-Json)
6868
}
6969
}
7070
}

templates/PSFProject/azFunctionResources/profileFunctions/Convert-AzureFunctionParameter.ps1

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,30 @@
2222
$Request
2323
)
2424

25-
$parameters = @{ }
25+
$parameterObject = [pscustomobject]@{
26+
Parameters = @{ }
27+
Serialize = $false
28+
}
2629

2730
foreach ($key in $Request.Query.Keys)
2831
{
2932
# Do NOT include the authentication key
3033
if ($key -eq 'code') { continue }
31-
$parameters[$key] = $Request.Query.$key
34+
$parameterObject.Parameters[$key] = $Request.Query.$key
3235
}
3336
foreach ($key in $Request.Body.Keys)
3437
{
35-
$parameters[$key] = $Request.Body.$key
38+
$parameterObject.Parameters[$key] = $Request.Body.$key
3639
}
37-
38-
if (($parameters.Count -eq 1) -and ($parameters.__SerializedParameters))
40+
if ($parameterObject.Parameters.__PSSerialize)
41+
{
42+
$parameterObject.Serialize = $true
43+
$null = $parameterObject.Parameters.Remove('__PSSerialize')
44+
}
45+
if ($parameterObject.Parameters.__SerializedParameters)
3946
{
40-
return $parameters.__SerializedParameters | ConvertFrom-PSFClixml
47+
$parameterObject.Parameters = $parameterObject.Parameters.__SerializedParameters | ConvertFrom-PSFClixml
4148
}
4249

43-
$parameters
50+
$parameterObject
4451
}

templates/PSFProject/azFunctionResources/run.ps1

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44
$TriggerMetadata
55
)
66

7-
$parameters = Convert-AzureFunctionParameter -Request $Request
8-
if ($parameters.__PSSerialize)
9-
{
10-
$usePSSerialize = $true
11-
$parameters.Remove('__PSSerialize')
12-
}
13-
else { $usePSSerialize = $false }
14-
7+
$parameterObject = Convert-AzureFunctionParameter -Request $Request
8+
$parameters = $parameterObject.Parameters
159
try { $data = %functionname% @parameters }
1610
catch
1711
{
1812
Write-AzureFunctionOutput -Value "Failed to execute: $_" -Status InternalServerError
1913
return
2014
}
2115

22-
Write-AzureFunctionOutput -Value $data -Serialize:$usePSSerialize
16+
Write-AzureFunctionOutput -Value $data -Serialize:$parameterObject.Serialize

templates/PSFProject/build/vsts-createFunctionClientModule.ps1

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,22 @@ if (-not $WorkingDirectory)
6666
}
6767
#endregion Handle Working Directory Defaults
6868

69+
Write-PSFMessage -Level Host -Message 'Starting Build: Client Module'
6970
$parentModule = 'þnameþ'
7071
if (-not $ModuleName) { $ModuleName = 'þnameþ.Client' }
72+
Write-PSFMessage -Level Host -Message 'Creating Folder Structure'
7173
$workingRoot = New-Item -Path $WorkingDirectory -Name $ModuleName -ItemType Directory
7274
$publishRoot = Join-Path -Path $WorkingDirectory -ChildPath 'publish\þnameþ'
73-
$functionFolder = Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\clientModule\functions" -Destination "$($workingRoot.FullName)\" -Recurse -PassThru
75+
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\clientModule\functions" -Destination "$($workingRoot.FullName)\" -Recurse
7476
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\clientModule\internal" -Destination "$($workingRoot.FullName)\" -Recurse
7577
Copy-Item -Path "$($publishRoot)\en-us" -Destination "$($workingRoot.FullName)\" -Recurse
78+
$functionFolder = Get-Item -Path "$($workingRoot.FullName)\functions"
7679

7780
#region Create Functions
7881
$encoding = [PSFEncoding]'utf8'
7982
$functionsText = Get-Content -Path "$($WorkingDirectory)\azFunctionResources\clientModule\function.ps1" -Raw
8083

84+
Write-PSFMessage -Level Host -Message 'Creating Functions'
8185
foreach ($functionSourceFile in (Get-ChildItem -Path "$($publishRoot)\functions" -Recurse -Filter '*.ps1'))
8286
{
8387
Write-PSFMessage -Level Host -Message " Processing function: $($functionSourceFile.BaseName)"
@@ -106,9 +110,17 @@ foreach ($functionSourceFile in (Get-ChildItem -Path "$($publishRoot)\functions"
106110
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\functionOverride\$($functionSourceFile.BaseName).ps1" -Destination $functionFolder.FullName
107111
continue
108112
}
113+
114+
# Figure out the Rest Method to use
115+
$methodName = 'Post'
116+
if ($override.RestMethods)
117+
{
118+
$methodName = $override.RestMethods | Where-Object { $_ -ne 'Get' } | Select-Object -First 1
119+
}
120+
109121
#endregion Load Overrides
110122

111-
$currentFunctionsText = $functionsText -replace '%functionname%', $functionSourceFile.BaseName -replace '%condensedname%', $condensedName
123+
$currentFunctionsText = $functionsText -replace '%functionname%', $functionSourceFile.BaseName -replace '%condensedname%', $condensedName -replace '%method%', $methodName
112124

113125
$parsedFunction = Read-PSMDScript -Path $functionSourceFile.FullName
114126
$functionAst = $parsedFunction.Ast.EndBlock.Statements | Where-Object {
@@ -119,6 +131,7 @@ foreach ($functionSourceFile in (Get-ChildItem -Path "$($publishRoot)\functions"
119131
$start = $functionAst.Body.Extent.StartOffSet + 1
120132
$currentFunctionsText = $currentFunctionsText.Replace('%parameter%', $functionAst.Body.Extent.Text.SubString(1, ($end - $start)))
121133

134+
Write-PSFMessage -Level Host -Message " Creating file: $($functionFolder.FullName)\$($functionSourceFile.Name)"
122135
[System.IO.File]::WriteAllText("$($functionFolder.FullName)\$($functionSourceFile.Name)", $currentFunctionsText, $encoding)
123136
}
124137
$functionsToExport = (Get-ChildItem -Path $functionFolder.FullName -Recurse -Filter *.ps1).BaseName | Sort-Object
@@ -136,22 +149,25 @@ $paramNewModuleManifest = @{
136149
FunctionsToExport = $functionsToExport
137150
CompanyName = $originalManifestData.CompanyName
138151
Author = $originalManifestData.Author
152+
Description = $originalManifestData.Description
153+
ModuleVersion = $originalManifestData.ModuleVersion
139154
RootModule = ('{0}.psm1' -f $ModuleName)
140155
Copyright = $originalManifestData.Copyright
141156
TypesToProcess = @()
142157
FormatsToProcess = @()
143158
RequiredAssemblies = @()
144159
RequiredModules = @($prereqHash)
145160
CompatiblePSEditions = 'Core', 'Desktop'
146-
PowerShellVersion = 5.0
161+
PowerShellVersion = '5.1'
147162
}
148163

149164
if ($IncludeAssembly) { $paramNewModuleManifest.RequiredAssemblies = $originalManifestData.RequiredAssemblies }
150165
if ($IncludeFormat) { $paramNewModuleManifest.FormatsToProcess = $originalManifestData.FormatsToProcess }
151166
if ($IncludeType) { $paramNewModuleManifest.TypesToProcess = $originalManifestData.TypesToProcess }
152-
167+
Write-PSFMessage -Level Host -Message "Creating Module Manifest for module: $ModuleName"
153168
New-ModuleManifest @paramNewModuleManifest
154169

170+
Write-PSFMessage -Level Host -Message "Copying additional module files"
155171
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\clientModule\moduleroot.psm1" -Destination "$($workingRoot.FullName)\$($ModuleName).psm1"
156172
Copy-Item -Path "$($WorkingDirectory)\LICENSE" -Destination "$($workingRoot.FullName)\"
157173
#endregion Create Core Module Files
@@ -172,14 +188,14 @@ if ($LocalRepo)
172188
{
173189
# Dependencies must go first
174190
Write-PSFMessage -Level Important -Message "Creating Nuget Package for module: PSFramework"
175-
New-PSMDModuleNugetPackage -ModulePath (Get-Module -Name PSFramework).ModuleBase -PackagePath .
191+
New-PSMDModuleNugetPackage -ModulePath (Get-Module -Name PSFramework).ModuleBase -PackagePath . -WarningAction SilentlyContinue
176192
Write-PSFMessage -Level Important -Message "Creating Nuget Package for module: þnameþ"
177-
New-PSMDModuleNugetPackage -ModulePath "$($publishDir.FullName)\þnameþ" -PackagePath .
193+
New-PSMDModuleNugetPackage -ModulePath $workingRoot.FullName -PackagePath . -EnableException
178194
}
179195
else
180196
{
181197
# Publish to Gallery
182198
Write-PSFMessage -Level Important -Message "Publishing the þnameþ module to $($Repository)"
183-
Publish-Module -Path "$($publishDir.FullName)\þnameþ" -NuGetApiKey $ApiKey -Force -Repository $Repository
199+
Publish-Module -Path $workingRoot.FullName -NuGetApiKey $ApiKey -Force -Repository $Repository
184200
}
185201
#endregion Publish

0 commit comments

Comments
 (0)