Skip to content
This repository was archived by the owner on Oct 5, 2022. It is now read-only.

Commit ac086c7

Browse files
committed
inject custom homepage into jsdoc from ejs templates
1 parent 0241629 commit ac086c7

18 files changed

+1115
-1435
lines changed

fonts.js renamed to build/fonts.js

File renamed without changes.

build/postflight.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* macOSNotifJS: A simple Javascript plugin to create simulated macOS notifications on your website.
3+
* <https://github.com/MattIPv4/macOSNotifJS/>
4+
* Copyright (C) 2019 Matt Cowley (MattIPv4) (me@mattcowley.co.uk)
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published
8+
* by the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, please see
16+
* <https://github.com/MattIPv4/macOSNotifJS/blob/master/LICENSE> or <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
const { name, version, description, browserslist } = require("../package.json");
20+
const chalk = require("chalk");
21+
const fs = require("fs");
22+
const jsdoc = require("jsdoc-api");
23+
const ejs = require("ejs");
24+
25+
const buildJSDoc = async position => {
26+
// Remove previous docs contents
27+
try {
28+
jsdoc.renderSync({
29+
files: [
30+
"src/macOSNotif.js",
31+
"src/themes.js",
32+
"src/interact.js",
33+
],
34+
package: "package.json",
35+
destination: "docs",
36+
});
37+
} catch (err) {
38+
console.error(chalk.red.bold(`\n${position} Failed to build JSDoc.`));
39+
throw err;
40+
}
41+
42+
// Done
43+
console.log(chalk.greenBright.bold(`\n${position} Successfully built new JSDoc documentation.`));
44+
};
45+
46+
const injectDocsHome = async position => {
47+
// Create the template variables
48+
const dateOfBuild = new Date().toISOString().slice(0, 10);
49+
const projectName = "macOSNotifJS";
50+
const browsers = browserslist.map(x => {
51+
return [
52+
"https://browserl.ist/?q=" + encodeURIComponent(x),
53+
x,
54+
];
55+
});
56+
57+
// Render the template
58+
let html;
59+
try {
60+
const templateFile = "build/templates/docs-home.ejs";
61+
const template = fs.readFileSync(templateFile, "utf8");
62+
html = ejs.render(template, {
63+
filename: templateFile,
64+
65+
name: projectName,
66+
version: version,
67+
dateOfBuild: dateOfBuild,
68+
description: description,
69+
browsers: browsers,
70+
});
71+
} catch (err) {
72+
console.error(chalk.red.bold(`\n${position} Failed to render custom homepage.`));
73+
throw err;
74+
}
75+
76+
// Inject into jsdoc
77+
try {
78+
const filePath = `docs/${name}/${version}/index.html`;
79+
let file = fs.readFileSync(filePath, "utf8");
80+
file = file.replace(`<h3>${name} ${version}</h3>`, html);
81+
fs.writeFileSync(filePath, file);
82+
} catch (err) {
83+
console.error(chalk.red.bold(`\n${position} Failed to inject custom homepage.`));
84+
throw err;
85+
}
86+
87+
// Done
88+
console.log(chalk.greenBright.bold(`\n${position} Custom JSDoc homepage successfully rendered & injected.`));
89+
};
90+
91+
const processes = [
92+
buildJSDoc,
93+
injectDocsHome,
94+
];
95+
96+
const postFlight = async () => {
97+
// Hello!
98+
console.info(chalk.cyan.bold("Hello! Beginning the post-flight processes for macOSNotifJS!"));
99+
100+
// Run
101+
processes.forEach(async (item, i) => {
102+
await item("(" + (i + 1) + "/" + processes.length + ")");
103+
});
104+
105+
// Done!
106+
console.log(chalk.green.bold("\nAll done!\n"));
107+
};
108+
109+
// Run
110+
postFlight();

preflight.js renamed to build/preflight.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
const chalk = require("chalk");
2020
const fs = require("fs");
2121
const { fork } = require("child_process");
22-
const jsdoc = require("jsdoc-api");
2322

2423
const runFonts = () => {
2524
return new Promise(resolve => {
@@ -52,7 +51,7 @@ const validateFonts = async position => {
5251
// Validate fonts built
5352
if (fs.existsSync("src/fonts/build")) {
5453
console.log(chalk.green("\nFonts build directory present, assuming already built."));
55-
console.info(chalk.cyan(" Run ") + chalk.cyanBright.italic("`node fonts.js`") + chalk.cyan(" to re-build fonts."));
54+
console.info(chalk.cyan(" Run ") + chalk.cyanBright.italic("`node build/fonts.js`") + chalk.cyan(" to re-build fonts."));
5655
} else {
5756
console.error(chalk.redBright("\nFonts build not found, building now..."));
5857
await runFonts();
@@ -75,32 +74,9 @@ const clearPreviousBuild = async position => {
7574
console.log(chalk.greenBright.bold(`\n${position} Successfully emptied dist directory.`));
7675
};
7776

78-
const buildJSDoc = async position => {
79-
// Remove previous docs contents
80-
try {
81-
jsdoc.renderSync({
82-
files: [
83-
"src/macOSNotif.js",
84-
"src/themes.js",
85-
"src/interact.js",
86-
],
87-
package: "package.json",
88-
readme: "README.md",
89-
destination: "docs",
90-
});
91-
} catch (err) {
92-
console.error(chalk.red.bold(`\n${position} Failed to build JSDoc.`));
93-
throw err;
94-
}
95-
96-
// Done
97-
console.log(chalk.greenBright.bold(`\n${position} Successfully built new JSDoc documentation.`));
98-
};
99-
10077
const processes = [
10178
validateFonts,
10279
clearPreviousBuild,
103-
buildJSDoc,
10480
];
10581

10682
const preFlight = async () => {

0 commit comments

Comments
 (0)