abinfo "Patching Cinny Web ..."
cd "$SRCDIR"/../cinny
ab_apply_patches "$SRCDIR"/autobuild/patches/*.cinny

if ab_match_arch loongson3; then
    abinfo "Patching Cinny to use @rollup/wasm-node on loongson3 ..."
    ab_apply_patches "$SRCDIR"/autobuild/patches/*.cinny.wasm
fi

abinfo "Patching Cinny Desktop ..."
cd "$SRCDIR"/..
ab_apply_patches "$SRCDIR"/autobuild/patches/*.cinny-desktop

abinfo "Copying Cinny Desktop config ..."
cp -v "$SRCDIR"/../config.json "$SRCDIR"/../cinny/

abinfo "Installing Cinny Web dependencies ..."
cd "$SRCDIR"/../cinny
npm ci

if ab_match_arch loongson3; then
    abinfo "Install @rollup/wasm-node on loongson3 ..."
    npm install -D rollup@npm:@rollup/wasm-node
fi

abinfo "Building Cinny Web ..."
if ! ab_match_arch amd64 && \
   ! ab_match_arch arm64; then
    export VITE_TLA_FORCE_WASM=true
fi

npm run build

abinfo "Installing Cinny Desktop dependencies ..."
cd "$SRCDIR"/..
npm ci
