Skip to content

Commit 4a9214f

Browse files
author
CodeJudge
committed
docs: 贡献指南 + 行为准则 + 备份脚本
1 parent 5a5a3d5 commit 4a9214f

5 files changed

Lines changed: 73 additions & 1 deletion

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PORT=3001
2+
JWT_SECRET=your_secret_key_here
3+
NODE_ENV=development

CODE_OF_CONDUCT.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 行为准则
2+
3+
## 我们的承诺
4+
为了营造开放和友好的环境,我们承诺尊重所有贡献者。
5+
6+
## 我们的标准
7+
- 使用友好和包容的语言
8+
- 尊重不同的观点和经验
9+
- 优雅地接受建设性批评
10+
- 关注对社区最有利的事情
11+
12+
## 违规行为
13+
请向项目维护者报告不可接受的行为。

CONTRIBUTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 贡献指南
2+
3+
感谢你对 CodeJudge 的关注!以下是一些贡献指南。
4+
5+
## 如何贡献
6+
7+
### 报告 Bug
8+
- 在 GitHub Issues 中提交
9+
- 请详细描述问题、复现步骤和环境
10+
11+
### 提交 Pull Request
12+
1. Fork 本仓库
13+
2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
14+
3. 提交修改 (`git commit -m 'feat: add amazing feature'`)
15+
4. 推送到分支 (`git push origin feature/amazing-feature`)
16+
5. 创建 Pull Request
17+
18+
### 开发规范
19+
- 前端使用 TypeScript,严格模式
20+
- 后端使用 CommonJS 模块
21+
- 提交信息遵循 conventional commits
22+
- 新增 API 需添加测试
23+
24+
### 本地开发
25+
```bash
26+
# 安装依赖
27+
cd backend && npm install
28+
cd ../frontend && npm install
29+
30+
# 启动开发环境
31+
cd backend && npm run dev # 后端 :3001
32+
cd frontend && npm run dev # 前端 :5173
33+
34+
# 运行测试
35+
cd backend && npm test
36+
```

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"start": "node src/app.js",
88
"dev": "nodemon src/app.js",
99
"test": "node --test tests/*.test.js",
10-
"test:watch": "node --watch --test tests/*.test.js"
10+
"test:watch": "node --watch --test tests/*.test.js",
11+
"backup": "node src/utils/dbBackup.js"
1112
},
1213
"dependencies": {
1314
"bcryptjs": "^2.4.3",

backend/src/utils/dbBackup.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { getDb } = require('../config/db');
4+
5+
async function backup() {
6+
const db = await getDb();
7+
const data = db.export();
8+
const backupDir = path.join(__dirname, '../../backups');
9+
if (!fs.existsSync(backupDir)) fs.mkdirSync(backupDir, { recursive: true });
10+
const filename = `oj-backup-${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.db`;
11+
fs.writeFileSync(path.join(backupDir, filename), Buffer.from(data));
12+
console.log(`Backup saved: ${filename}`);
13+
process.exit(0);
14+
}
15+
16+
backup().catch(err => {
17+
console.error('Backup failed:', err);
18+
process.exit(1);
19+
});

0 commit comments

Comments
 (0)