tauri-plugin-audioplayer 0.1.2

Tauri Audioplayer Plugin
[CmdletBinding()]
param(
  [switch]$SkipDependencies,
  [switch]$SkipChecks
)

$ErrorActionPreference = "Stop"
$script:ExitCode = 0
$RootDir = $PSScriptRoot
$DemoDir = Join-Path $RootDir "examples/demo"

function Write-Status {
  param([string]$Level, [string]$Message, [ConsoleColor]$Color)
  Write-Host "[$Level] " -ForegroundColor $Color -NoNewline
  Write-Host $Message
}

function Ok { param([string]$Message) Write-Status "OK" $Message Green }
function Warn { param([string]$Message) Write-Status "WARN" $Message Yellow }
function Fail {
  param([string]$Message)
  Write-Status "FAIL" $Message Red
  $script:ExitCode = 1
}

function Require-Command {
  param([string]$Name)
  $command = Get-Command $Name -ErrorAction SilentlyContinue
  if ($null -eq $command) {
    Fail "$Name is not installed"
    return
  }

  $version = & $Name --version 2>$null | Select-Object -First 1
  Ok "${Name}: $version"
}

function Require-File {
  param([string]$RelativePath)
  if (Test-Path -LiteralPath (Join-Path $RootDir $RelativePath) -PathType Leaf) {
    Ok $RelativePath
  }
  else {
    Fail "Missing $RelativePath"
  }
}

function Invoke-Check {
  param([string]$Label, [scriptblock]$Command)
  & $Command
  if ($LASTEXITCODE -eq 0) {
    Ok $Label
  }
  else {
    Fail $Label
  }
}

Write-Host "--- Toolchains ---"
Require-Command rustc
Require-Command cargo
Require-Command node
Require-Command pnpm

Write-Host "`n--- Tauri plugin structure ---"
$requiredFiles = @(
  "Cargo.toml", "Cargo.lock", "build.rs", "package.json", "rollup.config.js",
  "src/lib.rs", "src/commands.rs", "src/desktop.rs", "src/mobile.rs", "src/error.rs", "src/models.rs",
  "guest-js/index.ts", "permissions/default.toml",
  "examples/demo/package.json", "examples/demo/src-tauri/Cargo.toml", "examples/demo/src-tauri/tauri.conf.json"
)
$requiredFiles | ForEach-Object { Require-File $_ }

if ($script:ExitCode -ne 0) {
  Write-Host "`nFix the missing prerequisites before continuing."
  exit $script:ExitCode
}

if (-not $SkipDependencies) {
  Write-Host "`n--- Installing JavaScript dependencies ---"
  Invoke-Check "Plugin dependencies installed" { pnpm --dir $RootDir install --frozen-lockfile }
  Invoke-Check "Demo dependencies installed" { pnpm --dir $DemoDir install --frozen-lockfile }
}
else {
  Warn "Skipping dependency installation"
}

if (-not $SkipChecks) {
  Write-Host "`n--- Building and validating the plugin ---"
  Invoke-Check "JavaScript bindings built" { pnpm --dir $RootDir build }
  Require-File "dist-js/index.js"
  Require-File "dist-js/index.d.ts"
  Invoke-Check "Rust formatting is valid" { cargo fmt --manifest-path (Join-Path $RootDir "Cargo.toml") --check }
  Invoke-Check "Rust plugin compiles" { cargo check --manifest-path (Join-Path $RootDir "Cargo.toml") }
  Invoke-Check "Rust tests pass" { cargo test --manifest-path (Join-Path $RootDir "Cargo.toml") }
  Invoke-Check "Demo frontend builds" { pnpm --dir $DemoDir build }
}
else {
  Warn "Skipping build and test checks"
}

Write-Host "`n--- Summary ---"
if ($script:ExitCode -eq 0) {
  Ok "Tauri audioplayer plugin is ready."
}
else {
  Fail "Initialization completed with errors."
}

exit $script:ExitCode