# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Bruno Galeotti <bgaleotti at gmail dot com>

_name=TypeScript
pkgname=typescript
pkgver=5.4.5
pkgrel=1
pkgdesc='JavaScript with syntax for types'
arch=(any)
url=http://www.typescriptlang.org
license=('Apache-2.0')
depends=('nodejs')
makedepends=('git' 'npm' 'rsync')
source=("git+https://github.com/microsoft/$_name.git#tag=v$pkgver")
b2sums=('03ac05a6b973e1e3cb6f79e9f17a88f335a433dc0c35dde54dc8e499feccab3b8352da7c4e9ef65c3c1d5df2a2284e0f2b657ad4bffff438af2d3cc715fb0e98')

prepare() {
  cd $_name
  npm ci 
}

build() {
  cd $_name
  npx hereby LKG
}

check() {
  cd $_name
  npm run test
}

package() {
  local mod_dir=/usr/lib/node_modules/$pkgname
  install -d "$pkgdir"/{usr/bin,$mod_dir}
  ln -s $mod_dir/bin/{tsc,tsserver} "$pkgdir"/usr/bin

  cd $_name
  rsync -r --exclude=.gitattributes bin lib package.json "$pkgdir"/$mod_dir
  install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname README.md SECURITY.md
  install -Dm644 -t "$pkgdir"/usr/share/licenses/$pkgname \
    ThirdPartyNoticeText.txt
}
