Make Tauri prebuild cross-platform and remove legacy PS hook
This commit is contained in:
parent
f8760155e4
commit
3a4fe86e20
@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"tauri:prebuild": "pwsh -NoProfile -ExecutionPolicy Bypass -File ../scripts/tauri-prebuild.ps1",
|
"tauri:prebuild": "node ./scripts/tauri-prebuild.mjs",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
|
|||||||
81
Journal.App/scripts/tauri-prebuild.mjs
Normal file
81
Journal.App/scripts/tauri-prebuild.mjs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
const appRoot = path.resolve(__dirname, "..");
|
||||||
|
const repoRoot = path.resolve(appRoot, "..");
|
||||||
|
|
||||||
|
const sidecarProject = path.join(
|
||||||
|
repoRoot,
|
||||||
|
"Journal.Sidecar",
|
||||||
|
"Journal.Sidecar.csproj",
|
||||||
|
);
|
||||||
|
const publishOutputDir = path.join(repoRoot, "output");
|
||||||
|
const tauriBinDir = path.join(appRoot, "src-tauri", "bin");
|
||||||
|
|
||||||
|
function runtimeForCurrentPlatform() {
|
||||||
|
const arch = process.arch;
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
if (arch === "arm64") return "win-arm64";
|
||||||
|
return "win-x64";
|
||||||
|
}
|
||||||
|
if (process.platform === "linux") {
|
||||||
|
if (arch === "arm64") return "linux-arm64";
|
||||||
|
return "linux-x64";
|
||||||
|
}
|
||||||
|
if (process.platform === "darwin") {
|
||||||
|
if (arch === "arm64") return "osx-arm64";
|
||||||
|
return "osx-x64";
|
||||||
|
}
|
||||||
|
throw new Error(`Unsupported platform '${process.platform}' for sidecar publish.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sidecarFileName() {
|
||||||
|
return process.platform === "win32" ? "Journal.Sidecar.exe" : "Journal.Sidecar";
|
||||||
|
}
|
||||||
|
|
||||||
|
const runtime = runtimeForCurrentPlatform();
|
||||||
|
const sidecarName = sidecarFileName();
|
||||||
|
const publishedSidecar = path.join(publishOutputDir, sidecarName);
|
||||||
|
const bundledSidecar = path.join(tauriBinDir, sidecarName);
|
||||||
|
|
||||||
|
console.log(`Publishing sidecar for ${process.platform}/${process.arch} (${runtime})...`);
|
||||||
|
|
||||||
|
const publishArgs = [
|
||||||
|
"publish",
|
||||||
|
sidecarProject,
|
||||||
|
"-c",
|
||||||
|
"Release",
|
||||||
|
"-r",
|
||||||
|
runtime,
|
||||||
|
"--self-contained",
|
||||||
|
"-p:PublishSingleFile=true",
|
||||||
|
"-p:IncludeNativeLibrariesForSelfExtract=true",
|
||||||
|
"-p:RestoreIgnoreFailedSources=true",
|
||||||
|
"-p:NuGetAudit=false",
|
||||||
|
"-o",
|
||||||
|
publishOutputDir,
|
||||||
|
];
|
||||||
|
|
||||||
|
const publish = spawnSync("dotnet", publishArgs, {
|
||||||
|
cwd: repoRoot,
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (publish.error) {
|
||||||
|
throw publish.error;
|
||||||
|
}
|
||||||
|
if (publish.status !== 0) {
|
||||||
|
process.exit(publish.status ?? 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!existsSync(publishedSidecar)) {
|
||||||
|
throw new Error(`Published sidecar not found: ${publishedSidecar}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdirSync(tauriBinDir, { recursive: true });
|
||||||
|
copyFileSync(publishedSidecar, bundledSidecar);
|
||||||
|
console.log(`Staged sidecar for Tauri: ${bundledSidecar}`);
|
||||||
@ -25,7 +25,7 @@
|
|||||||
"active": true,
|
"active": true,
|
||||||
"targets": "all",
|
"targets": "all",
|
||||||
"resources": [
|
"resources": [
|
||||||
"bin/Journal.Sidecar.exe"
|
"bin"
|
||||||
],
|
],
|
||||||
"icon": [
|
"icon": [
|
||||||
"icons/32x32.png",
|
"icons/32x32.png",
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
param(
|
|
||||||
[ValidateSet("Release", "Debug")]
|
|
||||||
[string]$Configuration = "Release",
|
|
||||||
[string]$Runtime = "win-x64"
|
|
||||||
)
|
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
|
||||||
|
|
||||||
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
|
|
||||||
$sidecarProject = Join-Path $repoRoot "Journal.Sidecar\Journal.Sidecar.csproj"
|
|
||||||
$publishOutputDir = Join-Path $repoRoot "output"
|
|
||||||
$publishedSidecarExe = Join-Path $publishOutputDir "Journal.Sidecar.exe"
|
|
||||||
$tauriBinDir = Join-Path $repoRoot "Journal.App\src-tauri\bin"
|
|
||||||
$tauriBundledSidecarExe = Join-Path $tauriBinDir "Journal.Sidecar.exe"
|
|
||||||
|
|
||||||
if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) {
|
|
||||||
throw "dotnet was not found in PATH. Install .NET SDK and retry."
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not (Test-Path $sidecarProject)) {
|
|
||||||
throw "Sidecar project not found: $sidecarProject"
|
|
||||||
}
|
|
||||||
|
|
||||||
New-Item -ItemType Directory -Force -Path $publishOutputDir | Out-Null
|
|
||||||
|
|
||||||
$publishArgs = @(
|
|
||||||
"publish", $sidecarProject,
|
|
||||||
"-c", $Configuration,
|
|
||||||
"-r", $Runtime,
|
|
||||||
"--self-contained",
|
|
||||||
"-p:PublishSingleFile=true",
|
|
||||||
"-p:IncludeNativeLibrariesForSelfExtract=true",
|
|
||||||
"-p:RestoreIgnoreFailedSources=true",
|
|
||||||
"-p:NuGetAudit=false",
|
|
||||||
"-o", $publishOutputDir
|
|
||||||
)
|
|
||||||
|
|
||||||
Write-Host "Publishing Journal.Sidecar for Tauri bundle..." -ForegroundColor Cyan
|
|
||||||
Write-Host "> dotnet $($publishArgs -join ' ')" -ForegroundColor DarkGray
|
|
||||||
& dotnet @publishArgs
|
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
|
||||||
throw "dotnet publish failed with exit code $LASTEXITCODE."
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not (Test-Path $publishedSidecarExe)) {
|
|
||||||
throw "Sidecar publish output not found: $publishedSidecarExe"
|
|
||||||
}
|
|
||||||
|
|
||||||
New-Item -ItemType Directory -Force -Path $tauriBinDir | Out-Null
|
|
||||||
Copy-Item -Force $publishedSidecarExe $tauriBundledSidecarExe
|
|
||||||
Write-Host "Staged sidecar for Tauri: $tauriBundledSidecarExe" -ForegroundColor Green
|
|
||||||
Loading…
x
Reference in New Issue
Block a user