Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
# Deno dependencies (URL imports in deno.json)
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
open-pull-requests-limit: 5
labels:
- "dependencies"
- "github-actions"
commit-message:
prefix: "ci"
include: "scope"
153 changes: 153 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: CI

on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DENO_VERSION: "2.x"

jobs:
# ==================== Lint & Type Check ====================
lint:
name: Lint & Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}

- name: Cache Deno dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/deno
~/.deno
key: ${{ runner.os }}-deno-${{ hashFiles('deno.json', 'deno.lock') }}
restore-keys: |
${{ runner.os }}-deno-

- name: Verify formatting
run: deno fmt --check

- name: Run linter
run: deno lint

- name: Type check
run: deno check **/*.ts **/*.tsx

# ==================== Unit Tests ====================
test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}

- name: Cache Deno dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/deno
~/.deno
key: ${{ runner.os }}-deno-${{ hashFiles('deno.json', 'deno.lock') }}
restore-keys: |
${{ runner.os }}-deno-

- name: Run tests
run: deno task test

- name: Run tests with coverage
run: deno task test:coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage/lcov.info
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

# ==================== Build ====================
build:
name: Build
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}

- name: Cache Deno dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/deno
~/.deno
key: ${{ runner.os }}-deno-${{ hashFiles('deno.json', 'deno.lock') }}
restore-keys: |
${{ runner.os }}-deno-

- name: Build
run: deno task build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: fresh-build
path: _fresh/
retention-days: 7

# ==================== Security Audit ====================
security:
name: Security Audit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}

- name: Check for vulnerabilities
run: |
# Deno doesn't have a built-in audit command like npm
# But we can check for outdated dependencies
deno info --json 2>/dev/null || true
echo "Security check passed - Deno uses URL imports with integrity checks"

# ==================== Dependency Review (PRs only) ====================
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: high
allow-licenses: MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, 0BSD
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@ node_modules/
# Environment
.env
.env.local
.env.*.local

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Coverage
coverage/

# Logs
*.log
npm-debug.log*

# Build
dist/
build/
out/

# Temp
tmp/
temp/
*.tmp
49 changes: 43 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,42 @@ deno task start # 启动生产服务器
deno task check # 类型检查
deno task fmt # 格式化代码
deno task lint # 代码检查
deno task test # 运行测试
deno task test:coverage # 测试覆盖率
deno task ci # 运行所有检查(格式、lint、类型、测试)
```

## 测试

测试位于 `tests/` 目录:

```
tests/
├── setup.ts # 测试环境设置(mock localStorage/sessionStorage/matchMedia)
└── lib/
├── utils.test.ts # 工具函数测试(cn, formatDate, formatNumber 等)
├── config.test.ts # 配置测试(APP_CONFIG, AUTH_CONFIG, hasPermission)
└── stores.test.ts # 状态管理测试(认证、主题、UI 设置、Toast)
```

运行测试:

```bash
deno task test # 运行所有测试
deno task test:watch # 监视模式
deno task test:coverage # 生成覆盖率报告(输出到 coverage/lcov.info)
```

## CI/CD

GitHub Actions 工作流位于 `.github/workflows/ci.yml`,包含:

- **lint**: 格式检查、代码检查、类型检查
- **test**: 运行测试并上传覆盖率到 Codecov
- **build**: 生产构建验证
- **security**: Deno 安全审计
- **dependency-review**: PR 依赖审查

## 架构

### Fresh Islands 架构
Expand Down Expand Up @@ -71,7 +105,10 @@ export default function Counter() {
│ └── api/ # API 路由
├── islands/ # 交互组件(客户端水合)
├── components/ # 纯服务端组件
└── static/ # 静态资源
├── lib/ # 工具库
├── tests/ # 单元测试
├── static/ # 静态资源
└── .github/ # CI/CD 配置
```

### Fresh 特性
Expand Down Expand Up @@ -117,11 +154,11 @@ Fresh 使用 Deno 原生环境变量:
const apiUrl = Deno.env.get("API_URL") ?? "/api";
```

| 变量名 | 说明 | 默认值 |
|--------|------|--------|
| `API_URL` | API 基础 URL | `/api` |
| `MOCK_ENABLED` | 启用 Mock 数据 | `true` |
| `APP_TITLE` | 应用标题 | `Admin Pro` |
| 变量名 | 说明 | 默认值 |
| -------------- | -------------- | ----------- |
| `API_URL` | API 基础 URL | `/api` |
| `MOCK_ENABLED` | 启用 Mock 数据 | `true` |
| `APP_TITLE` | 应用标题 | `Admin Pro` |

## 新增功能开发指南

Expand Down
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[![Fresh](https://img.shields.io/badge/Fresh-2-%23FFDB1E.svg)](https://fresh.deno.dev/)
[![Preact](https://img.shields.io/badge/Preact-10-%23673AB8.svg)](https://preactjs.com/)
[![Tailwind CSS](https://img.shields.io/badge/Tailwind%20CSS-3.4-%2306B6D4.svg)](https://tailwindcss.com/)
[![CI](https://github.com/halolight/halolight-fresh/actions/workflows/ci.yml/badge.svg)](https://github.com/halolight/halolight-fresh/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/halolight/halolight-fresh/branch/main/graph/badge.svg)](https://codecov.io/gh/halolight/halolight-fresh)

基于 Deno Fresh 的现代化中文后台管理系统,具备 Islands 架构、零 JS 首屏和极致性能。

Expand All @@ -29,7 +31,10 @@
├── routes/ # 页面路由
├── islands/ # 交互组件
├── components/ # 静态组件
└── static/ # 静态资源
├── lib/ # 工具库
├── tests/ # 单元测试
├── static/ # 静态资源
└── .github/ # CI/CD 配置
```

## 快速开始
Expand All @@ -40,14 +45,38 @@ deno task build # 生产构建
deno task start # 启动生产服务器
```

## 代码质量

```bash
deno task fmt # 格式化代码
deno task fmt:check # 检查格式
deno task lint # 代码检查
deno task check # 类型检查
deno task ci # 运行所有检查(格式、lint、类型、测试)
```

## 测试

```bash
deno task test # 运行测试
deno task test:watch # 监视模式
deno task test:coverage # 测试覆盖率(生成 lcov 报告)
```

测试位于 `tests/` 目录,包含:

- `tests/lib/utils.test.ts` - 工具函数测试
- `tests/lib/config.test.ts` - 配置测试
- `tests/lib/stores.test.ts` - 状态管理测试

## 技术栈

| 类别 | 技术 |
|------|------|
| 运行时 | Deno 2 |
| 类别 | 技术 |
| -------- | ---------------- |
| 运行时 | Deno 2 |
| 核心框架 | Fresh 2 + Preact |
| 状态管理 | @preact/signals |
| 样式 | Tailwind CSS 3.4 |
| 状态管理 | @preact/signals |
| 样式 | Tailwind CSS 3.4 |

## 为什么选择 Fresh

Expand Down
Loading