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,124 +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
- $packageJson = [System.IO.File ]::ReadAllText($packageJsonPath )
104
- $packageJson = ($packageJson -replace " %version%" , $Version )
105
- [System.IO.File ]::WriteAllText($packageJsonPath , $packageJson )
106
-
107
85
# Create and publish the package
108
86
$packageName = $entry.Name
109
87
110
- $docFolder = " $packagePath /Documentation~"
111
-
112
- # Copy files used by UPM to display license, change log, etc.
113
- Copy-Item - Path " $ProjectRoot /LICENSE.md" - Destination " $packagePath "
114
- Copy-Item - Path " $ProjectRoot /UPM/UnityMetaFiles/LICENSE.md.meta.$packageName " - Destination " $packagePath /LICENSE.md.meta"
115
- Copy-Item - Path " $ProjectRoot /NOTICE.md" - Destination " $packagePath "
116
- Copy-Item - Path " $ProjectRoot /UPM/UnityMetaFiles/NOTICE.md.meta.$packageName " - Destination " $packagePath /NOTICE.md.meta"
117
- Copy-Item - Path " $ProjectRoot /CHANGELOG.md" - Destination " $packagePath "
118
- Copy-Item - Path " $ProjectRoot /UPM/UnityMetaFiles/CHANGELOG.md.meta.$packageName " - Destination " $packagePath /CHANGELOG.md.meta"
119
- Copy-Item - Path " $ProjectRoot /UPM/Documentation~" - Destination " $docFolder " - Recurse
120
- Copy-Item - Path " $ProjectRoot /Authors.md" - Destination " $docFolder "
121
-
122
- $samplesFolder = " $packagePath /Samples~"
123
-
124
- if ($packageName -eq " foundation" ) {
125
- # The foundation package contains files that are required to be copied into the Assets folder to be used.
126
- # In order to perform the necessary preparation, without overly complicating this script, we will use a
127
- # helper script to prepare the folder.
128
- Start-Process - FilePath " $PSHOME /powershell.exe" - ArgumentList " $scriptPath /foundationpreupm.ps1 -PackageRoot $packagePath " - NoNewWindow - Wait
129
- }
130
- elseif ($packageName -eq " standardassets" ) {
131
- # The standard assets package contains shaders that need to be imported into the Assets folder so that they
132
- # can be modified if the render pipeline is changed. To avoid duplicate resources (in library and assets)
133
- # we rename the Shaders folder to Shaders~, which makes it hidden to the Unity Editor.
134
- Rename-Item - Path " $packagePath /Shaders" - NewName " $packagePath /Shaders~"
135
- Remove-Item - Path " $packagePath /Shaders.meta"
136
- }
137
- elseif ($packageName -eq " examples" ) {
138
- # The examples folder is a collection of sample projects. In order to perform the necessary
139
- # preparation, without overly complicating this script, we will use a helper script to prepare
140
- # the folder.
141
- Start-Process - FilePath " $PSHOME /powershell.exe" - ArgumentList " $scriptPath /examplesfolderpreupm.ps1 -PackageRoot $packagePath " - NoNewWindow - Wait
142
- }
143
- elseif ($packageName -eq " extensions" ) {
144
- # The extensions folder contains one or more folders that provide their own examples. In order
145
- # to perform the necessary preparation, without overly complicating this script, we will use a
146
- # helper script to prepare the folder.
147
- 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"
148
93
}
149
94
else {
150
- # Some other folders have localized examples that need to be prepared. Intentionally skip the foundation as those samples
151
- $exampleFolder = " $packagePath /Examples"
152
- if (($PackageName -ne " foundation" ) -and (Test-Path - Path $exampleFolder )) {
153
- # Ensure the required samples exists
154
- if (-not (Test-Path - Path $samplesFolder )) {
155
- New-Item $samplesFolder - ItemType Directory | Out-Null
156
- }
95
+ $packagePath = Resolve-Path - Path " $ProjectRoot /$ ( $entry.Value ) "
96
+ }
157
97
158
- # Copy the examples
159
- Write-Output " Copying $exampleFolder to $samplesFolder "
160
- 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
+ }
161
157
}
162
158
}
163
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
+
164
164
Write-Output " ======================="
165
165
Write-Output " Creating $scope .$product .$packageName "
166
166
Write-Output " ======================="
167
- npm pack
167
+ npm pack $packagePath
168
168
169
169
# Move package file to OutputFolder
170
- Move-Item - Path " ./* .tgz" $OutputDirectory - Force
170
+ Move-Item - Path " ./$scope . $product . $packageName - $Version .tgz" $OutputDirectory - Force
171
171
172
172
# ======================
173
173
# Cleanup the changes we have made
174
174
# ======================
175
175
Write-Output " Cleaning up temporary changes"
176
176
177
- if (Test-Path - Path $samplesFolder ) {
178
- # A samples folder was created. Remove it.
179
- Remove-Item - Path $samplesFolder - Recurse - Force
180
- }
181
-
182
- if ($packageName -eq " foundation" ) {
183
- # The foundation package MOVES some content around. This restores the moved files.
184
- Start-Process - FilePath " git" - ArgumentList " checkout Services/SceneSystem/SceneSystemResources*" - NoNewWindow - Wait
185
- }
186
- elseif ($packageName -eq " standardassets" ) {
187
- # The standard assets package RENAMES and DELETES some content. This restores the original files.
188
- Rename-Item - Path " $packagePath /Shaders~" - NewName " $packagePath /Shaders"
189
- 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
+ }
190
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
+ }
191
198
192
- # Delete the files copied in previously
193
- Remove-Item - Path " $packagePath /LICENSE.md*"
194
- Remove-Item - Path " $packagePath /NOTICE.md*"
195
- Remove-Item - Path " $packagePath /CHANGELOG.md*"
196
- if (Test-Path - Path $docFolder ) {
197
- # A documentation folder was created. Remove it.
198
- Remove-Item - Path $docFolder - Recurse - Force
199
- }
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
+ }
200
207
201
- # Delete the renamed package.json.* files
202
- Remove-Item - Path " $packagePath /package.json"
203
- 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"
204
211
205
- # Restore original files
206
- Start-Process - FilePath " git" - ArgumentList " checkout packagetemplate.*" - NoNewWindow - Wait
212
+ # Restore original files
213
+ Start-Process - FilePath " git" - ArgumentList " checkout packagetemplate.*" - NoNewWindow - Wait
214
+ }
207
215
}
208
-
209
- # Return to the starting path
210
- Set-Location $startPath
0 commit comments