Files
note2any/build.sh
2026-04-21 17:55:41 +08:00

75 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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/bash
set -e # 出错立即退出
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# 1. 构建
MODE="$1"
BUILD_CMD=(npm run build)
if [[ "$MODE" == "obf" ]]; then
BUILD_CMD=(npm run build:obf)
echo "🏗️ 开始构建(启用混淆)..."
else
echo "🏗️ 开始构建(不启用混淆)..."
fi
if "${BUILD_CMD[@]}"; then
echo "✅ 构建成功"
echo
else
echo "❌ 构建失败,脚本终止"
echo
exit 1
fi
# 2. 目标目录
PLUGIN_DIR=~/myweb/.obsidian/plugins/note2any
FILES=("main.js" "styles.css" "manifest.json")
# 3. 遍历文件,逐一备份并覆盖
for FILE in "${FILES[@]}"; do
TARGET="$PLUGIN_DIR/$FILE"
BACKUP="$PLUGIN_DIR/backup/$FILE.bk"
if [ -f "$TARGET" ]; then
mkdir -p "$(dirname "$BACKUP")"
cp -f "$TARGET" "$BACKUP"
echo "💾 已备份 $TARGET -> $BACKUP"
fi
if [ -f "$FILE" ]; then
cp -f "$FILE" "$TARGET"
echo "📂 已更新 $TARGET"
else
echo "⚠️ 源文件 $FILE 不存在,跳过"
fi
done
# 4. 覆盖复制 assets 目录(静默)
if [ -d "assets" ]; then
mkdir -p "$PLUGIN_DIR/assets"
rsync -a --delete assets/ "$PLUGIN_DIR/assets/" >/dev/null
echo "🎨 已同步 assets -> $PLUGIN_DIR/assets/"
echo
else
echo "⚠️ 源目录 assets 不存在,跳过"
echo
fi
# 5. server 如有变动则同步远端
SERVER_STATUS="$(git status --porcelain --untracked-files=all -- server 2>/dev/null || true)"
if [[ -n "$SERVER_STATUS" ]]; then
echo "🚀 检测到 server 目录有变动,开始更新远端..."
bash "$SCRIPT_DIR/server/deploy.sh"
echo "✅ server 远端更新完成"
echo
else
echo " server 无变动,跳过远端更新"
echo
fi
echo "✅ 部署完成!"
echo