# -*- 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        Zettlr Zettlr 3.4.3 v
github.tarball_from archive
name                zettlr
revision            0

homepage            https://www.zettlr.com

description         A Markdown Editor for the 21st century.

long_description    \
    Zettlr is a Markdown Editor for the 21st century.  Zettlr supercharges \
    your writing experience and makes no compromises.  It supports standard \
    Markdown and does not need any special handling.  Just pull in your \
    existing notes, Zettelkasten, and paper projects and start working \
    on them immediately.  Zettlr uses a WYSIWYM (What You See Is What You \
    Mean) approach and renders certain elements such as links directly for \
    your convenience.  Zettlr is the first Markdown editor directly aimed at \
    writing professionally. Whether you are a college student, a researcher, \
    a journalist or an author -- Zettlr has the right tools for you.

categories          editors aqua
installs_libs       no
license             GPL-3
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer
supported_archs     x86_64 arm64

fetch.type          git

patchfiles-append   patch-disable-signing-forge.config.js.diff

depends_build-append \
                    bin:git:git \
                    port:yarn

build.env-append    CSC_IDENTITY_AUTO_DISCOVERY=false

use_configure       no
use_xcode           yes

build {
    switch ${build_arch} {
        x86_64 {
            set package_target {mac-x64}
        }
       arm64 {
            set package_target {mac-arm}
        }
    }

    # Fetch and build JS dependencies
    system -W ${worksrcpath} "${build.env} yarn install --immutable"

    # Build electron app
    system -W ${worksrcpath} "${build.env} yarn package:${package_target}"
}

destroot {
    switch $build_arch {
        x86_64 {
            set outdir_suffix {x64}
        }
       arm64 {
            set outdir_suffix {arm64}
        }
    }

    copy \
        ${worksrcpath}/out/Zettlr-darwin-${outdir_suffix}/Zettlr.app \
        ${destroot}${applications_dir}
}

github.livecheck.regex {([0-9.]+)}
