# Maintainer: David Heinemeier Hansson <david@hey.com>

# Upstream ships a release archive plus a SHA256SUMS manifest, which is what
# the upstream feed in .omarchy/package.json follows. Chromium and ffmpeg are
# runtime dependencies found on PATH, never downloaded.

pkgname=omarchy-billboard-generator
pkgver=0.2.0
pkgrel=1
pkgdesc='Desktop app and CLI that renders animated OMARCHY domain videos'
arch=('any')
url='https://github.com/llstrk/omarchy-billboard-generator'
# MIT covers the project's own code and Apache-2.0 and 0BSD the vendored npm
# dependencies. The Omarchy wordmark, website palettes, taglines and the ttfx
# animation runtime are Omarchy's own material carried over from omarchy-site,
# and PROVENANCE.md says which file is which.
license=('MIT' 'Apache-2.0' '0BSD' 'OFL-1.1' 'LicenseRef-Omarchy')
depends=('nodejs>=22' 'chromium' 'ffmpeg' 'xdg-utils')
makedepends=('npm')
source=("${pkgname}-${pkgver}.tar.gz::${url}/releases/download/v${pkgver}/${pkgname}.tar.gz")
sha256sums=('f499dfc1201ed3d6b8fba271496fcd4c8fc6301427f4f2fc53aab8d9c3f64f67')
# Pure JavaScript and WebAssembly; nothing here is an ELF to strip.
options=('!strip' '!debug')

_appdir="/usr/lib/${pkgname}"

build() {
  cd "${srcdir}/${pkgname}"
  # The same install the upstream release installer performs: locked production
  # dependencies, no lifecycle scripts.
  npm ci --omit=dev --ignore-scripts --cache "${srcdir}/npm-cache"
}

check() {
  cd "${srcdir}/${pkgname}"
  # The catalogs prefer a synced snapshot in the user data directory, so point
  # them at an empty one: the build must read the bundled data, not whatever
  # the builder's home happens to hold.
  export BILLBOARD_DATA_DIR="${srcdir}/data-home" BILLBOARD_CACHE_DIR="${srcdir}/cache-home"
  # Upstream's own startup check, plus the catalogs that load the bundled data.
  node bin/omarchy-billboard --help >/dev/null
  node bin/omarchy-billboard --list-themes >/dev/null
  node bin/omarchy-billboard --list-languages >/dev/null
  node bin/omarchy-billboard --list-animations >/dev/null
  node bin/omarchy-billboard-app --help >/dev/null
}

package() {
  cd "${srcdir}/${pkgname}"

  install -dm755 "${pkgdir}${_appdir}"
  # Only what runs: no tests, release scripts, CI, or the curl|bash installer.
  cp -a bin src app web assets data examples node_modules package.json "${pkgdir}${_appdir}/"

  # The entry points resolve their sources through the real path of the
  # script, so a symlink is enough and keeps the launcher's node on PATH.
  install -dm755 "${pkgdir}/usr/bin"
  ln -s "${_appdir}/bin/omarchy-billboard" "${pkgdir}/usr/bin/omarchy-billboard"
  ln -s "${_appdir}/bin/omarchy-billboard-app" "${pkgdir}/usr/bin/omarchy-billboard-app"

  # Written here rather than shipped as a second source: sync-upstream rewrites
  # sha256sums wholesale from the release manifest, so a local file's checksum
  # would not survive the first version bump. The WM class is what Chromium
  # derives for this app-mode window, so the launcher's icon follows it.
  install -dm755 "${pkgdir}/usr/share/applications"
  cat > "${pkgdir}/usr/share/applications/${pkgname}.desktop" <<'DESKTOP'
[Desktop Entry]
Version=1.0
Type=Application
Name=Omarchy Billboard Generator
Comment=Create animated Omarchy domain videos locally
Exec=omarchy-billboard-app
Icon=omarchy-billboard-generator
Terminal=false
Categories=AudioVideo;Video;
StartupWMClass=chrome-127.0.0.1__omarchy-billboard-Default
DESKTOP
  install -Dm644 app/icon.svg "${pkgdir}/usr/share/icons/hicolor/scalable/apps/${pkgname}.svg"

  install -Dm644 -t "${pkgdir}/usr/share/doc/${pkgname}" README.md THEMES.md PROVENANCE.md
  install -Dm644 -t "${pkgdir}/usr/share/licenses/${pkgname}" LICENSE PROVENANCE.md assets/fonts/*-OFL.txt
}
