Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit ca724f1

Browse files
committed
[FIX]: The name of the component is equal to the property defined in the name component, this is required
1 parent 132a4a2 commit ca724f1

File tree

6 files changed

+44
-45
lines changed

6 files changed

+44
-45
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,17 @@ we are getting this output:
312312
}
313313
```
314314

315+
## Change log
316+
317+
The change log can be found on the [Releases page](https://github.com/vue-styleguidist/vue-docgen-api/releases).
318+
319+
## Authors and license
320+
321+
[Rafael Escala](https://github.com/rafaesc92)
322+
323+
MIT License.
324+
325+
315326
[JSDoc]: http://usejsdoc.org/
316327
[vue]: https://vuejs.org/
317328
[babel]: https://www.npmjs.com/package/babel-core

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-docgen-api",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Toolbox to extract information from Vue component files for documentation generation purposes.",
55
"bugs": {
66
"url": "https://github.com/vue-styleguidist/vue-docgen-api/issues"

src/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function parse(file) {
77
throw new Error('The document is empty');
88
}
99
const jscodeReqest = utils.getComponentModuleJSCode(source, file);
10-
const component = utils.getSandbox(jscodeReqest, file).default;
10+
const component = utils.getSandbox(jscodeReqest).default;
1111
const doc = utils.getDocFile(jscodeReqest, file);
1212
const vueDoc = utils.getVueDoc(doc, component);
1313
return vueDoc;

src/utils/getVueDoc.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,14 @@ import processTags from './processTags';
33
import processProps from './processProps';
44
import processMethods from './processMethods';
55

6-
const getFileName = (fileName) => {
7-
return fileName.split('\\').reverse()[0].split('.')[0]
8-
}
9-
10-
const capitalizeFirstLetter = (str) => {
11-
return str[0].toUpperCase() + str.substr(1)
12-
}
13-
14-
const kebabToCamel= (myString) => {
15-
return myString.replace(/-([aA-zZ])/g, function (g) { return g[1].toUpperCase() })
16-
}
17-
18-
function getFileNameComponent(doc) {
19-
const packageComponent = doc.filter( comment => {
20-
return comment.kind === 'package'
21-
} )[0];
22-
const fileName = packageComponent['files'][0];
23-
return capitalizeFirstLetter(kebabToCamel(getFileName(fileName)));
24-
}
25-
266
export default function getVueDoc(docFile, component) {
277
let displayName;
288
let docComponent;
9+
if (!component.name || component.name === '') {
10+
throw new Error("The component has no name, add 'el' property on the Vue component");
11+
}
12+
displayName = component.name;
2913
if (docFile) {
30-
displayName = getFileNameComponent(docFile);
3114
docFile = docFile.filter( comment => {
3215
return comment.kind !== 'package'
3316
});
@@ -36,7 +19,6 @@ export default function getVueDoc(docFile, component) {
3619
})[0];
3720
} else {
3821
docFile = [];
39-
displayName = component.name || EMPTY;
4022
docComponent = false;
4123
}
4224
let description = EMPTY;

tests/components/button/Button.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<template>
2-
<button class="button" @click.prevent="onClick">
2+
<button class="buttonComponent" @click.prevent="onClick">
33
<slot></slot>
44
</button>
55
</template>
66

77
<script>
88
99
export default {
10-
name: 'button',
10+
name: 'buttonComponent',
1111
props: {
1212
/**
13-
* The color for the button
13+
* The color for the button example
1414
*/
1515
color: {
1616
type: String,

tests/index.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,60 @@ var api = require('../dist/main');
33
var grid = path.join(__dirname, './components/grid/Grid.vue');
44
var button = path.join(__dirname, './components/button/Button.vue');
55
const expect = require("chai").expect;
6+
let docGrid;
7+
let docButton;
68

7-
describe('tests', () => {
8-
it('should not return error', () => {
9-
expect(() => {api.parse(grid)}).to.not.throw()
10-
expect(() => {api.parse(button)}).to.not.throw()
9+
describe('tests components', () => {
10+
docGrid = api.parse(grid);
11+
docButton = api.parse(button);
12+
console.log(JSON.stringify(docButton, null, 2));
13+
14+
it('should return an object', () => {
15+
expect(docGrid).to.be.an('object')
16+
expect(docButton).to.be.an('object')
1117
})
1218

13-
const docJson = api.parse(grid);
14-
const docButtonJson = api.parse(button);
15-
console.log(JSON.stringify(docButtonJson, null, 2));
19+
it('The component name should be buttonComponent', () => {
20+
expect(docButton.displayName).to.equal('buttonComponent');
21+
})
1622

17-
it('should return an object', () => {
18-
expect(docJson).to.be.an('object')
23+
it('The component name should be grid', () => {
24+
expect(docGrid.displayName).to.equal('grid');
1925
})
2026

2127
it('should the component have tags', () => {
22-
expect(typeof docJson['tags'] !== 'undefined').to.be.true
28+
expect(typeof docGrid['tags'] !== 'undefined').to.be.true
2329
})
2430

2531
it('should the component have authors', () => {
26-
expect(typeof docJson['tags']['author'] !== 'undefined').to.be.true
32+
expect(typeof docGrid['tags']['author'] !== 'undefined').to.be.true
2733
})
2834

2935
it('should the component have description', () => {
30-
expect(typeof docJson['description'] !== 'undefined').to.be.true
36+
expect(typeof docGrid['description'] !== 'undefined').to.be.true
3137
})
3238

3339
it('should have methods', () => {
34-
expect(typeof docJson['methods'] !== 'undefined').to.be.true
40+
expect(typeof docGrid['methods'] !== 'undefined').to.be.true
3541
})
3642

3743
it('should the component have one method', () => {
38-
expect(Object.keys(docJson['methods']).length === 1).to.be.true
44+
expect(Object.keys(docGrid['methods']).length === 1).to.be.true
3945
})
4046

4147
it('should have props', () => {
42-
expect(typeof docJson['props'] !== 'undefined').to.be.true
48+
expect(typeof docGrid['props'] !== 'undefined').to.be.true
4349
})
4450

4551
it('should the component have version', () => {
46-
expect(typeof docJson['tags']['version'] !== 'undefined').to.be.true
52+
expect(typeof docGrid['tags']['version'] !== 'undefined').to.be.true
4753
})
4854

4955
it('should the component have three prop', () => {
50-
expect(Object.keys(docJson['props']).length === 3).to.be.true
56+
expect(Object.keys(docGrid['props']).length === 3).to.be.true
5157
})
5258

5359
it('should the prop msg have four tags', () => {
54-
expect(Object.keys(docJson['props']['msg']['tags']).length === 4).to.be.true
60+
expect(Object.keys(docGrid['props']['msg']['tags']).length === 4).to.be.true
5561
})
5662
})

0 commit comments

Comments
 (0)