-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
286 lines (262 loc) · 10.7 KB
/
Copy pathMakefile
File metadata and controls
286 lines (262 loc) · 10.7 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
.PHONY: help install dev build clean lint format typecheck check test \
build-mac publish-mac release-mac rclone-check print-version
# Default target
.DEFAULT_GOAL := help
# Shell
SHELL := /bin/bash
# Load .env if present
-include .env
export
# Colors
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
## Project information
PROJECT_NAME := Lightbridge Prompt Studio
## Release configuration
RCLONE_REMOTE ?= lightbridge-promptstudio
R2_BUCKET ?= lightbridge-promptstudio
RELEASE_PREFIX ?= releases
DRY_RUN ?= false
DMG_HEADLESS ?= true
LATEST_CLEAN ?= true
LATEST_FILENAME ?= PromptStudio_aarch64.dmg
## Help
help: ## Show this help
@echo '${YELLOW}=========================${RESET}'
@echo '${YELLOW}${PROJECT_NAME}${RESET}'
@echo '${YELLOW}=========================${RESET}'
@echo ''
@echo '${YELLOW}Development:${RESET}'
@echo ' ${GREEN}make dev${RESET} - Start full development environment (frontend + backend)'
@echo ' ${GREEN}make dev-frontend${RESET} - Start only the frontend development server'
@echo ''
@echo '${YELLOW}Build & Test:${RESET}'
@echo ' ${GREEN}make install${RESET} - Install project dependencies'
@echo ' ${GREEN}make build${RESET} - Build the application for production'
@echo ' ${GREEN}make clean${RESET} - Remove build artifacts and dependencies (destructive)'
@echo ' ${GREEN}make lint${RESET} - Lint source files'
@echo ' ${GREEN}make format${RESET} - Format source files'
@echo ' ${GREEN}make typecheck${RESET} - Run TypeScript type checking'
@echo ' ${GREEN}make check${RESET} - Run lint and type checking'
@echo ' ${GREEN}make test${RESET} - Run Rust tests'
@echo ''
@echo '${YELLOW}Release:${RESET}'
@echo ' ${GREEN}make rclone-check${RESET} - Verify rclone is installed and remote is configured'
@echo ' ${GREEN}make build-mac${RESET} - Build macOS Tauri installer locally'
@echo ' ${GREEN}make publish-mac${RESET} - Upload latest mac artifact(s) to R2'
@echo ' ${GREEN}make release-mac${RESET} - Build + publish (mac only)'
@echo ' ${GREEN}make print-version${RESET} - Print resolved release version (source + value)'
## Install project dependencies
install: ## Install all project dependencies (Node.js and Rust)
@echo "${YELLOW}Installing Node.js dependencies...${RESET}"
pnpm install
@echo "${YELLOW}Installing Rust dependencies...${RESET}"
cargo install tauri-cli
## Check if Tauri CLI is installed
check-tauri:
@if ! command -v cargo-tauri >/dev/null 2>&1; then \
echo "${YELLOW}Tauri CLI not found. Please run 'make install' first.${RESET}"; \
exit 1; \
fi
# Rule to automatically run pnpm install if node_modules is missing
node_modules: package.json
pnpm install
## Development Commands
dev: node_modules check-tauri ## Start full development environment (frontend + backend)
@echo "${YELLOW}Starting full development environment...${RESET}"
@echo "${YELLOW}Frontend: http://localhost:1420${RESET}"
@echo "${YELLOW}Backend: Debug mode enabled with backtraces${RESET}"
RUST_LOG=debug RUST_BACKTRACE=1 cargo tauri dev
dev-frontend: ## Start only the frontend development server
@echo "${YELLOW}Starting frontend development server...${RESET}"
@echo "${YELLOW}Access at: http://localhost:1420${RESET}"
pnpm run dev
## Build the application for production
build: node_modules check-tauri
@echo "${YELLOW}Building application...${RESET}"
cargo tauri build
## Remove build artifacts and dependencies
clean:
@echo "${YELLOW}Cleaning project...${RESET}"
rm -rf node_modules
rm -f pnpm-lock.yaml
rm -rf src-tauri/target
## Lint source files
lint:
@echo "${YELLOW}Linting source files...${RESET}"
pnpm run lint
## Format source files
format:
@echo "${YELLOW}Formatting source files...${RESET}"
pnpm run format
## Run TypeScript type checking
typecheck:
@echo "${YELLOW}Running TypeScript type checking...${RESET}"
pnpm run typecheck
## Run lint and type checking
check:
@echo "${YELLOW}Running all checks...${RESET}"
pnpm run check
## Run Rust tests
test:
@echo "${YELLOW}Running Rust tests...${RESET}"
cd src-tauri && cargo test
## Verify rclone is installed and remote is configured
rclone-check:
@set -euo pipefail; \
if ! command -v rclone >/dev/null 2>&1; then \
echo "${YELLOW}rclone not found. Please install rclone first.${RESET}"; \
exit 1; \
fi; \
if ! rclone listremotes | grep -q '^$(RCLONE_REMOTE):'; then \
echo "${YELLOW}rclone remote '$(RCLONE_REMOTE)' not found.${RESET}"; \
echo "${YELLOW}Run: rclone config to add it.${RESET}"; \
exit 1; \
fi; \
if ! rclone config show | awk 'BEGIN{in_section=0; ok=0} /^\[/{in_section=($$0=="[$(RCLONE_REMOTE)]")} in_section && $$1=="force_path_style" && $$3=="true"{ok=1} END{exit !ok}'; then \
echo "${YELLOW}Warning: rclone remote '$(RCLONE_REMOTE)' should set force_path_style = true.${RESET}"; \
echo "${YELLOW}Run: rclone config update $(RCLONE_REMOTE) force_path_style true${RESET}"; \
fi
## Print resolved release version
print-version:
@set -euo pipefail; \
VERSION_SOURCE="src-tauri/tauri.conf.json"; \
if [ -f src-tauri/tauri.conf.json ]; then \
VERSION=$$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' src-tauri/tauri.conf.json | head -n 1); \
else \
VERSION=""; \
fi; \
if [ -z "$$VERSION" ]; then \
VERSION_SOURCE="package.json"; \
if [ -f package.json ]; then \
VERSION=$$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -n 1); \
else \
VERSION=""; \
fi; \
fi; \
if [ -z "$$VERSION" ]; then \
VERSION_SOURCE="timestamp"; \
VERSION=$$(date +%Y%m%d%H%M%S); \
fi; \
echo "version=$$VERSION (source=$$VERSION_SOURCE)"
## Build macOS Tauri installer locally
build-mac: node_modules check-tauri
@echo "${YELLOW}Building macOS artifacts...${RESET}"
@if [ "$(DMG_HEADLESS)" = "true" ]; then \
CI=true pnpm run tauri:build; \
else \
pnpm run tauri:build; \
fi
@set -euo pipefail; \
ARTIFACT_DIR="src-tauri/target/release/bundle"; \
if [ ! -d "$$ARTIFACT_DIR" ]; then \
echo "${YELLOW}Build output not found at $$ARTIFACT_DIR.${RESET}"; \
exit 1; \
fi; \
DMG_FOUND=$$(find "$$ARTIFACT_DIR" -type f -name '*.dmg' -print -quit); \
if [ -n "$$DMG_FOUND" ]; then \
echo "${YELLOW}Found dmg artifact: $$DMG_FOUND${RESET}"; \
exit 0; \
fi; \
OTHER_FOUND=$$(find "$$ARTIFACT_DIR" -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.app.tar.gz' \) -print -quit); \
if [ -n "$$OTHER_FOUND" ]; then \
echo "${YELLOW}Warning: no dmg found; using $$OTHER_FOUND${RESET}"; \
exit 0; \
fi; \
APP_FOUND=$$(find "$$ARTIFACT_DIR" -type d -name '*.app' -print -quit); \
if [ -n "$$APP_FOUND" ]; then \
echo "${YELLOW}Warning: no dmg found; using $$APP_FOUND${RESET}"; \
exit 0; \
fi; \
echo "${YELLOW}No macOS artifacts found in $$ARTIFACT_DIR.${RESET}"; \
exit 1
## Upload latest mac artifact(s) to R2
publish-mac: rclone-check
@set -euo pipefail; \
ARTIFACT_DIR="src-tauri/target/release/bundle"; \
if [ ! -d "$$ARTIFACT_DIR" ]; then \
echo "${YELLOW}Build output not found at $$ARTIFACT_DIR. Run make build-mac first.${RESET}"; \
exit 1; \
fi; \
VERSION_SOURCE="src-tauri/tauri.conf.json"; \
if [ -f src-tauri/tauri.conf.json ]; then \
VERSION=$$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' src-tauri/tauri.conf.json | head -n 1); \
else \
VERSION=""; \
fi; \
if [ -z "$$VERSION" ]; then \
VERSION_SOURCE="package.json"; \
if [ -f package.json ]; then \
VERSION=$$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -n 1); \
else \
VERSION=""; \
fi; \
fi; \
if [ -z "$$VERSION" ]; then \
VERSION_SOURCE="timestamp"; \
VERSION=$$(date +%Y%m%d%H%M%S); \
echo "${YELLOW}Warning: version not found; using $$VERSION (timestamp).${RESET}"; \
fi; \
if [ "$$VERSION_SOURCE" != "timestamp" ]; then \
echo "${YELLOW}Using version $$VERSION from $$VERSION_SOURCE.${RESET}"; \
fi; \
if [ "$(DRY_RUN)" = "true" ]; then \
DRY_FLAGS="--dry-run"; \
echo "${YELLOW}DRY_RUN=true: no files will be uploaded.${RESET}"; \
else \
DRY_FLAGS=""; \
fi; \
DEST_LATEST="$(RCLONE_REMOTE):$(R2_BUCKET)/$(RELEASE_PREFIX)/latest/mac/"; \
DEST_VERSIONED="$(RCLONE_REMOTE):$(R2_BUCKET)/$(RELEASE_PREFIX)/v$$VERSION/mac/"; \
if [ "$(LATEST_CLEAN)" = "true" ]; then \
echo "${YELLOW}Cleaning latest directory before upload...${RESET}"; \
rclone delete "$$DEST_LATEST" --s3-no-check-bucket $$DRY_FLAGS; \
fi; \
if find "$$ARTIFACT_DIR" -type f -name '*.dmg' -print -quit | grep -q .; then \
FILES_MODE="dmg"; \
else \
FILES_MODE="other"; \
fi; \
if [ "$$FILES_MODE" = "other" ]; then \
if ! find "$$ARTIFACT_DIR" -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.app.tar.gz' \) -print -quit | grep -q .; then \
if ! find "$$ARTIFACT_DIR" -type d -name '*.app' -print -quit | grep -q .; then \
echo "${YELLOW}No macOS artifacts found in $$ARTIFACT_DIR.${RESET}"; \
exit 1; \
fi; \
echo "${YELLOW}Warning: no dmg or archive found; uploading .app bundles.${RESET}"; \
find "$$ARTIFACT_DIR" -type d -name '*.app' -print0 | while IFS= read -r -d '' file; do \
rclone copy "$$file" "$$DEST_LATEST" --s3-no-check-bucket --progress $$DRY_FLAGS; \
rclone copy "$$file" "$$DEST_VERSIONED" --s3-no-check-bucket --progress $$DRY_FLAGS; \
if [ -n "$(LATEST_FILENAME)" ]; then \
echo "${YELLOW}Warning: stable filename is configured but only .dmg files support it.${RESET}"; \
fi; \
echo "$(RELEASE_PREFIX)/latest/mac/$$(basename "$$file")"; \
echo "$(RELEASE_PREFIX)/v$$VERSION/mac/$$(basename "$$file")"; \
done; \
exit 0; \
fi; \
echo "${YELLOW}Warning: no dmg found; uploading archive artifacts.${RESET}"; \
fi; \
find "$$ARTIFACT_DIR" -type f \( -name '*.dmg' -o -name '*.zip' -o -name '*.tar.gz' -o -name '*.app.tar.gz' \) -print0 | while IFS= read -r -d '' file; do \
case "$$file" in \
*.dmg) ;; \
*.zip|*.tar.gz|*.app.tar.gz) [ "$$FILES_MODE" = "other" ] || continue ;; \
*) continue ;; \
esac; \
if [ -z "$(LATEST_FILENAME)" ] || [ "$$FILES_MODE" != "dmg" ]; then \
rclone copy "$$file" "$$DEST_LATEST" --s3-no-check-bucket --progress $$DRY_FLAGS; \
fi; \
rclone copy "$$file" "$$DEST_VERSIONED" --s3-no-check-bucket --progress $$DRY_FLAGS; \
if [ -n "$(LATEST_FILENAME)" ] && [ "$$FILES_MODE" = "dmg" ]; then \
rclone copyto "$$file" "$${DEST_LATEST}$(LATEST_FILENAME)" --s3-no-check-bucket --progress $$DRY_FLAGS; \
echo "$(RELEASE_PREFIX)/latest/mac/$(LATEST_FILENAME)"; \
fi; \
if [ -z "$(LATEST_FILENAME)" ] || [ "$$FILES_MODE" != "dmg" ]; then \
echo "$(RELEASE_PREFIX)/latest/mac/$$(basename "$$file")"; \
fi; \
echo "$(RELEASE_PREFIX)/v$$VERSION/mac/$$(basename "$$file")"; \
done
## Build + publish (mac only)
release-mac: build-mac publish-mac