# -*- 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           cargo   1.0
PortGroup           github  1.0

github.setup        jdx fnox 1.48.0 v
revision            0

homepage            https://fnox.jdx.dev/

description         encrypted\/remote secret manager

long_description    \
    Manage secrets with encryption or cloud providers—or both\! fnox gives \
    you a unified interface to work with secrets across development, CI, and \
    production.

categories          security
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

fetch.type          git

post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

cargo.offline_cmd

# 1.48.0 generates its Touch ID approval UI header at build time with a
# TypeScript (.mts) script run by Node. Node 22.6+ runs it with type
# stripping, which is on by default from Node 23.6.
depends_build-append \
                    path:bin/node:nodejs22
build.env-append    NODE=${prefix}/bin/node \
                    NODE_OPTIONS=--experimental-strip-types

# path:bin/node may be met by an older Node; type stripping needs 22.6+.
pre-configure {
    set node_version [string trimleft [exec ${prefix}/bin/node --version] v]
    if {[vercmp ${node_version} 22.6] < 0} {
        ui_error "${name} needs Node 22.6 or later to build; ${prefix}/bin/node is ${node_version}."
        ui_error "Install nodejs22 or later, then try again."
        return -code error "Node too old"
    }
}

destroot {
    xinstall -m 0755 \
        ${worksrcpath}/target/[cargo.rust_platform]/release/${name} \
        ${destroot}${prefix}/bin/
}
