Files
moonsource-template/tools/package.sh
T
GarfieldandCopilot 98d4744c53 🎉 初始化书源插件公共模板
update.lua(只更新本插件)、打包与测试脚本、发布流程、README 模板与同步脚本。

Co-authored-by: Copilot <[email protected]>
2026-11-18 14:28:56 +08:00

26 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# 打包本仓库的书源插件:moonsource-<名字>.koplugin-<VERSION>.zip,同时生成 SHA256SUMS。
# 用法:tools/package.sh <VERSION> [OUT_DIR] (OUT_DIR 默认 dist/)
# 打包时把 <包名>/version.lua 里的版本占位符换成发布版本;剔除 *.md、.DS_Store、*~。
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
VERSION="${1:?用法:tools/package.sh <VERSION> [OUT_DIR]}"
OUT="${2:-$ROOT/dist}"
case "$OUT" in /*) ;; *) OUT="$PWD/$OUT" ;; esac
NAME="$(cd "$ROOT" && ls -d moonsource-*.koplugin | head -n 1)"
[ -f "$ROOT/$NAME/main.lua" ] || { echo "找不到插件目录:$NAME" >&2; exit 1; }
PKG="$(echo "${NAME%.koplugin}" | tr - _)"
mkdir -p "$OUT"
STAGE="$(mktemp -d)"
trap 'rm -rf "$STAGE"' EXIT
rsync -a --exclude '*.md' --exclude '.DS_Store' --exclude '*~' "$ROOT/$NAME/" "$STAGE/$NAME/"
sed "s/@VERSION@/$VERSION/" "$ROOT/$NAME/$PKG/version.lua" > "$STAGE/$NAME/$PKG/version.lua"
ZIP="$OUT/$NAME-$VERSION.zip"
rm -f "$ZIP"
(cd "$STAGE" && zip -qr "$ZIP" "$NAME")
echo "Packaged $ZIP"
(cd "$OUT" && { command -v sha256sum >/dev/null && sha256sum ./*.zip || shasum -a 256 ./*.zip; } | sed 's# \./# #' > SHA256SUMS)