Skip to content

Commit ed8b46c

Browse files
committed
fix: refactor
1 parent 1d026fe commit ed8b46c

3 files changed

Lines changed: 35 additions & 44 deletions

File tree

‎.github/workflows/publish_jsr.yml‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ jobs:
4949
- name: 'Prepare files for JSR'
5050
shell: pwsh
5151
run: |
52-
$dll = Join-Path (Get-Location) "artifacts/libcpp_bindings_windows.dll"
53-
if (-not (Test-Path $dll)) { throw "DLL not found: $dll" }
5452
New-Item -ItemType Directory -Force -Path jsr/bin | Out-Null
55-
./jsr/scripts/embed_binary.ps1 $dll jsr/bin windows-x86_64
56-
Copy-Item -Force LICENSE jsr/LICENSE
53+
54+
Copy-Item -Force -LiteralPath artifacts/libcpp_bindings_windows.dll -Destination jsr/bin/libcpp_bindings_windows.dll
55+
56+
./jsr/scripts/binary_to_json.ps1 artifacts/libcpp_bindings_windows.dll jsr/bin/x86_64.json windows-x86_64
57+
5758
./jsr/scripts/set_version.ps1 jsr/jsr.json "${{ inputs.version }}"
5859
5960
- name: 'Publish package to JSR (normal)'

‎jsr/scripts/binary_to_json.ps1‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
param(
2+
[Parameter(Mandatory = $true)][string]$BinaryFilePath,
3+
[Parameter(Mandatory = $true)][string]$JsonFilePath,
4+
[Parameter(Mandatory = $true)][string]$Target
5+
)
6+
7+
$ErrorActionPreference = "Stop"
8+
9+
if (-not (Test-Path -LiteralPath $BinaryFilePath) -or (Get-Item -LiteralPath $BinaryFilePath).PSIsContainer) {
10+
Write-Error "Error: Binary path is not a file: $BinaryFilePath"
11+
exit 1
12+
}
13+
14+
$filename = [System.IO.Path]::GetFileName($BinaryFilePath)
15+
16+
New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetDirectoryName($JsonFilePath)) | Out-Null
17+
18+
$bytes = [System.IO.File]::ReadAllBytes($BinaryFilePath)
19+
$b64 = [System.Convert]::ToBase64String($bytes)
20+
21+
$obj = [ordered]@{
22+
target = $Target
23+
filename = $filename
24+
encoding = "base64"
25+
data = $b64
26+
}
27+
28+
$json = ($obj | ConvertTo-Json -Compress)
29+
30+
Set-Content -Path $JsonFilePath -Value $json -NoNewline -Encoding utf8NoBOM

‎jsr/scripts/embed_binary.ps1‎

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)