Skip to content

Commit ac4d3b2

Browse files
authored
feat: Feature/codex install update (#35)
* Add codex-install.ps1 script for Windows installation * Update codex-install.ps1 with latest changes from windows-codex-installer * Update codex-install.ps1 with BOM-less file writing and formatting
1 parent bab6e81 commit ac4d3b2

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

codex-install.ps1

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ function Invoke-GitCommand {
3232
}
3333
}
3434

35+
function Write-TextFileNoBom {
36+
param(
37+
[Parameter(Mandatory = $true)]
38+
[string] $Path,
39+
40+
[Parameter(Mandatory = $true)]
41+
[string] $Content
42+
)
43+
44+
if ($PSVersionTable.PSVersion.Major -ge 6) {
45+
$Content | Set-Content -LiteralPath $Path -Encoding utf8NoBOM
46+
return
47+
}
48+
49+
# Windows PowerShell 5.1 lacks utf8NoBOM. For this file we only emit ASCII JSON,
50+
# so ASCII preserves valid JSON bytes while avoiding a UTF-8 BOM.
51+
$Content | Set-Content -LiteralPath $Path -Encoding ascii
52+
}
53+
3554
Write-Host "--- $pluginName Installer for Codex ---"
3655

3756
New-Item -ItemType Directory -Force -Path $pluginsRoot | Out-Null
@@ -58,7 +77,7 @@ if (Test-Path $installDir) {
5877

5978
if (-not (Test-Path $marketplaceFile)) {
6079
Write-Host "Creating new personal marketplace..."
61-
'{"name":"personal","plugins":[]}' | Set-Content -LiteralPath $marketplaceFile -Encoding utf8
80+
Write-TextFileNoBom -Path $marketplaceFile -Content '{"name":"personal","plugins":[]}'
6281
}
6382

6483
Write-Host "Registering plugin in $marketplaceFile..."
@@ -90,6 +109,8 @@ if ($null -eq $marketplace.plugins) {
90109
}
91110

92111
$marketplace.plugins += $newPlugin
93-
$marketplace | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $marketplaceFile -Encoding utf8
112+
$marketplaceJson = $marketplace | ConvertTo-Json -Depth 10
113+
$marketplaceJson = $marketplaceJson -replace '":\s+', '": '
114+
Write-TextFileNoBom -Path $marketplaceFile -Content $marketplaceJson
94115

95116
Write-Host "Done! Restart Codex to use the $pluginName plugin."

0 commit comments

Comments
 (0)