# Maintainer: Alexander Epaneshnikov <alex19ep@archlinux.com>
# Contributor: libertylocked <libertylocked@disroot.org>

pkgname=bitwarden-cli
pkgver=1.18.1
_jslibcommit='5f64d956520612a681611a27c5f4f2e5f27b640e'
pkgrel=1
pkgdesc="The command line vault"
arch=('x86_64')
url="https://github.com/bitwarden/cli"
license=('GPL3')
depends=('gcc-libs')
makedepends=('git' 'npm' 'node-gyp' 'nodejs-lts-fermium')
options=('!strip')
source=("bitwarden-cli-${pkgver}.tar.gz::https://github.com/bitwarden/cli/archive/v${pkgver}.tar.gz"
        "jslib-${_jslibcommit}.tar.gz::https://github.com/bitwarden/jslib/archive/${_jslibcommit}.tar.gz")
sha512sums=('e9e2092ccd964d1f69ea6ba4a84aaa3c188db1f4c923dec8984a75ed6ebe039c36ae2395db065f636f010c8f8fd52ee898cadd7a9a40733c46f51767d74e1eec'
            '185a4e675cd2d97b1e42d414f6b68fce2710448cf5eb9d08bbbdc8ac73453460e296853fe5ec7a21405ac02905a22463634084ae25b22b01cb59754aaaea5039')

prepare() {
	cd cli-${pkgver}
	rmdir -v jslib
	ln -sv ../jslib-${_jslibcommit} jslib
}

build() {
	cd cli-${pkgver}
	export npm_config_cache="$srcdir/npm_cache"
	pushd jslib
	npm install
	popd
	npm install
	npm run build:prod
	npm run clean
	npm run package:lin
	./dist/linux/bw completion --shell zsh > _bw
}

package() {
	cd cli-${pkgver}
	install -vDm755 dist/linux/bw -t "${pkgdir}/usr/bin"
	# package zsh completions
	install -vDm644 "${srcdir}/cli-${pkgver}/_bw" -t "${pkgdir}/usr/share/zsh/site-functions"
}
