Files
moonsource-template/tools/sync.sh
T

23 lines
1.3 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
# 把模板仓库里的公共文件同步进一个插件仓库。
# 用法:tools/sync.sh <插件仓库目录>
# 同步:tools/package.sh、tools/run-tests.sh、.github/workflows/release.yml;
# 缺失时补:<包名>/version.lua、CHANGELOG.md、LICENSE、.gitignore、README.md。
set -eu
T="$(cd "$(dirname "$0")/.." && pwd)"
DEST="$(cd "${1:?用法:tools/sync.sh <插件仓库目录>}" && pwd)"
DIR="$(cd "$DEST" && ls -d moonsource-*.koplugin | head -n 1)"
NAME="${DIR%.koplugin}"; NAME="${NAME#moonsource-}"
PKG="moonsource_$NAME"
TITLE="$(awk -F'\t' -v n="$NAME" '$1==n {print $2}' "$T/plugins.tsv")"
[ -n "$TITLE" ] || { echo "plugins.tsv 里没有 $NAME" >&2; exit 1; }
mkdir -p "$DEST/tools" "$DEST/.github/workflows"
[ -f "$DEST/$DIR/$PKG/version.lua" ] || cp "$T/common/version.lua" "$DEST/$DIR/$PKG/version.lua"
cp "$T/tools/package.sh" "$T/tools/run-tests.sh" "$DEST/tools/"
cp "$T/.github/workflows/release.yml" "$DEST/.github/workflows/release.yml"
[ -f "$DEST/LICENSE" ] || cp "$T/LICENSE" "$DEST/LICENSE"
[ -f "$DEST/.gitignore" ] || printf '.DS_Store\n*.swp\ndist/\n.idea/\n' > "$DEST/.gitignore"
[ -f "$DEST/CHANGELOG.md" ] || sed "s/@TITLE@/$TITLE/g" "$T/common/CHANGELOG.seed.md" > "$DEST/CHANGELOG.md"
[ -f "$DEST/README.md" ] || sed -e "s/@NAME@/$NAME/g" -e "s/@TITLE@/$TITLE/g" "$T/README.plugin.md" > "$DEST/README.md"