feat: Auto-detect readme filename

BREAKING CHANGE: the --readme-file option now has a smart default value
This commit is contained in:
Tom MacWright 2018-05-21 20:39:00 -07:00
parent 251650424b
commit 4fd776b16a
No known key found for this signature in database
GPG Key ID: 3E7BD5F5BA0CEB5F
3 changed files with 58 additions and 4 deletions

View File

@ -1,5 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`readme autodetection of different filenames updates readme.markdown 1`] = `
"# A title
# API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [foo](#foo)
- [bar](#bar)
## foo
A function with documentation.
**Parameters**
- \`a\` {string} blah
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** answer
## bar
A second function with docs
**Parameters**
- \`b\`
# Another section
"
`;
exports[`readme command --readme-file 1`] = `
"# A title

View File

@ -22,6 +22,29 @@ function documentation(args, options, parseJSON) {
});
}
describe('readme autodetection of different filenames', function() {
const fixtures = path.join(__dirname, 'fixture/readme');
const sourceFile = path.join(fixtures, 'index.js');
let d;
let removeCallback;
beforeEach(() => {
const dirEntry = tmp.dirSync({ unsafeCleanup: true });
d = dirEntry.name;
fs.copySync(
path.join(fixtures, 'README.input.md'),
path.join(d, 'readme.markdown')
);
fs.copySync(path.join(fixtures, 'index.js'), path.join(d, 'index.js'));
});
test('updates readme.markdown', async function() {
await documentation(['readme index.js -s API'], { cwd: d });
const outputPath = path.join(d, 'readme.markdown');
expect(fs.readFileSync(outputPath, 'utf-8')).toMatchSnapshot();
});
});
describe('readme command', function() {
const fixtures = path.join(__dirname, 'fixture/readme');
const sourceFile = path.join(fixtures, 'index.js');

View File

@ -5,14 +5,11 @@ const path = require('path');
module.exports = function findReadme(dir: string) {
const readmeFilenames = [
'README',
'README.markdown',
'README.md',
'README.txt',
'Readme.md',
'readme.markdown',
'readme.md',
'readme.txt'
'readme.md'
];
const readmeFile = fs.readdirSync(dir).find(function(filename) {