# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>

pkgname=caprine
pkgver=2.59.1
pkgrel=0
pkgdesc="Elegant Facebook Messenger desktop app"
arch="x86_64 aarch64" # bloced by electron
url="https://github.com/sindresorhus/caprine"
license="MIT"
depends="electron"
makedepends="npm findutils coreutils"
options="!check"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/sindresorhus/caprine/archive/refs/tags/v$pkgver.tar.gz
	caprine.desktop
	caprine.js
	"

build() {
	npm install --ignore-scripts
	npx --yes patch-package
	npx tsc
	rm -r node_modules
	npm install --ignore-scripts --production
	npx --yes patch-package
}

package() {
	local appdir=/usr/lib/$pkgname

	install -d "$pkgdir"$appdir
	cp -r ./* "$pkgdir"$appdir

	install -dm755 "$pkgdir/usr/share/pixmaps"
	install -m644 build/icon.png "$pkgdir/usr/share/pixmaps/$pkgname.png"

	install -Dm755 "$srcdir"/$pkgname.js "$pkgdir"/usr/bin/$pkgname
	install -Dm644 "$srcdir"/$pkgname.desktop \
		"$pkgdir"/usr/share/applications/$pkgname.desktop

	install -dm755 "$pkgdir"/usr/share/licenses/$pkgname
	ln -s "$(realpath -m --relative-to=/usr/share/licenses/$pkgname $appdir/license)" \
		"$pkgdir"/usr/share/licenses/$pkgname

	# Clean up
	rm -r "$pkgdir"$appdir/build
	rm -r "$pkgdir"$appdir/source
	rm -r "$pkgdir"$appdir/tsconfig.json
	find "$pkgdir"$appdir \
		-name "package.json" \
			-exec sed -e "s|$srcdir/$pkgname|$appdir|" \
				-i {} \; \
		-or -name ".*" -prune -exec rm -r '{}' \; \
		-or -name "bin" -prune -exec rm -r '{}' \; \
		-or -name "example" -prune -exec rm -r '{}' \; \
		-or -name "examples" -prune -exec rm -r '{}' \; \
		-or -name "man" -prune -exec rm -r '{}' \; \
		-or -name "scripts" -prune -exec rm -r '{}' \; \
		-or -name "test" -prune -exec rm -r '{}' \;
}
sha512sums="
a525bafb6a53dd2dbdfc4b9b3e96d3939d93be950a3287f2a5ef6465d5a6b64ecda79b6d393023d067f939e1a6e85debc35f83bbb1f758011db9d94dd9ff8a72  caprine-2.59.1.tar.gz
a469e3bea24926119e51642b777ef794c5fa65421107903f967c36d81bbb1adb3d52469ce3a3301b2c890f1aa53ab989ded22a7c6e811fb8cf0a582dbd835e19  caprine.desktop
44280c62ce43bdafa8528729371fccb16b8a0e3db7aca28d5c157ae0144dca5fbb023b8883b561955aa28ab62e967f2674d8c6bcaff186e2cdd0e7ba8beab9ac  caprine.js
"
