-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy-to-docs.js
More file actions
69 lines (60 loc) · 2.18 KB
/
copy-to-docs.js
File metadata and controls
69 lines (60 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 将html目录下的文件复制到docs目录
* 用于GitHub Pages部署
*/
const fs = require('fs');
const path = require('path');
// 源目录和目标目录
const htmlZhDir = path.join(__dirname, 'html', 'zh');
const htmlEnDir = path.join(__dirname, 'html', 'en');
const docsDir = path.join(__dirname, 'docs');
const docsZhDir = path.join(docsDir, 'zh');
const docsEnDir = path.join(docsDir, 'en');
// 确保docs目录及其子目录存在
if (!fs.existsSync(docsDir)) {
fs.mkdirSync(docsDir, { recursive: true });
}
if (!fs.existsSync(docsZhDir)) {
fs.mkdirSync(docsZhDir, { recursive: true });
}
if (!fs.existsSync(docsEnDir)) {
fs.mkdirSync(docsEnDir, { recursive: true });
}
// 复制index.html到docs目录
const indexSrc = path.join(__dirname, 'index.html');
const indexDest = path.join(docsDir, 'index.html');
fs.copyFileSync(indexSrc, indexDest);
console.log(`已复制: ${indexSrc} -> ${indexDest}`);
// 复制style.css到docs目录
const styleSrc = path.join(__dirname, 'style.css');
const styleDest = path.join(docsDir, 'style.css');
fs.copyFileSync(styleSrc, styleDest);
console.log(`已复制: ${styleSrc} -> ${styleDest}`);
// 复制about.html到docs目录
const aboutSrc = path.join(__dirname, 'about.html');
const aboutDest = path.join(docsDir, 'about.html');
if (fs.existsSync(aboutSrc)) {
fs.copyFileSync(aboutSrc, aboutDest);
console.log(`已复制: ${aboutSrc} -> ${aboutDest}`);
}
// 复制中文HTML文件到docs/zh目录
if (fs.existsSync(htmlZhDir)) {
const zhFiles = fs.readdirSync(htmlZhDir);
zhFiles.forEach(file => {
const srcPath = path.join(htmlZhDir, file);
const destPath = path.join(docsZhDir, file);
fs.copyFileSync(srcPath, destPath);
console.log(`已复制: ${srcPath} -> ${destPath}`);
});
}
// 复制英文HTML文件到docs/en目录
if (fs.existsSync(htmlEnDir)) {
const enFiles = fs.readdirSync(htmlEnDir);
enFiles.forEach(file => {
const srcPath = path.join(htmlEnDir, file);
const destPath = path.join(docsEnDir, file);
fs.copyFileSync(srcPath, destPath);
console.log(`已复制: ${srcPath} -> ${destPath}`);
});
}
console.log('所有文件已复制完成!');