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

Commit 68f53a0

Browse files
authored
Merge pull request #27 from MattIPv4/jsdoc
Implement JSDoc
2 parents eeda7b9 + 9c70d0b commit 68f53a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+17968
-1242
lines changed

.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@
7777
"radix": [
7878
"error",
7979
"always"
80+
],
81+
"require-jsdoc": [
82+
"error",
83+
{
84+
"require": {
85+
"FunctionDeclaration": true,
86+
"MethodDefinition": true,
87+
"ClassDeclaration": true,
88+
"ArrowFunctionExpression": true,
89+
"FunctionExpression": true
90+
}
91+
}
92+
],
93+
"valid-jsdoc": [
94+
"error",
95+
{
96+
"requireReturn": false
97+
}
8098
]
8199
}
82100
}

fonts.js renamed to build/fonts.js

File renamed without changes.

build/postflight.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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 templateOptions = {
26+
name: "macOSNotifJS",
27+
packageName: name,
28+
version: version,
29+
dateOfBuild: new Date().toISOString().slice(0, 10),
30+
description: description,
31+
browsers: browserslist.map(x => {
32+
return [
33+
"https://browserl.ist/?q=" + encodeURIComponent(x),
34+
x,
35+
];
36+
}),
37+
};
38+
39+
const buildJSDoc = async position => {
40+
// Remove previous docs contents
41+
try {
42+
jsdoc.renderSync({
43+
files: [
44+
"src/macOSNotif.js",
45+
],
46+
package: "package.json",
47+
destination: "docs",
48+
});
49+
} catch (err) {
50+
console.error(chalk.red.bold(`\n${position} Failed to build JSDoc.`));
51+
throw err;
52+
}
53+
54+
// Done
55+
console.log(chalk.greenBright.bold(`\n${position} Successfully built new JSDoc documentation.`));
56+
};
57+
58+
const injectDocsHome = async position => {
59+
// Render the template
60+
let html;
61+
try {
62+
const templateFile = "build/templates/docs-home.ejs";
63+
const template = fs.readFileSync(templateFile, "utf8");
64+
html = ejs.render(template, {
65+
...templateOptions,
66+
filename: templateFile,
67+
});
68+
} catch (err) {
69+
console.error(chalk.red.bold(`\n${position} Failed to render custom homepage.`));
70+
throw err;
71+
}
72+
73+
// Inject into jsdoc
74+
try {
75+
const filePath = `docs/${name}/${version}/index.html`;
76+
let file = fs.readFileSync(filePath, "utf8");
77+
file = file
78+
.replace(`<h3>${name} ${version}</h3>`, html)
79+
.replace("<title>", `<title>${name} - v${version} - `);
80+
fs.writeFileSync(filePath, file);
81+
} catch (err) {
82+
console.error(chalk.red.bold(`\n${position} Failed to inject custom homepage.`));
83+
throw err;
84+
}
85+
86+
// Done
87+
console.log(chalk.greenBright.bold(`\n${position} Custom JSDoc homepage successfully rendered & injected.`));
88+
};
89+
90+
const createMainIndex = async position => {
91+
// Render the template
92+
try {
93+
const templateFile = "build/templates/main-index.ejs";
94+
const template = fs.readFileSync(templateFile, "utf8");
95+
const html = ejs.render(template, {
96+
...templateOptions,
97+
filename: templateFile,
98+
});
99+
fs.writeFileSync("index.html", html);
100+
} catch (err) {
101+
console.error(chalk.red.bold(`\n${position} Failed to render main index.`));
102+
throw err;
103+
}
104+
105+
// Done
106+
console.log(chalk.greenBright.bold(`\n${position} Successfully rendered main index file.`));
107+
};
108+
109+
const processes = [
110+
buildJSDoc,
111+
injectDocsHome,
112+
createMainIndex,
113+
];
114+
115+
const postFlight = async () => {
116+
// Hello!
117+
console.info(chalk.cyan.bold("Hello! Beginning the post-flight processes for macOSNotifJS!"));
118+
119+
// Run
120+
processes.forEach(async (item, i) => {
121+
await item("(" + (i + 1) + "/" + processes.length + ")");
122+
});
123+
124+
// Done!
125+
console.log(chalk.green.bold("\nAll done!\n"));
126+
};
127+
128+
// Run
129+
postFlight();

preflight.js renamed to build/preflight.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const runFonts = () => {
3131
});
3232
};
3333

34-
const emptyDir = dirPath => {
34+
const emptyDir = (dirPath, deleteDir) => {
3535
// Loop over every item in the directory
3636
const files = fs.readdirSync(dirPath);
3737
for (let i = 0; i < files.length; i++) {
@@ -41,35 +41,55 @@ const emptyDir = dirPath => {
4141
fs.unlinkSync(filePath);
4242
} else {
4343
// If not, recurse as it is a directory
44-
emptyDir(filePath);
44+
emptyDir(filePath, true);
4545
}
4646
}
47+
if (deleteDir) fs.rmdirSync(dirPath);
4748
};
4849

49-
const preFlight = async () => {
50-
// Hello!
51-
console.info(chalk.cyan.bold("Hello! Beginning the pre-flight checks for the macOSNotifJS build process!"));
52-
50+
const validateFonts = async position => {
5351
// Validate fonts built
5452
if (fs.existsSync("src/fonts/build")) {
55-
console.log(chalk.green("\n(1/2) Fonts build directory present, assuming already built."));
56-
console.info(chalk.cyan(" Run ") + chalk.cyanBright.italic("`node fonts.js`") + chalk.cyan(" to re-build fonts."));
53+
console.log(chalk.green("\nFonts build directory present, assuming already built."));
54+
console.info(chalk.cyan(" Run ") + chalk.cyanBright.italic("`node build/fonts.js`") + chalk.cyan(" to re-build fonts."));
5755
} else {
5856
console.error(chalk.redBright("\nFonts build not found, building now..."));
5957
await runFonts();
6058
}
6159

60+
// Done
61+
console.log(chalk.greenBright.bold(`\n${position} Fonts validation completed successfully.`));
62+
};
63+
64+
const clearPreviousBuild = async position => {
6265
// Remove previous plugin build
6366
try {
6467
emptyDir("dist");
6568
} catch (err) {
66-
console.error(chalk.red.bold("\n(2/2) Failed to empty dist directory"));
69+
console.error(chalk.red.bold(`\n${position} Failed to empty dist directory.`));
6770
throw err;
6871
}
69-
console.log(chalk.green("\n(2/2) Successfully emptied dist directory."));
72+
73+
// Done
74+
console.log(chalk.greenBright.bold(`\n${position} Successfully emptied dist directory.`));
75+
};
76+
77+
const processes = [
78+
validateFonts,
79+
clearPreviousBuild,
80+
];
81+
82+
const preFlight = async () => {
83+
// Hello!
84+
console.info(chalk.cyan.bold("Hello! Beginning the pre-flight checks for the macOSNotifJS build process!"));
85+
86+
// Run
87+
processes.forEach(async (item, i) => {
88+
await item("(" + (i + 1) + "/" + processes.length + ")");
89+
});
7090

7191
// Done!
72-
console.log(chalk.greenBright.bold("\nReady to begin webpack build!\n"));
92+
console.log(chalk.green.bold("\nReady to begin webpack build!\n"));
7393
};
7494

7595
// Run

0 commit comments

Comments
 (0)