#!/usr/bin/env sh set -eu SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) PLUGIN_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd) CONTRACT="$SCRIPT_DIR/production-contract.mjs" DIST_DIR=${ONLYOFFICE_PLUGIN_DIST_DIR:-"$PLUGIN_DIR/dist"} case "$DIST_DIR" in /*) ;; *) DIST_DIR=$(CDPATH= cd -- "$DIST_DIR" && pwd) ;; esac PACKAGE="$DIST_DIR/eln-template-filler.plugin" TEMP_PACKAGE="$DIST_DIR/.eln-template-filler.$$.plugin" cleanup() { rm -f "$TEMP_PACKAGE" } trap cleanup EXIT trap 'exit 1' HUP INT TERM command -v jq >/dev/null 2>&1 || { printf '%s\n' 'jq is required to package the plugin' >&2 exit 1 } command -v zip >/dev/null 2>&1 || { printf '%s\n' 'zip is required to package the plugin' >&2 exit 1 } command -v unzip >/dev/null 2>&1 || { printf '%s\n' 'unzip is required to verify the plugin' >&2 exit 1 } command -v node >/dev/null 2>&1 || { printf '%s\n' 'Node.js is required to validate the production package' >&2 exit 1 } for required_file in \ "$DIST_DIR/config.json" \ "$DIST_DIR/index.html" \ "$DIST_DIR/resources/icon.png" \ "$DIST_DIR/resources/icon@2x.png" \ "$DIST_DIR/translations/langs.json"; do if [ ! -f "$required_file" ]; then printf '%s\n' "Missing production build file: $required_file" >&2 exit 1 fi done jq -e \ '.version == "0.1.0" and .guid == "asc.{7F4E8F35-5D66-47F8-A5B4-6AB3FAACF565}" and .variations[0].url == "index.html?v=0.1.0"' \ "$DIST_DIR/config.json" >/dev/null node "$CONTRACT" validate-dist "$DIST_DIR" cd "$DIST_DIR" set -- \ config.json \ index.html \ assets/ \ resources/ \ resources/icon.png \ resources/icon@2x.png \ translations/ \ translations/langs.json for asset in assets/*; do set -- "$@" "$asset" done zip -q "$TEMP_PACKAGE" "$@" unzip -tq "$TEMP_PACKAGE" >/dev/null mv -f "$TEMP_PACKAGE" "$PACKAGE" printf '%s\n' "$PACKAGE"