Skip to content

Commit

Permalink
feat: 增加github action ci 部署页面
Browse files Browse the repository at this point in the history
  • Loading branch information
CC11001100 committed Jan 13, 2025
1 parent 7320679 commit d08fdfe
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main # 触发分支

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install dependencies
run: npm install

- name: Build project
run: npm run build # 假设构建输出到 dist 文件夹

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist # 将 dist 文件夹部署到 gh-pages 分支
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
"repository": "[email protected]:JSREI/js-script-hook-goat.git",
"author": "CC11001100 <[email protected]>",
"license": "MIT",
"scripts": {
"pages": "node pages.js",
"start": "node index.js"
},
"dependencies": {
"crypto-js": "^4.2.0",
"express": "^4.21.2",
"body-parser": "^1.20.3"
}
}
}
40 changes: 40 additions & 0 deletions pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require('fs');
const path = require('path');

// 定义源文件夹和目标文件夹
const sourceDir = path.join(__dirname, 'public');
const targetDir = path.join(__dirname, 'docs');

// 确保目标文件夹存在
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}

// 递归复制文件夹内容
function copyFolderRecursive(source, target) {
// 读取源文件夹内容
const files = fs.readdirSync(source);

for (const file of files) {
const sourcePath = path.join(source, file);
const targetPath = path.join(target, file);

// 判断是文件还是文件夹
const stat = fs.statSync(sourcePath);
if (stat.isDirectory()) {
// 如果是文件夹,递归复制
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath, { recursive: true });
}
copyFolderRecursive(sourcePath, targetPath);
} else {
// 如果是文件,直接复制
fs.copyFileSync(sourcePath, targetPath);
console.log(`Copied: ${sourcePath} -> ${targetPath}`);
}
}
}

// 执行复制
copyFolderRecursive(sourceDir, targetDir);
console.log('All files copied from public to docs!');
10 changes: 0 additions & 10 deletions site/index.html

This file was deleted.

0 comments on commit d08fdfe

Please sign in to comment.