14
14
What version of the artifacts should we build?
15
15
. PARAMETER PreviewNumber
16
16
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.
17
19
#>
18
20
param (
19
21
[string ]$ProjectRoot ,
20
22
[string ]$OutputDirectory = " ./artifacts/upm" ,
21
23
[ValidatePattern (" ^\d+\.\d+\.\d+-?[a-zA-Z0-9\.]*$" )]
22
24
[string ]$Version ,
23
25
[ValidatePattern (" ^\d+?[\.\d+]*$" )]
24
- [string ]$PreviewNumber
26
+ [string ]$PreviewNumber ,
27
+ [switch ]$Repack
25
28
)
26
29
27
- [string ]$startPath = $ (Get-Location )
28
-
29
30
if (-not $ProjectRoot ) {
30
31
throw " Missing required parameter: -ProjectRoot."
31
32
}
@@ -47,8 +48,6 @@ if (-not (Test-Path $OutputDirectory -PathType Container)) {
47
48
$OutputDirectory = Resolve-Path - Path $OutputDirectory
48
49
Write-Output " OutputDirectory: $OutputDirectory "
49
50
50
- $scriptPath = " $ProjectRoot /scripts/packaging"
51
-
52
51
$scope = " com.microsoft.mixedreality"
53
52
$product = " toolkit"
54
53
@@ -66,13 +65,9 @@ $product = "toolkit"
66
65
$packages = [ordered ]@ {
67
66
" foundation" = " Assets/MRTK" ;
68
67
" standardassets" = " Assets/MRTK/StandardAssets" ;
69
- # extensions
70
68
" extensions" = " Assets/MRTK/Extensions" ;
71
- # tools
72
69
" tools" = " Assets/MRTK/Tools" ;
73
- # tests
74
70
" testutilities" = " Assets/MRTK/Tests/TestUtilities" ;
75
- # examples
76
71
" examples" = " Assets/MRTK/Examples" ;
77
72
}
78
73
@@ -87,122 +82,134 @@ $packages = [ordered]@{
87
82
88
83
# Create and publish the packages
89
84
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
-
105
85
# Create and publish the package
106
86
$packageName = $entry.Name
107
87
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"
146
93
}
147
94
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
+ }
155
97
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
+ }
159
157
}
160
158
}
161
159
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
+
162
164
Write-Output " ======================="
163
165
Write-Output " Creating $scope .$product .$packageName "
164
166
Write-Output " ======================="
165
- npm pack
167
+ npm pack $packagePath
166
168
167
169
# Move package file to OutputFolder
168
- Move-Item - Path " ./* .tgz" $OutputDirectory - Force
170
+ Move-Item - Path " ./$scope . $product . $packageName - $Version .tgz" $OutputDirectory - Force
169
171
170
172
# ======================
171
173
# Cleanup the changes we have made
172
174
# ======================
173
175
Write-Output " Cleaning up temporary changes"
174
176
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
+ }
188
182
}
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
+ }
189
198
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
+ }
198
207
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"
202
211
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
+ }
205
215
}
206
-
207
- # Return to the starting path
208
- Set-Location $startPath
0 commit comments