-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,46 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: lts/* | ||
- uses: pnpm/action-setup@v2 | ||
|
||
- name: Install pnpm package manager | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: latest | ||
- run: pnpm install | ||
- run: pnpm build | ||
- uses: cloudflare/[email protected] | ||
|
||
- name: Cache pnpm package store directory | ||
id: cache-pnpm-store | ||
uses: actions/cache@v3 | ||
env: | ||
cache-name: cache-pnpm-store-directory | ||
with: | ||
# the pnpm package store directory path is ` ~/.local/share/pnpm/store` on GNU/Linux | ||
path: ~/.local/share/pnpm/store | ||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-build-${{ env.cache-name }}- | ||
${{ runner.os }}-build- | ||
${{ runner.os }}- | ||
- if: ${{ steps.cache-pnpm-store.outputs.cache-hit != 'true' }} | ||
name: List the state of node modules | ||
continue-on-error: true | ||
run: pnpm list | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Build | ||
run: pnpm build | ||
|
||
- name: Deploy to Cloudflare Pages | ||
uses: cloudflare/[email protected] | ||
with: | ||
apiToken: ${{ secrets.CF_API_TOKEN }} | ||
accountId: ${{ secrets.CF_ACCOUNT_ID }} | ||
workingDirectory: 'out' | ||
command: pages deploy --project-name=yunagi . | ||
workingDirectory: "dist" | ||
command: pages deploy --project-name=yunagi . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
/dist/ | ||
|
||
# production | ||
/build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fs = require("fs/promises"); | ||
const path = require("path"); | ||
|
||
async function copyFiles() { | ||
const publicDir = "public"; | ||
const distDir = "dist"; | ||
const filesToCopy = ["sitemap.xml", "robots.txt"]; | ||
|
||
console.log("Starting to copy files..."); | ||
console.log("Checking if dist directory exists..."); | ||
|
||
try { | ||
// 使用 fs.promises.access 检查目录是否存在 | ||
await fs.access(distDir); | ||
|
||
// 如果 access 没有抛出错误,说明目录存在,可以继续执行操作 | ||
console.log(`Directory ${distDir} exists.`); | ||
console.log("Copying files..."); | ||
|
||
// 使用 Promise.all 来并行拷贝文件 | ||
await Promise.all( | ||
filesToCopy.map(async (file) => { | ||
const sourcePath = path.join(publicDir, file); | ||
const destinationPath = path.join(distDir, file); | ||
try { | ||
await fs.copyFile(sourcePath, destinationPath); | ||
console.log(`File ${file} copied successfully.`); | ||
} catch (error) { | ||
console.error(`Error copying ${file}: ${error.message}`); | ||
} | ||
}) | ||
); | ||
|
||
console.log("All files copied successfully."); | ||
} catch (error) { | ||
// 如果目录不存在,输出提示信息 | ||
console.log( | ||
`Directory ${distDir} does not exist. Please run "pnpm build" before running this script.` | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
copyFiles(); |