Files
vim-im-switch/deploy.sh
2025-11-04 20:46:31 +08:00

84 lines
2.5 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/bash
# Obsidian Vim IM Switch Plugin 一键部署脚本
# 编译并复制插件文件到 Obsidian 插件目录
set -e # 遇到错误时退出
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 配置
SOURCE_DIR="/Users/gavin/vim-im-switch"
TARGET_DIR="/Users/gavin/myweb/.obsidian/plugins/vim-im-switch"
echo -e "${BLUE}🚀 开始部署 Obsidian Vim IM Switch Plugin...${NC}"
# 检查源目录
if [ ! -d "$SOURCE_DIR" ]; then
echo -e "${RED}❌ 源目录不存在: $SOURCE_DIR${NC}"
exit 1
fi
# 进入源目录
cd "$SOURCE_DIR"
echo -e "${YELLOW}📁 当前目录: $(pwd)${NC}"
# 编译项目
echo -e "${YELLOW}🔨 开始编译项目...${NC}"
if npm run build; then
echo -e "${GREEN}✅ 编译成功${NC}"
else
echo -e "${RED}❌ 编译失败${NC}"
exit 1
fi
# 检查编译产物(构建产物位于项目根,确保 main.js manifest.json styles.css 可用)
if [ ! -f "main.js" ] || [ ! -f "manifest.json" ] || [ ! -f "styles.css" ]; then
echo -e "${RED}❌ 编译产物缺失: 期待 main.js, manifest.json, styles.css 在项目根目录下${NC}"
ls -la | sed -n '1,200p'
exit 1
fi
# 创建目标目录
echo -e "${YELLOW}📂 创建目标目录...${NC}"
mkdir -p "$TARGET_DIR"
# 复制文件
echo -e "${YELLOW}📋 复制插件文件...${NC}"
# 复制必需的文件到 Obsidian 插件目录
cp -f main.js "$TARGET_DIR/"
cp -f manifest.json "$TARGET_DIR/"
cp -f styles.css "$TARGET_DIR/"
echo -e "${GREEN}✅ Obsidian 插件文件复制完成:${NC}"
echo -e " • main.js"
echo -e " • manifest.json"
echo -e " • styles.css"
# 复制 Vim 插件fcitx-osx.vim
echo -e "${YELLOW}📋 复制 Vim 插件...${NC}"
mkdir -p ~/.vim/plugin
if [ -f "fcitx-osx.vim" ]; then
cp -f fcitx-osx.vim ~/.vim/plugin/
echo -e "${GREEN}✅ Vim 插件复制完成:${NC}"
echo -e " • fcitx-osx.vim → ~/.vim/plugin/"
else
echo -e "${YELLOW}⚠️ 未找到 fcitx-osx.vim跳过 Vim 插件复制(确定文件存在于仓库根)${NC}"
fi
# 验证文件
echo -e "${YELLOW}🔍 验证复制的文件...${NC}"
ls -la "$TARGET_DIR"
echo -e "${GREEN}🎉 部署完成!${NC}"
echo -e "${BLUE}📍 Obsidian 插件已部署到: $TARGET_DIR${NC}"
echo -e "${BLUE}📍 Vim 插件已部署到: ~/.vim/plugin/${NC}"
echo -e "${YELLOW}💡 请重启 Obsidian 或重新加载插件以使更改生效${NC}"
echo -e "${YELLOW}💡 Vim 插件将在下次启动 Vim 时自动加载${NC}"