Skip to content

Commit 69435f7

Browse files
committed
dynamic allocation, only edit platforms, bug fixes
1 parent c1a5acc commit 69435f7

File tree

3 files changed

+232
-322
lines changed

3 files changed

+232
-322
lines changed

win/common-utils.ps1

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ $script:WORKSPACE_DIR = Join-Path $env:USERPROFILE ".browserstack"
55
$script:PROJECT_FOLDER = "NOW"
66
$script:NOW_OS = "windows"
77

8-
98
$script:GLOBAL_DIR = Join-Path $WORKSPACE_DIR $PROJECT_FOLDER
109
$script:LOG_DIR = Join-Path $GLOBAL_DIR "logs"
1110
$script:GLOBAL_LOG = ""
@@ -112,6 +111,50 @@ function Invoke-GitClone {
112111
}
113112
}
114113

114+
function Reset-BrowserStackConfigFile {
115+
param(
116+
[Parameter(Mandatory)][string]$RepoRoot,
117+
[Parameter(Mandatory)][string]$RelativePath
118+
)
119+
$gitDir = Join-Path $RepoRoot ".git"
120+
if (!(Test-Path $gitDir)) { return }
121+
$normalized = $RelativePath -replace '\\','/'
122+
try {
123+
[void](Invoke-External -Exe "git" -Arguments @("checkout","--",$normalized) -LogFile $GLOBAL_LOG -WorkingDirectory $RepoRoot)
124+
} catch {
125+
Log-Line "⚠️ Unable to reset $RelativePath via git checkout ($($_.Exception.Message))" $GLOBAL_LOG
126+
}
127+
}
128+
129+
function Set-BrowserStackPlatformsSection {
130+
param(
131+
[Parameter(Mandatory)][string]$RepoRoot,
132+
[Parameter(Mandatory)][string]$RelativeConfigPath,
133+
[Parameter(Mandatory)][string]$PlatformsYaml
134+
)
135+
136+
$configPath = Join-Path $RepoRoot $RelativeConfigPath
137+
if (!(Test-Path $configPath)) {
138+
throw "browserstack config not found: $configPath"
139+
}
140+
141+
Reset-BrowserStackConfigFile -RepoRoot $RepoRoot -RelativePath $RelativeConfigPath
142+
143+
$normalizedPlatforms = ($PlatformsYaml -replace "`r","").TrimEnd("`n")
144+
$blockBuilder = New-Object System.Text.StringBuilder
145+
[void]$blockBuilder.AppendLine("")
146+
[void]$blockBuilder.AppendLine("platforms:")
147+
if (-not [string]::IsNullOrWhiteSpace($normalizedPlatforms)) {
148+
foreach ($line in ($normalizedPlatforms -split "`n")) {
149+
[void]$blockBuilder.AppendLine($line)
150+
}
151+
}
152+
153+
$appendText = ($blockBuilder.ToString() -replace "`n","`r`n")
154+
Add-Content -Path $configPath -Value $appendText
155+
Log-Line "✅ Updated platforms in $RelativeConfigPath" $GLOBAL_LOG
156+
}
157+
115158
function Set-ContentNoBom {
116159
param(
117160
[Parameter(Mandatory)][string]$Path,

0 commit comments

Comments
 (0)