-
Notifications
You must be signed in to change notification settings - Fork 20
/
pack.ps1
166 lines (123 loc) · 6.21 KB
/
pack.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
$artifactsFolderName = "artifacts"
$localizationFolderName = "Localization"
$cultures = New-Object Collections.Generic.List[String]
$pkgExtension = "nupkg"
$pkgNamePrefix = "OrchardCore.Translations."
$pkgVersion = $env:nugetVersion
$pkgTitle = "Orchard Core translations for '{0}' culture"
$pkgDescription = "Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework.
Orchard Core translations for '{0}' ({1}) culture"
$pkgSpecExtension = "nuspec"
$pkgPropsExtension = "props"
$pkgBuildFolderName = "buildTransitive"
$pkgSpecTemplate = "_template.$pkgSpecExtension"
$pkgPropsTemplate = "_template.$pkgPropsExtension"
$pkgIconFile = "icon.png"
$csprojFilePath = "$env:GITHUB_WORKSPACE/.github/workflows/project.csproj"
$iconSrcPath = "$env:GITHUB_WORKSPACE/.github/workflows/nuget-icon.png"
function createNuGetPackage([string]$pkgName, [string]$culture, [string]$folder, [string]$cultureDisplayName)
{
echo "Copying content files .."
$pkgId = "$pkgName.$pkgVersion"
$pkgFolderPath = [IO.Path]::Combine($artifactsFolderName, $pkgId)
$pkgContentFolderPath = [IO.Path]::Combine($pkgFolderPath, "content")
New-Item -Path $pkgContentFolderPath -ItemType "Directory" | Out-Null
$pkgCultureFolderPath = [IO.Path]::Combine($pkgContentFolderPath, $localizationFolderName, $culture)
$cultureFolder = [IO.Path]::Combine($localizationFolderName, $folder)
Copy-Item -Path $cultureFolder -Destination $pkgCultureFolderPath -Recurse
echo "Copying '$pkgName.$pkgPropsExtension' ..."
$pkgBuildFolderPath = [IO.Path]::Combine($pkgFolderPath, $pkgBuildFolderName)
New-Item -Path $pkgBuildFolderPath -ItemType "Directory" | Out-Null
$pkgPropsFileName = "$pkgName.$pkgPropsExtension"
$pkgPropsFilePath = [IO.Path]::Combine($pkgBuildFolderPath, $pkgPropsFileName)
Copy-Item -Path $pkgPropsTemplate -Destination $pkgPropsFilePath
buildNuGetPackageSpec $pkgName $culture $cultureDisplayName
$pkgSpecFileName = "$pkgName.$pkgSpecExtension"
$pkgSpecFilePath = [IO.Path]::Combine($env:GITHUB_WORKSPACE, $pkgFolderPath, $pkgSpecFileName)
$pkgDestinationPath = [IO.Path]::Combine($env:GITHUB_WORKSPACE, $pkgFolderPath)
$iconDestinationPath = [IO.Path]::Combine($env:GITHUB_WORKSPACE, $pkgFolderPath, $pkgIconFile)
echo "Copying $iconSrcPath to $iconDestinationPath ..."
Copy-Item -Path $iconSrcPath -Destination $iconDestinationPath
dotnet pack $csprojFilePath -p:NuspecFile=$pkgSpecFilePath -p:PackageOutputPath=$pkgDestinationPath # | Out-Null
}
function createNuGetMetaPackage()
{
$pkgName = $pkgNamePrefix + "All"
$pkgId = "$pkgName.$pkgVersion"
echo "Creating '$pkgId.$pkgExtension' ..."
buildNuGetMetaPackageSpec $pkgName
$pkgSpecFileName = "$pkgName.$pkgSpecExtension"
$pkgSpecFilePath = [IO.Path]::Combine($env:GITHUB_WORKSPACE, $artifactsFolderName, $pkgSpecFileName)
$pkgDestinationPath = [IO.Path]::Combine($env:GITHUB_WORKSPACE, $pkgFolderPath)
$pkgFolderPath = [IO.Path]::Combine($artifactsFolderName, $pkgId)
echo "Project file in '$csprojFilePath'"
$iconDestinationPath = [IO.Path]::Combine($env:GITHUB_WORKSPACE, $artifactsFolderName, $pkgIconFile)
echo "Copying '$iconSrcPath to $iconDestinationPath ..."
Copy-Item -Path $iconSrcPath -Destination $iconDestinationPath
dotnet pack $csprojFilePath -p:NuspecFile=$pkgSpecFilePath -p:PackageOutputPath=$pkgDestinationPath # | Out-Null
}
function buildNuGetPackageSpec($pkgName, $culture, $cultureDisplayName)
{
echo "Building '$pkgName.$pkgSpecExtension' ..."
$pkgSpecDocument = [xml](Get-Content -Path $pkgSpecTemplate)
$metadata = $pkgSpecDocument.package.metadata
$metadata.id = $pkgName
$metadata.version = $pkgVersion
$metadata.title = [String]::Format($pkgTitle, $cultureDisplayName)
$metadata.description = [String]::Format($pkgDescription, $cultureDisplayName, $culture)
$pkgId = $pkgNamePrefix + $culture
$pkgFolderPath = [IO.Path]::Combine($artifactsFolderName, "$pkgId.$pkgVersion")
$pkgSpecFilePath = [IO.Path]::Combine($PWD, $pkgFolderPath, "$pkgId.$pkgSpecExtension")
$pkgSpecDocument.Save($pkgSpecFilePath)
echo "File '$pkgSpecFilePath' built"
}
function buildNuGetMetaPackageSpec($pkgName)
{
echo "Building '$pkgName.$pkgSpecExtension' ..."
$pkgSpecDocument = [xml](Get-Content -Path $pkgSpecTemplate)
$metadata = $pkgSpecDocument.package.metadata
$metadata.id = $pkgName
$metadata.version = $pkgVersion
$metadata.title = "Orchard Core Translations for All cultures"
$metadata.description = "Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework.
Orchard Core translation for all supported cultures"
$dependencies = $pkgSpecDocument.CreateElement("dependencies")
$dependencies.RemoveAllAttributes()
foreach($culture in $cultures)
{
$dependency = $pkgSpecDocument.CreateElement("dependency")
$dependency.SetAttribute("id", $pkgNamePrefix + $culture)
$dependency.SetAttribute("version", $pkgVersion)
$dependencies.AppendChild($dependency) | Out-Null
}
$metadata.AppendChild($dependencies) | Out-Null
$pkgId = $pkgNamePrefix + "All"
$pkgSpecFilePath = [IO.Path]::Combine($PWD, $artifactsFolderName, "$pkgId.$pkgSpecExtension")
$pkgSpecDocument.Save($pkgSpecFilePath)
}
echo "Start generating translations NuGet packages"
echo ""
$json = Get-Content -Raw -Path cultures.json | ConvertFrom-Json
foreach ($culture in $json.cultures)
{
$cultureName = $culture.name
$cultureFolder = $culture.folder
$cultureDisplayName = $culture.'display-name'
if($culture.'generate-package')
{
$pkgName = $pkgNamePrefix + $cultureName
$pkgId = "$pkgName.$pkgVersion"
echo "Preparing a NuGet package for '$($culture.'display-name')' culture"
echo "Creating '$pkgId.$pkgExtension' ..."
createNuGetPackage $pkgName $cultureName $cultureFolder $cultureDisplayName
echo ""
}
if($culture.'meta-package')
{
$cultures.Add($cultureName)
}
}
echo "Creating translations meta package ..."
createNuGetMetaPackage
echo ""
echo "Translations NuGet packages created successfully!!"