-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
193 lines (168 loc) · 5.91 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Detect operating system
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
# Windows paths
ANKI_ADDON_DIR := $(APPDATA)/Anki2/addons21
ANKI_PATH := "C:/Program Files/Anki/anki.exe"
RM_CMD := rd /s /q
CP_CMD := xcopy /E /I /Y
MKDIR_CMD := mkdir
RMDIR_CMD := rmdir /s /q
# Windows color codes (if using PowerShell)
BLUE := [34m
YELLOW := [33m
GREEN := [32m
NC := [0m
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
DETECTED_OS := Linux
# Linux paths
ANKI_ADDON_DIR := $(HOME)/.local/share/Anki2/addons21
ANKI_PATH := anki
RM_CMD := rm -rf
CP_CMD := cp -r
MKDIR_CMD := mkdir -p
RMDIR_CMD := rm -rf
endif
ifeq ($(UNAME_S),Darwin)
DETECTED_OS := MacOS
# MacOS paths
ANKI_ADDON_DIR := $(HOME)/Library/Application Support/Anki2/addons21
ANKI_PATH := /Applications/Anki.app/Contents/MacOS/anki
RM_CMD := rm -rf
CP_CMD := cp -r
MKDIR_CMD := mkdir -p
RMDIR_CMD := rm -rf
endif
# Unix-like color codes
BLUE := \033[34m
YELLOW := \033[33m
GREEN := \033[32m
NC := \033[0m
endif
# Common variables
ADDON_NAME := Hanzi2Pinyin
PYTHON_CMD := python
ifeq ($(DETECTED_OS),Windows)
PYTHON_CMD := python.exe
endif
.DEFAULT_GOAL := help
.PHONY: help sync anki sync-and-run clean-deps install-deps update-deps check-os tag retag ankiaddon check-zip check-ankiaddon check-contents
help:
@echo ""
@echo "$(BLUE)=== Hanzi2Pinyin Anki Add-on Development Commands ===$(NC)"
@echo "----------------------------------------------------"
@echo "$(YELLOW)System Information:$(NC)"
@echo " make check-os - Show detected OS and paths"
@echo ""
@echo "$(YELLOW)Development Commands:$(NC)"
@echo " make help - Show this help message"
@echo " make sync - Sync 'addon/' to Anki directory"
@echo " make anki - Start Anki with debug console"
@echo " make sync-and-run - Sync addon and start Anki"
@echo ""
@echo "$(YELLOW)Dependency Management:$(NC)"
@echo " make clean-deps - Remove all dependencies"
@echo " make install-deps - Install dependencies"
@echo " make update-deps - Update to latest versions"
@echo ""
@echo "$(YELLOW)GitHub Releases:$(NC)"
@echo " make tag - Create a new tag (GitHub workflows)"
@echo " make retag - Delete and recreate a tag (GitHub workflows)"
@echo " make ankiaddon"
@echo " make check-zip"
@echo ""
# Check OS configuration
check-os:
@echo "$(BLUE)Detected OS: $(DETECTED_OS)$(NC)"
@echo "$(BLUE)Anki Add-on Directory: $(ANKI_ADDON_DIR)$(NC)"
@echo "$(BLUE)Anki Path: $(ANKI_PATH)$(NC)"
# Dependency management
install-deps:
@echo "$(BLUE)Installing dependencies...$(NC)"
$(PYTHON_CMD) -m pip install -r requirements.txt --target ./addon/lib --upgrade
@echo "$(GREEN)Dependencies installed successfully!$(NC)"
clean-deps:
@echo "$(YELLOW)Cleaning dependency directory...$(NC)"
$(RM_CMD) ./addon/lib/*
@echo "$(GREEN)Dependencies cleaned successfully!$(NC)"
update-deps: clean-deps install-deps
@echo "$(GREEN)Dependencies updated successfully!$(NC)"
# Sync addon to Anki directory
sync:
sync:
@echo "$(BLUE)Syncing addon to Anki...$(NC)"
ifeq ($(DETECTED_OS),Windows)
$(RM_CMD) "$(ANKI_ADDON_DIR)/$(ADDON_NAME)" > nul 2>&1 || true
$(MKDIR_CMD) "$(ANKI_ADDON_DIR)" > nul 2>&1 || true
else
$(RM_CMD) "$(ANKI_ADDON_DIR)/$(ADDON_NAME)" 2>/dev/null || true
$(MKDIR_CMD) "$(ANKI_ADDON_DIR)" 2>/dev/null || true
endif
$(CP_CMD) addon "$(ANKI_ADDON_DIR)/$(ADDON_NAME)"
ifeq ($(DETECTED_OS),Windows)
@for /r "$(ANKI_ADDON_DIR)/$(ADDON_NAME)" %%d in (__pycache__) do @if exist "%%d" rd /s /q "%%d"
else
@find "$(ANKI_ADDON_DIR)/$(ADDON_NAME)" -type d -name "__pycache__" -exec rm -rf {} +
endif
@echo "$(GREEN)✨ Sync complete! ✨$(NC)"
# Launch Anki
anki:
@echo "$(BLUE)Starting Anki...$(NC)"
@echo "Launching from: $(ANKI_PATH)"
@"$(ANKI_PATH)"
# Combined sync and launch
sync-and-run: sync anki
# Command to delete and recreate a tag
# It will prompt: Enter version (e.g., 1.0.0):
# Will delete existing tag and create new one
retag:
@read -p "Enter version (e.g., 1.0.0): " version; \
if [ -n "$$version" ]; then \
echo "Deleting tag v$$version..."; \
git push --delete origin "v$$version" 2>/dev/null || echo "Remote tag doesn't exist"; \
git tag -d "v$$version" 2>/dev/null || echo "Local tag doesn't exist"; \
echo "Creating new tag v$$version..."; \
git tag "v$$version" && \
git push origin "v$$version" && \
echo "Successfully created and pushed tag v$$version" || \
echo "Failed to create/push tag"; \
else \
echo "No version provided"; \
fi
# Command to create a new tag
# It will prompt: Enter version (e.g., 1.0.0):
# If tag already exists, it will tell you to use retag
tag:
@read -p "Enter version (e.g., 1.0.0): " version; \
if [ -n "$$version" ]; then \
if git rev-parse "v$$version" >/dev/null 2>&1; then \
echo "Error: Tag v$$version already exists. Use 'make retag' to recreate it."; \
exit 1; \
else \
echo "Creating new tag v$$version..."; \
git tag "v$$version" && \
git push origin "v$$version" && \
echo "Successfully created and pushed tag v$$version" || \
echo "Failed to create/push tag"; \
fi \
else \
echo "No version provided"; \
fi
ankiaddon:
@echo "$(BLUE)Creating .ankiaddon package...$(NC)"
@find addon -type d -name "__pycache__" -exec rm -rf {} +
cd addon && zip -r ../Hanzi2Pinyin.ankiaddon * -x "**/__pycache__/*"
@echo "$(GREEN)✨ Created Hanzi2Pinyin.ankiaddon ✨$(NC)"
# Command to verify contents
check-contents:
@echo "$(BLUE)Checking .ankiaddon contents...$(NC)"
unzip -l Hanzi2Pinyin.ankiaddon
check-zip:
@echo "$(BLUE)Creating check zip file...$(NC)"
cd addon && zip -r ../addon_check.zip * --exclude "*__pycache__*" "*.pyc"
@echo "$(GREEN)✨ Created addon_check.zip for verification ✨$(NC)"
check-ankiaddon:
@echo "$(BLUE)Checking .ankiaddon contents...$(NC)"
unzip -l Hanzi2Pinyin.ankiaddon