mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
This is a re-write of the generate-dev-bundle.ps1 script, which occurred during debugging of an unrelated concern of the (new) 64-bit Windows build on our Jenkins server. Ultimately, I'm afraid this script doesn't solve the problem I originally set out to fix, which was a Windows long-file path concern. The hunch behind that thinking was that the use of npm@1 to install npm@5 could be causing problems, since npm@1 had no concept of nested node_modules directories. We had used npm@1 because Node.js for Windows hasn't always offered (via nodejs.org/dist/) versions including npm which we could use to install our own requirements. Happily, that is no longer the case! While this script now deals with long paths much more gracefully itself, I'm not sure it completely quelled the long-path issue, and there are still some directory trees which are longer than I think they should be. The warnings I was seeing may not have harmed the actual bundle and were more problematic for this build script itself when it tried to deal with the aftermath of all those files, since native Windows commands struggle to deal with long file paths (when cleaning up, etc.). In the end, this script does have performance enhancements though! For starters, it's nearly twice as fast at finishing. Most of this was gained by avoiding back-and-forth moving of large file structures, opting instead to directly install into the targets when possible. It also ensures that the npm build cache is not bundled, which started occurring since our modification of the $HOME and $USERPROFILE variables led npm@5 to think the npm cache was in the root of the bundle. Additionally, it no longer modifies the $PATH, in any way, during the build. This became particularly helpful during testing when I found that PowerShell maintained that $PATH in the environment of the host shell. I'd like to say it increases readability of the script, which had become a bit of a patchwork quilt, but that's YTBD and YMMV. This is my first "complete" PowerShell script myself so it probably still leaves some things to desired, formatting wise. Functionality- wise, I hope it's improved.
118 lines
3.2 KiB
PowerShell
118 lines
3.2 KiB
PowerShell
# This is the "/scripts" directory, useful for accessing other scripts.
|
|
$scriptsDir = (Get-Item $PSScriptRoot).parent.FullName
|
|
|
|
# This is the root of the Meteor repository.
|
|
$rootDir = (Get-Item $scriptsDir).parent.FullName
|
|
|
|
echo "Root $rootDir"
|
|
|
|
# This is the "meteor" shell script.
|
|
$meteorSh = Join-Path $rootDir 'meteor'
|
|
|
|
<#
|
|
.Synopsis
|
|
Get the architecture for the Meteor Dev Bundle
|
|
|
|
.Description
|
|
Determine the architecture (64-bit/32-bit) from the environment,
|
|
taking into consideration the PLATFORM override environment variable,
|
|
which is used by Jenkins when building the dev bundle for Windows.
|
|
|
|
Otherwise, use logic similar to that of Chocolatey's
|
|
Get-OSArchitectureWidth method, as seen here: https://git.io/vd2e9
|
|
#>
|
|
Function Get-MeteorPlatform {
|
|
if (Test-Path env:PLATFORM) {
|
|
$PLATFORM = (Get-Item env:PLATFORM).Value
|
|
} elseif (([System.IntPtr]::Size -eq 4) -and (Test-Path env:\PROCESSOR_ARCHITEW6432)) {
|
|
$PLATFORM = "windows_x64"
|
|
} elseif ([System.IntPtr]::Size -eq 4) {
|
|
$PLATFORM = "windows_x86"
|
|
} else {
|
|
$PLATFORM = "windows_x64"
|
|
}
|
|
$PLATFORM
|
|
}
|
|
|
|
<#
|
|
.Synopsis
|
|
Get a shell script variable out of a regular Bash script.
|
|
#>
|
|
Function Read-VariableFromShellScript {
|
|
Param (
|
|
[Parameter(Mandatory=$True, Position=0)]
|
|
[string]$Path,
|
|
[Parameter(Mandatory=$True, Position=1)]
|
|
[string]$Name
|
|
)
|
|
$v = Select-String -Path $Path -Pattern "^\s*${Name}=(\S+)" | `
|
|
% { $_.Matches[0].Groups[1].Value } | `
|
|
Select-Object -First 1
|
|
$v = $v.Trim()
|
|
$v
|
|
}
|
|
|
|
Function New-TemporaryDirectory {
|
|
$parent = [System.IO.Path]::GetTempPath()
|
|
[string] $name = [System.Guid]::NewGuid()
|
|
New-Item -ItemType Directory -Path (Join-Path $parent $name)
|
|
}
|
|
|
|
Function Remove-DirectoryRecursively {
|
|
Param (
|
|
[Parameter(Mandatory=$True, Position=0)]
|
|
[string]$Path
|
|
)
|
|
if (Test-Path -LiteralPath $Path -PathType 'Container') {
|
|
$emptyTempDir = New-TemporaryDirectory
|
|
# Quietly use Robocopy to sync the Path with an empty directory.
|
|
& robocopy.exe $emptyTempDir $Path /purge | Out-Null
|
|
Remove-Item $Path -Recurse -Force
|
|
Remove-Item $emptyTempDir -Force
|
|
# # Get-ChildItem $(Join-Path $Path '*') -Recurse | Remove-Item -Force -Recurse
|
|
# del /f /s /q $Path 1>nul
|
|
# start /wait rmdir $Path /s /q | Out-Null
|
|
}
|
|
}
|
|
|
|
Function Expand-TarGzToDirectory {
|
|
Param (
|
|
[Parameter(Mandatory=$True, Position=0)]
|
|
[string]$Path,
|
|
[Parameter(Mandatory=$True, Position=1)]
|
|
[string]$Destination,
|
|
[string]$Binary = "7z.exe"
|
|
)
|
|
& cmd /C "$Binary x $Path -so | $Binary x -aoa -si -ttar -o$Destination"
|
|
if ($LASTEXITCODE -eq 0) {
|
|
return $True
|
|
}
|
|
$False
|
|
}
|
|
|
|
Function Expand-7zToDirectory {
|
|
Param (
|
|
[Parameter(Mandatory=$True, Position=0)]
|
|
[string]$Path,
|
|
[Parameter(Mandatory=$True, Position=1)]
|
|
[string]$Destination,
|
|
[string]$Binary = "7z.exe"
|
|
)
|
|
& "$Binary" x "$Path" -o"$Destination" | Out-Null
|
|
}
|
|
|
|
Function Add-ToExistingEnvPath {
|
|
Param(
|
|
[Parameter(Mandatory=$True, Position=0)]
|
|
[string]$Path
|
|
)
|
|
$env:PATH = "$Path;${env:PATH}"
|
|
}
|
|
|
|
Export-ModuleMember -Function `
|
|
Add-ToExistingEnvPath, `
|
|
Expand-7zToDirectory, `
|
|
Expand-TarGzToDirectory, `
|
|
Get-MeteorPlatform, `
|
|
Read-VariableFromShellScript, `
|
|
Remove-DirectoryRecursively |