Skip to content

Commit 4fd776b

Browse files
committedMay 22, 2018
feat: Auto-detect readme filename
BREAKING CHANGE: the --readme-file option now has a smart default value
1 parent 2516504 commit 4fd776b

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed
 

‎__tests__/__snapshots__/bin-readme.js.snap

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`readme autodetection of different filenames updates readme.markdown 1`] = `
4+
"# A title
5+
6+
# API
7+
8+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
9+
10+
### Table of Contents
11+
12+
- [foo](#foo)
13+
- [bar](#bar)
14+
15+
## foo
16+
17+
A function with documentation.
18+
19+
**Parameters**
20+
21+
- \`a\` {string} blah
22+
23+
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** answer
24+
25+
## bar
26+
27+
A second function with docs
28+
29+
**Parameters**
30+
31+
- \`b\`
32+
33+
# Another section
34+
"
35+
`;
36+
337
exports[`readme command --readme-file 1`] = `
438
"# A title
539

‎__tests__/bin-readme.js

+23
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ function documentation(args, options, parseJSON) {
2222
});
2323
}
2424

25+
describe('readme autodetection of different filenames', function() {
26+
const fixtures = path.join(__dirname, 'fixture/readme');
27+
const sourceFile = path.join(fixtures, 'index.js');
28+
let d;
29+
let removeCallback;
30+
31+
beforeEach(() => {
32+
const dirEntry = tmp.dirSync({ unsafeCleanup: true });
33+
d = dirEntry.name;
34+
fs.copySync(
35+
path.join(fixtures, 'README.input.md'),
36+
path.join(d, 'readme.markdown')
37+
);
38+
fs.copySync(path.join(fixtures, 'index.js'), path.join(d, 'index.js'));
39+
});
40+
41+
test('updates readme.markdown', async function() {
42+
await documentation(['readme index.js -s API'], { cwd: d });
43+
const outputPath = path.join(d, 'readme.markdown');
44+
expect(fs.readFileSync(outputPath, 'utf-8')).toMatchSnapshot();
45+
});
46+
});
47+
2548
describe('readme command', function() {
2649
const fixtures = path.join(__dirname, 'fixture/readme');
2750
const sourceFile = path.join(fixtures, 'index.js');

‎src/get-readme-file.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ const path = require('path');
55

66
module.exports = function findReadme(dir: string) {
77
const readmeFilenames = [
8-
'README',
98
'README.markdown',
109
'README.md',
11-
'README.txt',
1210
'Readme.md',
1311
'readme.markdown',
14-
'readme.md',
15-
'readme.txt'
12+
'readme.md'
1613
];
1714

1815
const readmeFile = fs.readdirSync(dir).find(function(filename) {

0 commit comments

Comments
 (0)
Please sign in to comment.