Skip to content

Commit cea4d4e

Browse files
committed
Add repack ability
1 parent a898f95 commit cea4d4e

File tree

1 file changed

+110
-103
lines changed

1 file changed

+110
-103
lines changed

scripts/packaging/createupmpackages.ps1

Lines changed: 110 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
What version of the artifacts should we build?
1515
.PARAMETER PreviewNumber
1616
The preview number to append to the version. Note: Exclude this parameter to create non-preview packages.
17+
.PARAMETER Repack
18+
Add this switch if ProjectRoot represents a folder with existing tarballs to be patched and repacked.
1719
#>
1820
param(
1921
[string]$ProjectRoot,
2022
[string]$OutputDirectory = "./artifacts/upm",
2123
[ValidatePattern("^\d+\.\d+\.\d+-?[a-zA-Z0-9\.]*$")]
2224
[string]$Version,
2325
[ValidatePattern("^\d+?[\.\d+]*$")]
24-
[string]$PreviewNumber
26+
[string]$PreviewNumber,
27+
[switch]$Repack
2528
)
2629

27-
[string]$startPath = $(Get-Location)
28-
2930
if (-not $ProjectRoot) {
3031
throw "Missing required parameter: -ProjectRoot."
3132
}
@@ -47,8 +48,6 @@ if (-not (Test-Path $OutputDirectory -PathType Container)) {
4748
$OutputDirectory = Resolve-Path -Path $OutputDirectory
4849
Write-Output "OutputDirectory: $OutputDirectory"
4950

50-
$scriptPath = "$ProjectRoot/scripts/packaging"
51-
5251
$scope = "com.microsoft.mixedreality"
5352
$product = "toolkit"
5453

@@ -66,13 +65,9 @@ $product = "toolkit"
6665
$packages = [ordered]@{
6766
"foundation" = "Assets/MRTK";
6867
"standardassets" = "Assets/MRTK/StandardAssets";
69-
# extensions
7068
"extensions" = "Assets/MRTK/Extensions";
71-
# tools
7269
"tools" = "Assets/MRTK/Tools";
73-
# tests
7470
"testutilities" = "Assets/MRTK/Tests/TestUtilities";
75-
# examples
7671
"examples" = "Assets/MRTK/Examples";
7772
}
7873

@@ -87,122 +82,134 @@ $packages = [ordered]@{
8782

8883
# Create and publish the packages
8984
foreach ($entry in $packages.GetEnumerator()) {
90-
$packageFolder = $entry.Value
91-
$packagePath = Resolve-Path -Path "$ProjectRoot/$packageFolder"
92-
93-
# Switch to the folder containing the package.json file
94-
Set-Location $packagePath
95-
96-
# The package manifest files what we use are actually templates,
97-
# rename the files so that npm can consume them.
98-
Rename-Item -Path "$packagePath/packagetemplate.json" -NewName "$packagePath/package.json"
99-
Rename-Item -Path "$packagePath/packagetemplate.json.meta" -NewName "$packagePath/package.json.meta"
100-
101-
# Apply the version number to the package json file
102-
$packageJsonPath = "$packagePath/package.json"
103-
((Get-Content -Path $packageJsonPath -Raw) -Replace '("version\": )"([0-9.]+-?[a-zA-Z0-9.]*|%version%)', "`$1`"$VersionWithPreview") | Set-Content -Path $packageJsonPath -NoNewline
104-
10585
# Create and publish the package
10686
$packageName = $entry.Name
10787

108-
$docFolder = "$packagePath/Documentation~"
109-
110-
# Copy files used by UPM to display license, change log, etc.
111-
Copy-Item -Path "$ProjectRoot/LICENSE.md" -Destination "$packagePath"
112-
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/LICENSE.md.meta.$packageName" -Destination "$packagePath/LICENSE.md.meta"
113-
Copy-Item -Path "$ProjectRoot/NOTICE.md" -Destination "$packagePath"
114-
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/NOTICE.md.meta.$packageName" -Destination "$packagePath/NOTICE.md.meta"
115-
Copy-Item -Path "$ProjectRoot/CHANGELOG.md" -Destination "$packagePath"
116-
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/CHANGELOG.md.meta.$packageName" -Destination "$packagePath/CHANGELOG.md.meta"
117-
Copy-Item -Path "$ProjectRoot/UPM/Documentation~" -Destination "$docFolder" -Recurse
118-
Copy-Item -Path "$ProjectRoot/Authors.md" -Destination "$docFolder"
119-
120-
$samplesFolder = "$packagePath/Samples~"
121-
122-
if ($packageName -eq "foundation") {
123-
# The foundation package contains files that are required to be copied into the Assets folder to be used.
124-
# In order to perform the necessary preparation, without overly complicating this script, we will use a
125-
# helper script to prepare the folder.
126-
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/foundationpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
127-
}
128-
elseif ($packageName -eq "standardassets") {
129-
# The standard assets package contains shaders that need to be imported into the Assets folder so that they
130-
# can be modified if the render pipeline is changed. To avoid duplicate resources (in library and assets)
131-
# we rename the Shaders folder to Shaders~, which makes it hidden to the Unity Editor.
132-
Rename-Item -Path "$packagePath/Shaders" -NewName "$packagePath/Shaders~"
133-
Remove-Item -Path "$packagePath/Shaders.meta"
134-
}
135-
elseif ($packageName -eq "examples") {
136-
# The examples folder is a collection of sample projects. In order to perform the necessary
137-
# preparation, without overly complicating this script, we will use a helper script to prepare
138-
# the folder.
139-
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/examplesfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
140-
}
141-
elseif ($packageName -eq "extensions") {
142-
# The extensions folder contains one or more folders that provide their own examples. In order
143-
# to perform the necessary preparation, without overly complicating this script, we will use a
144-
# helper script to prepare the folder.
145-
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/extensionsfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
88+
if ($Repack) {
89+
$packageTarball = "$scope.$product.$packageName"
90+
$tarballPath = Get-ChildItem -Path $ProjectRoot -Filter $packageTarball* -Name | Select-Object -First 1
91+
tar -xzf (Join-Path $ProjectRoot $tarballPath)
92+
$packagePath = Resolve-Path -Path "package"
14693
}
14794
else {
148-
# Some other folders have localized examples that need to be prepared. Intentionally skip the foundation as those samples
149-
$exampleFolder = "$packagePath/Examples"
150-
if (($PackageName -ne "foundation") -and (Test-Path -Path $exampleFolder)) {
151-
# Ensure the required samples exists
152-
if (-not (Test-Path -Path $samplesFolder)) {
153-
New-Item $samplesFolder -ItemType Directory | Out-Null
154-
}
95+
$packagePath = Resolve-Path -Path "$ProjectRoot/$($entry.Value)"
96+
}
15597

156-
# Copy the examples
157-
Write-Output "Copying $exampleFolder to $samplesFolder"
158-
Copy-Item -Path $exampleFolder -Destination $samplesFolder -Recurse -Force
98+
if (-not $Repack) {
99+
# The package manifest files what we use are actually templates,
100+
# rename the files so that npm can consume them.
101+
Rename-Item -Path "$packagePath/packagetemplate.json" -NewName "$packagePath/package.json"
102+
Rename-Item -Path "$packagePath/packagetemplate.json.meta" -NewName "$packagePath/package.json.meta"
103+
104+
$docFolder = "$packagePath/Documentation~"
105+
106+
# Copy files used by UPM to display license, change log, etc.
107+
Copy-Item -Path "$ProjectRoot/LICENSE.md" -Destination "$packagePath"
108+
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/LICENSE.md.meta.$packageName" -Destination "$packagePath/LICENSE.md.meta"
109+
Copy-Item -Path "$ProjectRoot/NOTICE.md" -Destination "$packagePath"
110+
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/NOTICE.md.meta.$packageName" -Destination "$packagePath/NOTICE.md.meta"
111+
Copy-Item -Path "$ProjectRoot/CHANGELOG.md" -Destination "$packagePath"
112+
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/CHANGELOG.md.meta.$packageName" -Destination "$packagePath/CHANGELOG.md.meta"
113+
Copy-Item -Path "$ProjectRoot/UPM/Documentation~" -Destination "$docFolder" -Recurse
114+
Copy-Item -Path "$ProjectRoot/Authors.md" -Destination "$docFolder"
115+
116+
$scriptPath = "$ProjectRoot/scripts/packaging"
117+
$samplesFolder = "$packagePath/Samples~"
118+
119+
if ($packageName -eq "foundation") {
120+
# The foundation package contains files that are required to be copied into the Assets folder to be used.
121+
# In order to perform the necessary preparation, without overly complicating this script, we will use a
122+
# helper script to prepare the folder.
123+
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/foundationpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
124+
}
125+
elseif ($packageName -eq "standardassets") {
126+
# The standard assets package contains shaders that need to be imported into the Assets folder so that they
127+
# can be modified if the render pipeline is changed. To avoid duplicate resources (in library and assets)
128+
# we rename the Shaders folder to Shaders~, which makes it hidden to the Unity Editor.
129+
Rename-Item -Path "$packagePath/Shaders" -NewName "$packagePath/Shaders~"
130+
Remove-Item -Path "$packagePath/Shaders.meta"
131+
}
132+
elseif ($packageName -eq "examples") {
133+
# The examples folder is a collection of sample projects. In order to perform the necessary
134+
# preparation, without overly complicating this script, we will use a helper script to prepare
135+
# the folder.
136+
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/examplesfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
137+
}
138+
elseif ($packageName -eq "extensions") {
139+
# The extensions folder contains one or more folders that provide their own examples. In order
140+
# to perform the necessary preparation, without overly complicating this script, we will use a
141+
# helper script to prepare the folder.
142+
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/extensionsfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
143+
}
144+
else {
145+
# Some other folders have localized examples that need to be prepared. Intentionally skip the foundation as those samples
146+
$exampleFolder = "$packagePath/Examples"
147+
if (($PackageName -ne "foundation") -and (Test-Path -Path $exampleFolder)) {
148+
# Ensure the required samples exists
149+
if (-not (Test-Path -Path $samplesFolder)) {
150+
New-Item $samplesFolder -ItemType Directory | Out-Null
151+
}
152+
153+
# Copy the examples
154+
Write-Output "Copying $exampleFolder to $samplesFolder"
155+
Copy-Item -Path $exampleFolder -Destination $samplesFolder -Recurse -Force
156+
}
159157
}
160158
}
161159

160+
# Apply the version number to the package json file
161+
$packageJsonPath = "$packagePath/package.json"
162+
((Get-Content -Path $packageJsonPath -Raw) -Replace '("version\": )"([0-9.]+-?[a-zA-Z0-9.]*|%version%)', "`$1`"$Version") | Set-Content -Path $packageJsonPath -NoNewline
163+
162164
Write-Output "======================="
163165
Write-Output "Creating $scope.$product.$packageName"
164166
Write-Output "======================="
165-
npm pack
167+
npm pack $packagePath
166168

167169
# Move package file to OutputFolder
168-
Move-Item -Path "./*.tgz" $OutputDirectory -Force
170+
Move-Item -Path "./$scope.$product.$packageName-$Version.tgz" $OutputDirectory -Force
169171

170172
# ======================
171173
# Cleanup the changes we have made
172174
# ======================
173175
Write-Output "Cleaning up temporary changes"
174176

175-
if (Test-Path -Path $samplesFolder) {
176-
# A samples folder was created. Remove it.
177-
Remove-Item -Path $samplesFolder -Recurse -Force
178-
}
179-
180-
if ($packageName -eq "foundation") {
181-
# The foundation package MOVES some content around. This restores the moved files.
182-
Start-Process -FilePath "git" -ArgumentList "checkout Services/SceneSystem/SceneSystemResources*" -NoNewWindow -Wait
183-
}
184-
elseif ($packageName -eq "standardassets") {
185-
# The standard assets package RENAMES and DELETES some content. This restores the original files.
186-
Rename-Item -Path "$packagePath/Shaders~" -NewName "$packagePath/Shaders"
187-
Start-Process -FilePath "git" -ArgumentList "checkout Shaders.meta" -NoNewWindow -Wait
177+
if ($Repack) {
178+
# Clean up the unpacked tarball folder
179+
if (Test-Path -Path $packagePath) {
180+
Remove-Item -Path $packagePath -Recurse -Force
181+
}
188182
}
183+
else {
184+
if (Test-Path -Path $samplesFolder) {
185+
# A samples folder was created. Remove it.
186+
Remove-Item -Path $samplesFolder -Recurse -Force
187+
}
188+
189+
if ($packageName -eq "foundation") {
190+
# The foundation package MOVES some content around. This restores the moved files.
191+
Start-Process -FilePath "git" -ArgumentList "checkout Services/SceneSystem/SceneSystemResources*" -NoNewWindow -Wait
192+
}
193+
elseif ($packageName -eq "standardassets") {
194+
# The standard assets package RENAMES and DELETES some content. This restores the original files.
195+
Rename-Item -Path "$packagePath/Shaders~" -NewName "$packagePath/Shaders"
196+
Start-Process -FilePath "git" -ArgumentList "checkout Shaders.meta" -NoNewWindow -Wait
197+
}
189198

190-
# Delete the files copied in previously
191-
Remove-Item -Path "$packagePath/LICENSE.md*"
192-
Remove-Item -Path "$packagePath/NOTICE.md*"
193-
Remove-Item -Path "$packagePath/CHANGELOG.md*"
194-
if (Test-Path -Path $docFolder) {
195-
# A documentation folder was created. Remove it.
196-
Remove-Item -Path $docFolder -Recurse -Force
197-
}
199+
# Delete the files copied in previously
200+
Remove-Item -Path "$packagePath/LICENSE.md*"
201+
Remove-Item -Path "$packagePath/NOTICE.md*"
202+
Remove-Item -Path "$packagePath/CHANGELOG.md*"
203+
if (Test-Path -Path $docFolder) {
204+
# A documentation folder was created. Remove it.
205+
Remove-Item -Path $docFolder -Recurse -Force
206+
}
198207

199-
# Delete the renamed package.json.* files
200-
Remove-Item -Path "$packagePath/package.json"
201-
Remove-Item -Path "$packagePath/package.json.meta"
208+
# Delete the renamed package.json.* files
209+
Remove-Item -Path "$packagePath/package.json"
210+
Remove-Item -Path "$packagePath/package.json.meta"
202211

203-
# Restore original files
204-
Start-Process -FilePath "git" -ArgumentList "checkout packagetemplate.*" -NoNewWindow -Wait
212+
# Restore original files
213+
Start-Process -FilePath "git" -ArgumentList "checkout packagetemplate.*" -NoNewWindow -Wait
214+
}
205215
}
206-
207-
# Return to the starting path
208-
Set-Location $startPath

0 commit comments

Comments
 (0)