# Maintainer: Gavin Luo <lunt.luo@gmail.com>

pkgname=gnome-shell-extension-chinese-calendar
_shortname=${pkgname#gnome-shell-extension-}
pkgver=1.4
pkgrel=1
pkgdesc='展示中国农历和节假日信息的gnome-shell扩展'
arch=('any')
url="https://github.com/tigertall/chinese-calendar"
license=('MIT')
depends=('gnome-shell>=45' 'dconf')
makedepends=('npm' 'gettext' 'zip')
source=("${pkgver}.tar.gz"::"${url}/archive/refs/tags/v${pkgver}.tar.gz")
b2sums=('e8433d66d91217f27c9f5c446e15b1b4e8b078240813143904b44b1c99da89e30b6171f6909ac48b5d910f86e7722036f5100ee971176f6285ed6029842d4c0e')

build() {
    cd "${_shortname}-${pkgver}"
    npm install --cache "${srcdir}/npm-cache"
    npm run build

    rm -rf "${srcdir}/dist" && unzip -d "${srcdir}/dist" chinese-calendar.zip
}

package() {
    cd "${srcdir}/dist"

    uuid=$(grep -oP '"uuid":\s*"\K[^"\s]+' "metadata.json")

    find "schemas" -type f -exec install -Dvm644 {} "${pkgdir}/usr/share/glib-2.0/{}" \;
    find "locale" -type f -exec install -Dvm644 {} "${pkgdir}/usr/share/{}" \;

    install -Dvm644 *.{js,json,css} -t "${pkgdir}/usr/share/gnome-shell/extensions/${uuid}/"

    install -Dvm644 "LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
