# Maintainer: George Rawlinson <george@rawlinson.net.nz>

pkgname=homebridge-denon-tv
pkgver=3.12.0
pkgrel=1
pkgdesc="Homebridge plugin for Denon/Marantz AV receivers"
arch=('any')
url="https://github.com/grzegorz914/homebridge-denon-tv"
license=('MIT')
depends=('homebridge')
makedepends=('npm')
options=('!strip')
source=("$pkgname-$pkgver.tar.gz::https://registry.npmjs.org/$pkgname/-/$pkgname-$pkgver.tgz")
noextract=("$pkgname-$pkgver.tar.gz")
sha512sums=('ce775535983085be213cc3a4bc76d6f6fbfb9b9fb815936bebf4b28ae19b1694852ef50e8c1a50332012ba74104e2eb85ff143c397461113a06748cac7f648e3')
b2sums=('b37379611559e740107416f4a090a4a08b399918e1b75b3cd7a1890d7f46b3808f35c4b124db81d34513edb1042b951dedef1059340e66e335f3008807c64911')

package() {
  local NPM_FLAGS=(--no-audit --no-fund --no-update-notifier)

  npm install \
    --global \
    --prefix "$pkgdir/usr" \
    "${NPM_FLAGS[@]}" \
    "$pkgname-$pkgver.tar.gz"

  # Non-deterministic race in npm gives 777 permissions to random directories
  # See https://github.com/npm/cli/issues/1103 for details
  find "$pkgdir/usr" -type d -exec chmod 755 {} +

  # npm gives ownership of ALL FILES to build user
  # https://bugs.archlinux.org/task/63396
  chown -R root:root "$pkgdir"

  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" \
    "$pkgdir/usr/lib/node_modules/$pkgname/LICENSE"
}