Skip to content

Commit 69b79b8

Browse files
authored
Exclude *.md files from nuget package to reduce overrall package size. (#566)
* Exclude *.md files from nuget package to reduce overrall package size. * Exclude markdown files in weekly service module generation. * Simplify and handle possibility of position change.
1 parent 9ce9ab3 commit 69b79b8

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

.azure-pipelines/generate-modules-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ jobs:
231231
$ModuleMapping.Keys | ForEach-Object {
232232
$ModuleName = $_
233233
$ModuleProjectDir = "$(System.DefaultWorkingDirectory)/src/$ModuleName/$ModuleName"
234-
& $(System.DefaultWorkingDirectory)/tools/PackModule.ps1 -Module $ModuleName -ArtifactsLocation $(Build.ArtifactStagingDirectory)\
234+
& $(System.DefaultWorkingDirectory)/tools/PackModule.ps1 -Module $ModuleName -ArtifactsLocation $(Build.ArtifactStagingDirectory)\ -ExcludeMarkdownDocsFromNugetPackage
235235
}
236236
237237
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1

.azure-pipelines/generation-templates/generate-service-modules.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ jobs:
229229
$ModuleMapping.Keys | ForEach-Object {
230230
$ModuleName = $_
231231
$ModuleProjectDir = "$(System.DefaultWorkingDirectory)/src/$ModuleName/$ModuleName"
232-
& $(System.DefaultWorkingDirectory)/tools/PackModule.ps1 -Module $ModuleName -ArtifactsLocation $(Build.ArtifactStagingDirectory)\
232+
& $(System.DefaultWorkingDirectory)/tools/PackModule.ps1 -Module $ModuleName -ArtifactsLocation $(Build.ArtifactStagingDirectory)\ -ExcludeMarkdownDocsFromNugetPackage
233233
}
234234
235235
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1

tools/NuspecHelper.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,19 @@ function Set-Dependencies(
8585
$MetadataElement["dependencies"].AppendChild($NewDependencyElement)
8686
}
8787
}
88+
89+
<#
90+
Remove Markdown Docs Element from the Nuspec File.
91+
This is fixed in autorest code generator
92+
https://github.com/Azure/autorest.powershell/blob/4e5e47e874747ce9cfbf88981538654dd2bafe4f/powershell/generators/nuspec.ts#L42
93+
#>
94+
function Remove-MarkdownDocsElement(
95+
[parameter(Position=1, Mandatory=$true)]
96+
[ValidateScript({Test-Path $_ -PathType Leaf})][string] $NuSpecFilePath){
97+
98+
$XmlDocument = New-Object System.Xml.XmlDocument
99+
$XmlDocument.Load($NuSpecFilePath)
100+
$docsNode = $XmlDocument.DocumentElement.Files.ChildNodes | Where-Object { $_.target -eq 'docs'}
101+
$XmlDocument.DocumentElement.Files.RemoveChild($docsNode) | Out-Null
102+
$XmlDocument.Save($NuSpecFilePath)
103+
}

tools/PackModule.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22
# Licensed under the MIT License.
33
Param(
44
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()][string] $Module,
5-
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()][string] $ArtifactsLocation
5+
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()][string] $ArtifactsLocation,
6+
[string] $ModulePrefix="Microsoft.Graph",
7+
[switch] $ExcludeMarkdownDocsFromNugetPackage
68
)
9+
$NuspecHelperPS1 = Join-Path $PSScriptRoot "./NuspecHelper.ps1"
10+
# Import scripts
11+
. $NuspecHelperPS1
12+
713
$LASTEXITCODE = $null
814
$ErrorActionPreference = "Stop"
915
if($PSEdition -ne "Core") {
1016
Write-Error "This script requires PowerShell Core to execute. [Note] Generated cmdlets will work in both PowerShell Core or Windows PowerShell."
1117
}
1218

1319
$ModuleProjLocation = Join-Path $PSScriptRoot "../src/$Module/$Module"
20+
$ModuleNuspec = Join-Path $ModuleProjLocation "$ModulePrefix.$Module.nuspec"
1421
$PackModulePS1 = Join-Path $ModuleProjLocation "/pack-module.ps1"
1522

1623
if (Test-Path $PackModulePS1) {
24+
#Remove MarkDown Docs From Nuget Package
25+
if ($ExcludeMarkdownDocsFromNugetPackage) {
26+
Write-Information "Removing MarkDownDocs from Nuget Package..."
27+
Remove-MarkdownDocsElement -NuSpecFilePath $ModuleNuspec
28+
}
1729
# Pack module
1830
& $PackModulePS1
1931
if($LASTEXITCODE) {

0 commit comments

Comments
 (0)