Skip to content

Commit e07cf0f

Browse files
boneskullcraigtaub
authored andcommitted
do not commit generated content to VCS; closes #3713 (#4289)
* do not commit generated content to VCS This removes `markdown-magic` and replaces its functionality with the built-in data capabilities of 11ty. The TOC, `--help` output, and source files are now all done via global data scripts in `docs/_data`. When building documentation, we will no longer get changes to e.g., `docs/index.md` because of the automatically generated content. * add inclusive language plugin to eleventy Usage of the words as defined in options will result in a warning, and will not break the build. Also: Eleventy should ignore the historical changelogs in `docs/changelogs`.
1 parent 137ba18 commit e07cf0f

14 files changed

+647
-557
lines changed

.eleventy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
'use strict';
22

33
module.exports = function(eleventyConfig) {
4+
eleventyConfig.addPlugin(
5+
require('@11ty/eleventy-plugin-inclusive-language'),
6+
{
7+
words:
8+
'simply,obviously,basically,of course,clearly,everyone knows,however,easy'
9+
}
10+
);
11+
412
eleventyConfig.addPassthroughCopy('docs/css');
513
eleventyConfig.addPassthroughCopy('docs/js');
614
eleventyConfig.addPassthroughCopy('docs/images');

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ overrides:
3636
- test/integration/options/watch.spec.js
3737
- test/integration/helpers.js
3838
- lib/growl.js
39+
- docs/_data/**/*.js
3940
parserOptions:
4041
ecmaVersion: 2017
4142
env:

docs/.eleventyignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ LICENSE*
44
.*
55
_dist/
66
example/
7+
changelogs/

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _So you wanna build the site?_
3434
cp: docs/_dist/_headers: No such file or directory
3535
```
3636

37-
- See `package-scripts.js` for details on what the builds are actually doing; especially see [markdown-magic](https://npm.im/markdown-magic) for how we're dynamically inserting information into `docs/index.md`.
37+
- See `package-scripts.js` for details on what the builds are actually doing.
3838

3939
## License
4040

docs/_data/files.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
const {resolve, relative, dirname} = require('path');
4+
const {readFileSync} = require('fs');
5+
6+
const PROJECT_ROOT_DIR = resolve(__dirname, '..', '..');
7+
const FILES = [
8+
{
9+
slug: 'simplereporter',
10+
path: require.resolve('../../test/integration/fixtures/simple-reporter.js'),
11+
header: '// my-reporter.js'
12+
}
13+
];
14+
15+
const HEADER = '```js\n';
16+
const FOOTER = '```\n';
17+
18+
const loadFile = (path, {header} = {}) => {
19+
const relativeDir = relative(dirname(path), PROJECT_ROOT_DIR);
20+
let content = readFileSync(path, 'utf-8');
21+
// replace relative paths in `require()` to root with "mocha".
22+
// might not work in the general case. not gonna parse an AST for this
23+
// e.g. `require('../../lib/foo')` => `require('mocha/lib/foo')`
24+
// also trim any trailing whitespace
25+
content = content
26+
.replace(
27+
new RegExp(`require\\(['"]${relativeDir}(.*?)['"]\\)`, 'g'),
28+
"require('mocha$1')"
29+
)
30+
.trim();
31+
return `${HEADER}${header}\n\n${content}${FOOTER}`;
32+
};
33+
34+
/**
35+
* Loads files from disk (see `FILES` above) to be shown as data.
36+
* Used for embedding sources directly into pages
37+
*/
38+
module.exports = () => {
39+
const files = FILES.map(({path, header, slug}) => {
40+
const content = loadFile(path, {header});
41+
return {slug, content};
42+
});
43+
return files.reduce(
44+
(files, {slug, content}) => ({
45+
...files,
46+
[slug]: content
47+
}),
48+
{}
49+
);
50+
};

docs/_data/toc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const markdownToc = require('markdown-toc');
4+
const {readFileSync} = require('fs');
5+
const {resolve} = require('path');
6+
7+
const IGNORED_HEADINGS_REGEXP = /Features|Table of Contents|Backers|Sponsors/i;
8+
const DOCUMENT_PATH = resolve(__dirname, '..', 'index.md');
9+
10+
module.exports = () => {
11+
const doc = readFileSync(DOCUMENT_PATH, 'utf-8');
12+
return markdownToc(doc, {
13+
slugify: require('uslug'),
14+
firsth1: false,
15+
bullets: '-',
16+
maxdepth: 2,
17+
// if filter is supplied, maxdepth is apparently ignored,
18+
// so we have to do it ourselves.
19+
filter: (str, ele) => ele.lvl < 2 && !IGNORED_HEADINGS_REGEXP.test(str)
20+
}).content;
21+
};

docs/_data/usage.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const stripAnsi = require('strip-ansi');
4+
const {resolve} = require('path');
5+
const {execSync} = require('child_process');
6+
7+
const executable = require.resolve('../../bin/mocha');
8+
const flag = '--help';
9+
10+
/**
11+
* Return the output of `mocha --help` for display
12+
*/
13+
module.exports = () => {
14+
return stripAnsi(
15+
String(
16+
execSync(`"${process.execPath}" ${executable} ${flag}`, {
17+
cwd: resolve(__dirname, '..')
18+
})
19+
).trim()
20+
);
21+
};

docs/api-tutorials/custom-reporter.md

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,7 @@ 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-
<!-- AUTO-GENERATED-CONTENT:START (file:src=../../test/integration/fixtures/simple-reporter.js&header=// my-reporter.js)' -->
10-
11-
```js
12-
// my-reporter.js
13-
'use strict';
14-
15-
const Mocha = require('mocha');
16-
const {
17-
EVENT_RUN_BEGIN,
18-
EVENT_RUN_END,
19-
EVENT_TEST_FAIL,
20-
EVENT_TEST_PASS,
21-
EVENT_SUITE_BEGIN,
22-
EVENT_SUITE_END
23-
} = Mocha.Runner.constants;
24-
25-
// this reporter outputs test results, indenting two spaces per suite
26-
class MyReporter {
27-
constructor(runner) {
28-
this._indents = 0;
29-
const stats = runner.stats;
30-
31-
runner
32-
.once(EVENT_RUN_BEGIN, () => {
33-
console.log('start');
34-
})
35-
.on(EVENT_SUITE_BEGIN, () => {
36-
this.increaseIndent();
37-
})
38-
.on(EVENT_SUITE_END, () => {
39-
this.decreaseIndent();
40-
})
41-
.on(EVENT_TEST_PASS, test => {
42-
// Test#fullTitle() returns the suite name(s)
43-
// prepended to the test title
44-
console.log(`${this.indent()}pass: ${test.fullTitle()}`);
45-
})
46-
.on(EVENT_TEST_FAIL, (test, err) => {
47-
console.log(
48-
`${this.indent()}fail: ${test.fullTitle()} - error: ${err.message}`
49-
);
50-
})
51-
.once(EVENT_RUN_END, () => {
52-
console.log(`end: ${stats.passes}/${stats.passes + stats.failures} ok`);
53-
});
54-
}
55-
56-
indent() {
57-
return Array(this._indents).join(' ');
58-
}
59-
60-
increaseIndent() {
61-
this._indents++;
62-
}
63-
64-
decreaseIndent() {
65-
this._indents--;
66-
}
67-
}
68-
69-
module.exports = MyReporter;
70-
```
71-
72-
<!-- AUTO-GENERATED-CONTENT:END -->
9+
{{ files.simplereporter }}
7310

7411
To use this reporter, execute `mocha --reporter /path/to/my-reporter.js`.
7512

@@ -110,4 +47,4 @@ The event names are exported from the `constants` property of `Mocha.Runner`:
11047

11148
**Please use these constants** instead of the event names in your own reporter! This will ensure compatibility with future versions of Mocha.
11249

113-
> It's important to understand that all `Suite` callbacks will be run _before_ the {@link Runner} emits `EVENT_RUN_BEGIN`. Hooks and tests, however, won't run until _after_ the {@link Runner} emits `EVENT_RUN_BEGIN`.
50+
> It's important to understand that all `Suite` callbacks will be run _before_ the {@link Runner} emits `EVENT_RUN_BEGIN`. Hooks and tests won't run until _after_ the {@link Runner} emits `EVENT_RUN_BEGIN`.

docs/changelogs/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Historical Changelogs
2+
3+
These are changelogs for (very) old versions of Mocha.
4+
5+
These changelogs are _not_ included in the website, and are here only for archival purposes.
6+
7+
_If you're looking for the current changelog, [here is the current changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)._

0 commit comments

Comments
 (0)