# Copyright 2020-2024 Robert Günzler
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit font multiprocessing savedconfig

DESCRIPTION="Slender typeface for code, from code"
HOMEPAGE="https://typeof.net/Iosevka/"

SRC_URI="https://github.com/be5invis/Iosevka/archive/v${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/Iosevka-${PV}"
KEYWORDS=

LICENSE="OFL-1.1"
SLOT="0"
IUSE=""

BDEPEND="
	>=net-libs/nodejs-18[npm]
	media-gfx/ttfautohint
"

FONT_NAME=Iosevka
FONT_S="${S}/dist/${FONT_NAME}/TTF"
FONT_SUFFIX="ttf"

RESTRICT="network-sandbox"

src_prepare() {
	default

	restore_config private-build-plans.toml
}

src_compile() {
	local -a npm_flags=(
		--audit false
		--color false
		--foreground-scripts
		# --offline
		--progress false
		--save false
		--verbose
	)

	# install deps
	npm "${npm_flags[@]}" ci || die

	# determine font name
	if [ -e private-build-plans.toml ]; then
		FONT_NAME=$(grep -m1 -Po '(?<=\[buildPlans\.)[^\]]+' private-build-plans.toml)
	fi

	# select targets
	local -a build_targets=("ttf::${FONT_NAME}")

	# run build
	npm "${npm_flags[@]}" run build -- --jCmd="$(get_makeopts_jobs)"  "${build_targets[@]}" || die
}

src_install() {
	font_src_install

	save_config private-build-plans.toml
}