# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               github 1.0

github.setup            Abdenasser neohtop 1.2.0 v
github.tarball_from     archive
revision                1
categories              sysutils aqua
maintainers             {i0ntempest @i0ntempest} openmaintainer
platforms               macosx
license                 MIT

description             htop on steroids
long_description        ${name} is a modern, cross-platform system monitor built on top of\
                        Svelte, Rust and Tauri.

checksums               rmd160  230314ef89d7f6ee2f5873586e4ea7a3c341be6f \
                        sha256  055fae3f307ca1b3603467ffe5011babc10b4659de58fe2c69083db3fd46c36b \
                        size    3603554

universal_variant       no

depends_build-append    path:bin/node:nodejs22 \
                        path:bin/npm:npm11 \
                        port:cargo \
                        port:rust \
                        port:jq \
                        port:moreutils

platform darwin {
    if {${os.major} < 20} {
        # 10.15-
        depends_build-replace \
                        path:bin/node:nodejs22 \
                        path:bin/node:nodejs18
        depends_build-replace \
                        path:bin/npm:npm11 \
                        path:bin/npm:npm9
    }
}

post-patch {
    set tauriconf tauri.conf.json
    system -W ${worksrcpath}/src-tauri \
        "${prefix}/bin/jq -r \'.bundle.targets |= \"app\"\' ${tauriconf} | \
            ${prefix}/bin/sponge ${tauriconf}"
    system -W ${worksrcpath}/src-tauri \
        "${prefix}/bin/jq -r \'.bundle.macOS.signingIdentity |= \"-\"\' ${tauriconf} | \
            ${prefix}/bin/sponge ${tauriconf}"
    system -W ${worksrcpath}/src-tauri \
        "${prefix}/bin/jq -r \'.bundle.macOS.minimumSystemVersion |= \"${macosx_deployment_target}\"\' ${tauriconf} | \
            ${prefix}/bin/sponge ${tauriconf}"
}

configure.cmd           ${prefix}/bin/npm install
configure.pre_args
configure.args-append   --verbose

build.cmd               ${prefix}/bin/npm run tauri build
build.pre_args
build.args-append       --verbose

set appname             NeoHtop
destroot {
    copy ${worksrcpath}/src-tauri/target/release/bundle/macos/${appname}.app ${destroot}${applications_dir}
    ln -s ${applications_dir}/${appname}.app/Contents/MacOS/${appname} ${destroot}/${prefix}/bin/${name}
}
