-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
64 lines (58 loc) · 1.9 KB
/
build.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const fs = require("fs");
/**
* Initialize build process
*
* @function init
*/
(function init() {
const vanillaApps = fs
.readdirSync(__dirname, { withFileTypes: true })
.filter(isDirentValidDirectory)
.map((dir) => dir.name);
const listItems = vanillaApps.map(getListItemString).join("");
const buildMarkup = getBuildMarkup(listItems);
fs.writeFileSync("index.html", buildMarkup);
})();
/**
* Returns final build markup
*
* @function getBuildMarkup
* @param {String} listItems
* @returns {String} Final Markup String
*/
function getBuildMarkup(listItems) {
return `<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Vanilla Web</title> </head> <body> <h1>Welcome to Vanilla Web</h1> <p> A list of vanilla web implementations of some common and important concepts. </p><p> Source Code for this project can be found <a target="_blank" href="https://github.com/akulsr0/vanilla-web/">here</a> </p><h2>Apps</h2> <ul id="vanilla-apps-list">${listItems}</ul> </body></html>`;
}
/**
* Title Cases a word
* eg. accordion -> Accordion
*
* @function toTitle
* @param {string} w
* @returns {string} Title Cased Word
*/
function toTitle(w) {
return w[0].toUpperCase() + w.slice(1).toLowerCase();
}
/**
* Returns apps list item markup
*
* @function getListItemString
* @param {string} app
* @returns {string}
*/
function getListItemString(app) {
const appTitle = app.split("-").map(toTitle).join(" ");
return `<li><a href="./${app}">${appTitle}</a></li>`;
}
/**
* Checks if a dirent is a directory and is not hidden.
*
* @function isDirentValidDirectory
* @param {fs.Dirent} dirent
* @returns {boolean}
*/
function isDirentValidDirectory(dirent) {
const isDirentHidden = dirent.name.startsWith(".");
return dirent.isDirectory() && !isDirentHidden;
}