-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (157 loc) · 4.83 KB
/
Copy pathMakefile
File metadata and controls
198 lines (157 loc) · 4.83 KB
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
.PHONY: all build clean install uninstall install-cli uninstall-cli dmg
.SILENT:
# Colors for output
GREEN := \033[0;32m
YELLOW := \033[1;33m
BLUE := \033[0;34m
RED := \033[0;31m
NC := \033[0m
# Build variables
APP_NAME := nvim_url.app
BUILD_DIR := build
APP_BUNDLE := $(BUILD_DIR)/$(APP_NAME)
CONTENTS_DIR := $(APP_BUNDLE)/Contents
RESOURCES_DIR := $(CONTENTS_DIR)/Resources
SCRIPTS_DIR := $(RESOURCES_DIR)/Scripts
# CLI variables
CLI_INSTALL_PATH := $(HOME)/.local/bin/nvim_url
CLI_SOURCE := Contents/Resources/nvim_url.sh
# DMG variables
VERSION := 0.1.0
DMG_NAME := nvim_url-$(VERSION)
VOLUME_NAME := Neovim URL Handler
DMG_TEMP := dmg_temp
DIST_DIR := dist
FINAL_DMG := $(DIST_DIR)/$(DMG_NAME).dmg
all: install-cli
build: clean
echo "$(BLUE)Building $(APP_NAME)...$(NC)"
echo " Creating build directory...$(NC)"
mkdir -p $(APP_BUNDLE)
echo " Copying app contents...$(NC)"
cp -R Contents $(APP_BUNDLE)/
echo " Copying icon...$(NC)"
if [ -f "Contents/Resources/applet.icns" ]; then \
cp Contents/Resources/applet.icns $(RESOURCES_DIR)/applet.icns; \
fi
echo " Compiling AppleScript...$(NC)"
mkdir -p $(SCRIPTS_DIR)
osacompile -o $(SCRIPTS_DIR)/main.scpt main.applescript
echo " Setting permissions...$(NC)"
chmod +x $(RESOURCES_DIR)/nvim_url.sh
chmod +x $(CONTENTS_DIR)/MacOS/applet
if [ -d "$(CONTENTS_DIR)/_CodeSignature" ]; then \
echo " Removing old code signature...$(NC)"; \
rm -rf $(CONTENTS_DIR)/_CodeSignature; \
fi
echo ""
echo " Finished! App bundle created at: $(BLUE)$(APP_BUNDLE)$(NC)"
echo ""
clean:
if [ -d "$(BUILD_DIR)" ]; then \
echo "$(YELLOW)Cleaning previous build...$(NC)"; \
echo " Removing the build directory: $(YELLOW)$(BUILD_DIR)$(NC)"; \
rm -rf $(BUILD_DIR); \
\
echo ""; \
echo " All cleaned up!"; \
echo ""; \
fi
install: uninstall build
echo "$(GREEN)Installing $(APP_NAME) to /Applications...$(NC)"
cp -R $(APP_BUNDLE) /Applications/
echo ""
echo " Done! Installed to $(GREEN)/Applications/$(APP_NAME)$(NC)"
echo ""
echo " Try it out by running, and it should open this project's README:"
echo " $(BLUE)open 'nvim://file/$(CURDIR)/README.md:10'$(NC)"
echo ""
uninstall:
echo "$(YELLOW)Uninstalling $(APP_NAME) from /Applications...$(NC)"
echo ""
if [ -d "/Applications/$(APP_NAME)" ]; then \
echo " Removing /Applications/$(APP_NAME)..."; \
rm -rf "/Applications/$(APP_NAME)"; \
\
echo ""; \
echo " $(GREEN)Done!$(NC)"; \
else \
echo " $(YELLOW)App not found in /Applications$(NC)"; \
fi
echo ""
install-cli: uninstall-cli install
echo "$(GREEN)Installing nvim_url CLI...$(NC)"
echo ""
if [ ! -f "$(CLI_SOURCE)" ]; then \
echo "$(RED)Error: $(CLI_SOURCE) not found$(NC)"; \
echo "$(YELLOW)Make sure the source file exists$(NC)"; \
exit 1; \
fi
echo " Creating directory $(BLUE)$(dir $(CLI_INSTALL_PATH))$(NC)"
mkdir -p "$(dir $(CLI_INSTALL_PATH))"
echo " Creating symlink at $(BLUE)$(CLI_INSTALL_PATH)$(NC)"
ln -sf "$(CURDIR)/$(CLI_SOURCE)" "$(CLI_INSTALL_PATH)"
chmod +x "$(CLI_INSTALL_PATH)"
echo ""
echo " $(GREEN)Done!$(NC) You can now use: $(BLUE)nvim_url <file>$(NC)"
echo ""
echo " Make sure $(BLUE)$(dir $(CLI_INSTALL_PATH))$(NC) is in your PATH:"
echo " $(YELLOW)export PATH=\"\$$HOME/.local/bin:\$$PATH\"$(NC)"
echo ""
echo " Examples:"
echo " $(BLUE)nvim_url README.md$(NC)"
echo " $(BLUE)nvim_url README.md:10$(NC)"
echo ""
uninstall-cli:
echo "$(YELLOW)Uninstalling nvim_url CLI...$(NC)"
echo ""
if [ -L "$(CLI_INSTALL_PATH)" ]; then \
echo " Removing symlink at $(BLUE)$(CLI_INSTALL_PATH)$(NC)"; \
rm "$(CLI_INSTALL_PATH)"; \
\
echo ""; \
echo " $(GREEN)Done!$(NC)"; \
else \
echo " $(YELLOW)CLI not found at $(CLI_INSTALL_PATH)$(NC)"; \
fi
echo ""
dmg: build
echo "$(GREEN)Packaging $(APP_NAME) into DMG...$(NC)"
if [ ! -d "$(APP_BUNDLE)" ]; then \
echo "$(RED)Error: Build not found at $(APP_BUNDLE)$(NC)"; \
echo "$(YELLOW)Run 'make build' first$(NC)"; \
exit 1; \
fi
if [ -d "$(DMG_TEMP)" ]; then \
echo "$(YELLOW)Cleaning previous DMG temp files...$(NC)"; \
rm -rf $(DMG_TEMP); \
fi
echo " Creating dist directory..."
mkdir -p $(DIST_DIR)
echo "$(YELLOW)Creating DMG contents...$(NC)"
mkdir -p $(DMG_TEMP)
echo " Copying app to temp directory..."
cp -R $(APP_BUNDLE) $(DMG_TEMP)/
echo " Creating Applications symlink..."
ln -s /Applications $(DMG_TEMP)/Applications
echo "$(YELLOW)Creating DMG image...$(NC)"
if [ -f "$(FINAL_DMG)" ]; then \
rm $(FINAL_DMG); \
fi
hdiutil create -volname "$(VOLUME_NAME)" \
-srcfolder $(DMG_TEMP) \
-ov \
-format UDZO \
$(FINAL_DMG)
echo "$(YELLOW)Cleaning up...$(NC)"
rm -rf $(DMG_TEMP)
echo ""
echo "$(GREEN)DMG created successfully!$(NC)"
echo "Location: $(YELLOW)$(FINAL_DMG)$(NC)"
echo ""
echo "To test the DMG:"
echo " open $(FINAL_DMG)"
echo ""
echo "File size:"
ls -lh $(FINAL_DMG) | awk '{print " " $$5}'
echo ""