Skip to content

Commit d08fdfe

Browse files
committed
feat: 增加github action ci 部署页面
1 parent 7320679 commit d08fdfe

File tree

4 files changed

+76
-11
lines changed

4 files changed

+76
-11
lines changed

Diff for: .github/workflows/deploy.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main # 触发分支
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: 16
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Build project
25+
run: npm run build # 假设构建输出到 dist 文件夹
26+
27+
- name: Deploy to GitHub Pages
28+
uses: peaceiris/actions-gh-pages@v3
29+
with:
30+
github_token: ${{ secrets.GITHUB_TOKEN }}
31+
publish_dir: ./dist # 将 dist 文件夹部署到 gh-pages 分支

Diff for: package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
"repository": "[email protected]:JSREI/js-script-hook-goat.git",
66
"author": "CC11001100 <[email protected]>",
77
"license": "MIT",
8+
"scripts": {
9+
"pages": "node pages.js",
10+
"start": "node index.js"
11+
},
812
"dependencies": {
913
"crypto-js": "^4.2.0",
1014
"express": "^4.21.2",
1115
"body-parser": "^1.20.3"
1216
}
13-
}
17+
}

Diff for: pages.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// 定义源文件夹和目标文件夹
5+
const sourceDir = path.join(__dirname, 'public');
6+
const targetDir = path.join(__dirname, 'docs');
7+
8+
// 确保目标文件夹存在
9+
if (!fs.existsSync(targetDir)) {
10+
fs.mkdirSync(targetDir, { recursive: true });
11+
}
12+
13+
// 递归复制文件夹内容
14+
function copyFolderRecursive(source, target) {
15+
// 读取源文件夹内容
16+
const files = fs.readdirSync(source);
17+
18+
for (const file of files) {
19+
const sourcePath = path.join(source, file);
20+
const targetPath = path.join(target, file);
21+
22+
// 判断是文件还是文件夹
23+
const stat = fs.statSync(sourcePath);
24+
if (stat.isDirectory()) {
25+
// 如果是文件夹,递归复制
26+
if (!fs.existsSync(targetPath)) {
27+
fs.mkdirSync(targetPath, { recursive: true });
28+
}
29+
copyFolderRecursive(sourcePath, targetPath);
30+
} else {
31+
// 如果是文件,直接复制
32+
fs.copyFileSync(sourcePath, targetPath);
33+
console.log(`Copied: ${sourcePath} -> ${targetPath}`);
34+
}
35+
}
36+
}
37+
38+
// 执行复制
39+
copyFolderRecursive(sourceDir, targetDir);
40+
console.log('All files copied from public to docs!');

Diff for: site/index.html

-10
This file was deleted.

0 commit comments

Comments
 (0)