-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
36 lines (35 loc) · 1.05 KB
/
preload.js
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
((()=>{
let fs = require('fs')
let path = require('path')
let src = getPath('./');
for (let pagePath of src) {
let isPage = (pagePath.substring(pagePath.lastIndexOf('.') + 1).toLowerCase() == 'pug')
if (isPage) {
let htmlPath = pagePath.substring(0, pagePath.lastIndexOf('.')) + '.html'
let hasHtml = fs.existsSync(htmlPath)
if (!hasHtml) {
console.log(htmlPath)
fs.writeFile(htmlPath,
`<!DOCTYPE html><html lang="en"><pug src="./${pagePath}"></pug></html>`,
err=>{
if (err) console.error(err)
}
)
}
}
}
function getPath(currentDirPath, history = []) {
fs.readdirSync(currentDirPath).forEach(function (name) {
let filePath = path.join(currentDirPath, name);
let stat = fs.statSync(filePath);
if (stat.isFile()) {
// console.log(filePath, stat);
history.push(filePath.replace(/\\/g, '/'));
} else if (stat.isDirectory()) {
getPath(filePath, history);
}
});
return history;
}
return
})())