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

pkgname=nodejs-homebridge-webos-tv
_pkgname="${pkgname#nodejs-}"
pkgver=2.2.5
pkgrel=1
pkgdesc="Homebridge plugin for LG webOS TVs"
arch=('any')
url="https://github.com/merdok/homebridge-webos-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=('83f6d8777ab5979799d9d2638d304bb0514a471d5c0a492b8b55f6f74428eba389ee9b82f0b39ce7813af7215a633ae8304d4ce5b91ca45e26ab0c72fe462722')
b2sums=('fd159d415a87606c602ba7c8d89a8e9c2b3a50373b426b74cd02a37cdf41290b8318ac129744490c31ea1a9c7bf7c64eb0dcdfe0c08c6c0ad4b2c1f3597408e1')

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"
}