-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-entry-point.js
46 lines (38 loc) · 1.42 KB
/
generate-entry-point.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
37
38
39
40
41
42
43
44
45
46
import fs from 'node:fs';
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY ?? '';
const GITHUB_REPOSITORY_NO_USER = GITHUB_REPOSITORY.split('/').reverse()[0] ?? '';
const isGithubPages = process.env.GITHUB_PAGES === "true";
const isGithubCodespaces = process.env.CODESPACES === "true";
const findEntryHtmlFilesRecursive = () => {
const htmlFilesPath = [];
const items = fs.readdirSync("files", { withFileTypes: true, recursive: true })
for (const item of items) {
if (item && !item.isDirectory() && item.name === 'index.html') {
const getHref = () => {
if (isGithubPages) {
return `/${GITHUB_REPOSITORY_NO_USER}/${item.path}/${item.name}`
}
// if (isGithubCodespaces) {
// return `/${item.path}/${item.name}`
// }
return `/${item.path}/${item.name}`
}
htmlFilesPath.push({
href: getHref(),
folder: item.path.split('/')[1]
})
}
}
return htmlFilesPath;
}
const json = JSON.stringify({
GITHUB_REPOSITORY,
GITHUB_REPOSITORY_NO_USER,
isGithubPages,
isGithubCodespaces,
entryPointsHtml: findEntryHtmlFilesRecursive()
}, undefined, 4)
console.log(json)
fs.writeFile('entry-point.json', json, { flag: 'w+' }, err => {
console.log('generate-entry-point.js Error:', err)
});