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
# raisfast 常用命令
#
# 用法: just <recipe>
# 帮助: just --list
set dotenv-load
db := "sqlite"
db_url := "sqlite:./storage/db/raisfast.db?mode=rwc"
plugin_type := "all"
# ── 默认 ──────────────────────────────────────────────────────────
default:
@just --list
features := "db-" + db + " plugin-" + plugin_type + " search-tantivy"
# ── 编译 ──────────────────────────────────────────────────────────
# 编译检查(默认 SQLite)
check *FLAGS:
DATABASE_URL={{db_url}} cargo check --features "{{features}}" {{FLAGS}}
# 编译发布版本
build *FLAGS:
DATABASE_URL={{db_url}} cargo build --release --features "{{features}}" {{FLAGS}}
# 编译发布版本(含 Admin UI)
build-full *FLAGS:
cd frontend && pnpm install --frozen-lockfile
cd frontend/admin && pnpm build
DATABASE_URL={{db_url}} cargo build --release --features "{{features}}" {{FLAGS}}
# ── 代码质量 ──────────────────────────────────────────────────────
# 格式化
fmt:
cargo fmt
# 格式化检查
fmt-check:
cargo fmt --check
# Lint
lint:
DATABASE_URL={{db_url}} cargo clippy --features "{{features}}" -- -D warnings
# 全部质量检查(fmt + lint)
qa: fmt-check lint
# ── 测试 ──────────────────────────────────────────────────────────
# 运行所有测试
test *FLAGS:
DATABASE_URL={{db_url}} cargo test --features "{{features}}" {{FLAGS}}
# 仅运行单元测试
test-unit:
DATABASE_URL={{db_url}} cargo test --lib --features "{{features}}"
# 仅运行集成测试
test-integration:
DATABASE_URL={{db_url}} cargo test --test api_tests --features "{{features}}"
# ── 数据库 ────────────────────────────────────────────────────────
# 创建 SQLite 数据库并运行迁移
db-init:
mkdir -p data
sqlite3 {{db_url}} < migrations/001_init.sql
sqlite3 {{db_url}} < migrations/002_add_indexes.sql
# 重新创建数据库(危险:删除现有数据)
db-reset:
rm -f data/blog.db
just db-init
# 运行 CLI 迁移
db-migrate:
DATABASE_URL={{db_url}} cargo run -- db migrate
# 备份数据库
db-backup:
DATABASE_URL={{db_url}} cargo run -- db backup ./backups
# 生成 sqlx 离线查询元数据
db-prepare:
DATABASE_URL={{db_url}} cargo sqlx prepare -- --features "{{features}}"
# 验证离线编译(不依赖 DATABASE_URL)
check-offline:
cargo check --features "{{features}}"
# ── 运行 ──────────────────────────────────────────────────────────
# 启动开发服务器
dev:
DATABASE_URL={{db_url}} cargo run --features "{{features}}"
# ── 数据库后端切换 ────────────────────────────────────────────────
# 用 PostgreSQL 编译检查
pg-check:
cargo check --features "db-postgres"
# 用 MySQL 编译检查
mysql-check:
cargo check --features "db-mysql"
# ── 完整 CI 流水线 ────────────────────────────────────────────────
# CI: fmt → lint → test(确保所有检查通过)
ci: fmt-check lint test
# ── 插件 ──────────────────────────────────────────────────────────
# 编译所有示例 WASM 插件并复制到 plugins/ 目录
plugins-build:
@echo "Building seo-optimizer..."
cd plugins-examples/seo-optimizer && cargo build --target wasm32-unknown-unknown --release
@echo "Building content-filter..."
cd plugins-examples/content-filter && cargo build --target wasm32-unknown-unknown --release
@mkdir -p plugins/seo-optimizer plugins/content-filter
cp plugins-examples/seo-optimizer/target/wasm32-unknown-unknown/release/seo_optimizer.wasm plugins/seo-optimizer/
cp plugins-examples/seo-optimizer/plugin.toml plugins/seo-optimizer/
cp plugins-examples/content-filter/target/wasm32-unknown-unknown/release/content_filter.wasm plugins/content-filter/
cp plugins-examples/content-filter/plugin.toml plugins/content-filter/
@echo "Done. WASM plugins ready in plugins/"
# 复制 JS 插件到 plugins/ 目录
plugins-js-build:
@echo "Copying JS plugins..."
@mkdir -p plugins/welcome-email
@cp plugins-examples-js/welcome-email/plugin.toml plugins/welcome-email/
@cp plugins-examples-js/welcome-email/index.js plugins/welcome-email/
@mkdir -p plugins/seo-optimizer-js
@cp plugins-examples-js/seo-optimizer-js/plugin.toml plugins/seo-optimizer-js/
@cp plugins-examples-js/seo-optimizer-js/index.js plugins/seo-optimizer-js/
@echo "Done. JS plugins ready in plugins/"
# 编译 TypeScript JS 插件(需要 esbuild)
plugins-ts-build:
@echo "Compiling TypeScript plugins..."
@npx esbuild plugins-examples-js/seo-optimizer-js/src/index.ts \
--outfile=plugins-examples-js/seo-optimizer-js/index.js \
--bundle --format=iife --target=es2021
@echo "Done."
# 扫描 plugins-examples-lua/ 下所有含 plugin.toml 的子目录,复制到 plugins/
# 扫描 plugins-examples-lua/ 下含 plugin.toml 的子目录,复制到 plugins/
plugins-lua-build:
#!/usr/bin/env bash
echo "Scanning plugins-examples-lua/..."
count=0
for dir in plugins-examples-lua/*/; do
if [ -f "${dir}plugin.toml" ]; then
name=$(basename "$dir")
echo " $name"
mkdir -p "plugins/$name"
cp -r "$dir"* "plugins/$name/"
count=$((count + 1))
else
echo " Skipping $(basename "$dir"): missing plugin.toml"
fi
done
echo "Done. $count Lua plugin(s) copied to plugins/"
# 编译/复制所有插件(WASM + JS + Lua)
plugins-all: plugins-build plugins-js-build plugins-lua-build