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

104 lines
3.3 KiB
Bash
Executable File
Raw Permalink 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 plugin one-click deploy script
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
SOURCE_DIR="/Users/gavin/vim-im-switch"
TARGET_DIR="/Users/gavin/myweb/.obsidian/plugins/vim-im-switch"
echo -e "${BLUE}🚀 Start deploy...${NC}"
if [ ! -d "$SOURCE_DIR" ]; then
echo -e "${RED}❌ Source dir not found: $SOURCE_DIR${NC}"
exit 1
fi
cd "$SOURCE_DIR"
echo -e "${YELLOW}📁 Current: $(pwd)${NC}"
echo -e "${YELLOW}🔨 Build project...${NC}"
if npm run build; then
echo -e "${GREEN}✅ Build success${NC}"
else
echo -e "${RED}❌ Build failed${NC}"
exit 1
fi
if [ ! -f "main.js" ] && [ ! -f "vim-im-switch-plugin/main.js" ]; then
echo -e "${RED}❌ main.js not found in project or vim-im-switch-plugin/ (build output)${NC}"
exit 1
fi
echo -e "${YELLOW}📂 Creating target dir...${NC}"
mkdir -p "$TARGET_DIR"
echo -e "${YELLOW}📋 Copying plugin files...${NC}"
# If build outputs are in vim-im-switch-plugin, prefer that directory
SRC_PLUGIN_DIR="$SOURCE_DIR"
if [ -d "$SOURCE_DIR/vim-im-switch-plugin" ]; then
SRC_PLUGIN_DIR="$SOURCE_DIR/vim-im-switch-plugin"
else
# If build outputs are at project root, copy them into vim-im-switch-plugin for release
mkdir -p "$SOURCE_DIR/vim-im-switch-plugin"
for f in main.js manifest.json styles.css; do
if [ -f "$SOURCE_DIR/$f" ]; then
cp -f "$SOURCE_DIR/$f" "$SOURCE_DIR/vim-im-switch-plugin/"
echo -e "${GREEN}✔ Move $f -> $SOURCE_DIR/vim-im-switch-plugin/${NC}"
fi
done
SRC_PLUGIN_DIR="$SOURCE_DIR/vim-im-switch-plugin"
fi
echo -e "${YELLOW}🔍 Using source dir: $SRC_PLUGIN_DIR${NC}"
for f in main.js manifest.json styles.css; do
if [ -f "$SRC_PLUGIN_DIR/$f" ]; then
cp -f "$SRC_PLUGIN_DIR/$f" "$TARGET_DIR/"
echo -e "${GREEN}✔ Copied $f -> $TARGET_DIR/${NC}"
else
echo -e "${YELLOW}⚠️ Not found: $SRC_PLUGIN_DIR/$f (skipped)${NC}"
fi
done
echo -e "${GREEN}✅ Obsidian plugin files copied (if available)${NC}"
# Ensure repo-level release directory (vim-im-switch-plugin) contains the built files
RELEASE_DIR="$SOURCE_DIR/vim-im-switch-plugin"
mkdir -p "$RELEASE_DIR"
echo -e "${YELLOW}📦 Updating release dir: $RELEASE_DIR${NC}"
for f in main.js manifest.json styles.css; do
if [ -f "$SOURCE_DIR/$f" ]; then
cp -f "$SOURCE_DIR/$f" "$RELEASE_DIR/"
echo -e "${GREEN}✔ Copied $SOURCE_DIR/$f -> $RELEASE_DIR/${NC}"
else
if [ -f "$RELEASE_DIR/$f" ]; then
echo -e "${YELLOW} Using existing $RELEASE_DIR/$f${NC}"
else
echo -e "${RED}⚠️ Missing build output: $f (not found in project root or $RELEASE_DIR)${NC}"
fi
fi
done
echo -e "${YELLOW}📋 Copying plugin files to Obsidian plugin dir: $TARGET_DIR${NC}"
for f in main.js manifest.json styles.css; do
if [ -f "$RELEASE_DIR/$f" ]; then
cp -f "$RELEASE_DIR/$f" "$TARGET_DIR/"
echo -e "${GREEN}✔ Copied $RELEASE_DIR/$f -> $TARGET_DIR/${NC}"
else
echo -e "${YELLOW}⚠️ Not found in release dir: $RELEASE_DIR/$f (skipped)${NC}"
fi
done
echo -e "${GREEN}🎉 Deploy complete!${NC}"
echo -e " • Obsidian plugin -> $TARGET_DIR"
echo -e " • Release copy -> $RELEASE_DIR"
echo -e "${YELLOW}💡 Restart Obsidian or reload plugin to take effect.${NC}"