mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
feat: Auto-detect readme filename
BREAKING CHANGE: the --readme-file option now has a smart default value
This commit is contained in:
parent
251650424b
commit
4fd776b16a
@ -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
|
||||
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user