Skip to content

Commit 24d1dfb

Browse files
authored
fix broken template processing in jsdoc output (#4381)
because the files generated by jsdoc were output to `docs/_site`, they were not processed as liquid templates, which meant the custom reporter tutorial was broken. to fix this, we needed to: 1. change the output directory of jsdoc to `docs/api` (just somewhere else) 2. add this to `.gitignore`, obviously 3. tell eleventy to _ignore_ `.gitignore` (just rely on its `.eleventyignore` file) 4. tell eleventy to pass-through all assets underneath `docs/api` (css, images, etc) 5. update the file-loading 11ty data script to output a raw file 6. update the tutorial to use a fenced code block (jsdoc markdown plugin seems to strip html?) and tell Prettier to ignore the liquid template directive also: - removed link to google group - prettier-related reformats - tweak data script to use `fs.promises` * update @mocha/docdash Signed-off-by: Christopher Hiller <[email protected]>
1 parent 7c91d82 commit 24d1dfb

10 files changed

+98
-90
lines changed

.eleventy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ module.exports = function(eleventyConfig) {
1616
eleventyConfig.addPassthroughCopy('docs/_headers');
1717
eleventyConfig.addPassthroughCopy('docs/favicon.ico');
1818
eleventyConfig.addPassthroughCopy('docs/example');
19+
eleventyConfig.addPassthroughCopy('docs/api/images');
20+
eleventyConfig.addPassthroughCopy('docs/api/scripts');
21+
eleventyConfig.addPassthroughCopy('docs/api/styles');
1922

2023
/* Markdown Plugins */
2124
const markdown = require('markdown-it')({
@@ -43,11 +46,12 @@ module.exports = function(eleventyConfig) {
4346

4447
eleventyConfig.setLibrary('md', markdown);
4548

49+
eleventyConfig.setUseGitIgnore(false);
50+
4651
return {
4752
passthroughFileCopy: true,
4853
dir: {
4954
input: 'docs',
50-
includes: '_includes',
5155
output: 'docs/_site'
5256
}
5357
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
docs/_site
33
docs/_dist
44
docs/images/supporters
5+
docs/api
56
mocha.js
67
mocha.js.map
78
.karma/

docs/.eleventyignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ LICENSE*
55
_dist/
66
example/
77
changelogs/
8+
api-tutorials/
9+
_site/
10+

docs/API.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Mocha's API Documentation
22

3-
* * *
3+
---
44

5-
Congratulations! You've found Mocha's API documentation. These docs are for developers who wish to:
5+
Congratulations! You've found Mocha's API documentation. These docs are for developers who wish to:
66

77
- Create an extension for Mocha, or
88
- Develop Mocha itself, or
@@ -16,5 +16,4 @@ Otherwise, **you probably want the [main documentation](https://mochajs.org)**.
1616
- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)**
1717
- [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md)
1818
- [Gitter Chatroom](https://gitter.im/mochajs/mocha) (ask questions here!)
19-
- [Google Group](https://groups.google.com/group/mochajs)
2019
- [Issue Tracker](https://github.com/mochajs/mocha/issues)

docs/_data/files.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const {resolve, relative, dirname} = require('path');
4-
const {readFileSync} = require('fs');
4+
const {promises: fs} = require('fs');
55

66
const PROJECT_ROOT_DIR = resolve(__dirname, '..', '..');
77
const FILES = [
@@ -12,12 +12,9 @@ const FILES = [
1212
}
1313
];
1414

15-
const HEADER = '```js\n';
16-
const FOOTER = '```\n';
17-
18-
const loadFile = (path, {header} = {}) => {
15+
const loadFile = async (path, {header} = {}) => {
1916
const relativeDir = relative(dirname(path), PROJECT_ROOT_DIR);
20-
let content = readFileSync(path, 'utf-8');
17+
let content = await fs.readFile(path, 'utf-8');
2118
// replace relative paths in `require()` to root with "mocha".
2219
// might not work in the general case. not gonna parse an AST for this
2320
// e.g. `require('../../lib/foo')` => `require('mocha/lib/foo')`
@@ -28,18 +25,19 @@ const loadFile = (path, {header} = {}) => {
2825
"require('mocha$1')"
2926
)
3027
.trim();
31-
return `${HEADER}${header}\n\n${content}${FOOTER}`;
28+
return `${header}\n\n${content}`;
3229
};
3330

3431
/**
3532
* Loads files from disk (see `FILES` above) to be shown as data.
3633
* Used for embedding sources directly into pages
3734
*/
38-
module.exports = () => {
39-
const files = FILES.map(({path, header, slug}) => {
40-
const content = loadFile(path, {header});
41-
return {slug, content};
42-
});
35+
module.exports = async () => {
36+
const files = [];
37+
for await (const {path, header, slug} of FILES) {
38+
const content = await loadFile(path, {header});
39+
files.push({slug, content});
40+
}
4341
return files.reduce(
4442
(files, {slug, content}) => ({
4543
...files,

docs/api-tutorials/custom-reporter.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ For example, if `mocha-foo-reporter` was published to the npm registry, you coul
66

77
If you're looking to get started quickly, here's an example of a custom reporter:
88

9+
<!-- prettier-ignore -->
10+
```js
911
{{ files.simplereporter }}
12+
```
1013

1114
To use this reporter, execute `mocha --reporter /path/to/my-reporter.js`.
1215

jsdoc.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"static": false
99
},
1010
"opts": {
11-
"destination": "docs/_site/api",
11+
"destination": "docs/api",
1212
"encoding": "utf8",
1313
"recurse": true,
1414
"template": "node_modules/@mocha/docdash",

0 commit comments

Comments
 (0)