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

Commit 8712d17

Browse files
committed
Updated
1 parent fb2bd4b commit 8712d17

File tree

10 files changed

+60
-12
lines changed

10 files changed

+60
-12
lines changed

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": "2.0.0",
3+
"version": "2.0.1",
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
@@ -9,6 +9,6 @@ export default function parse(file, webpackConfig) {
99
}
1010
stateDoc.file = file;
1111
const component = utils.getComponent(source, file, webpackConfig);
12-
const vueDoc = utils.getVueDoc(stateDoc.docComponent, component);
12+
const vueDoc = utils.getVueDoc(stateDoc.getDoc(), component);
1313
return vueDoc;
1414
}

src/utils/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ export {default as getComponentModuleJSCode} from './getComponentModuleJSCode';
22
export {default as getComponent} from './getComponent';
33
export {default as getDocFile} from './getDocFile';
44
export {default as getVueDoc} from './getVueDoc';
5-
export {default as getSandbox} from './getSandbox';
65
export {default as parser} from './parser';
7-
export {default as sandbox} from './sandbox';

src/utils/optionsWebpack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
resolve: {
77
modulesDirectories: ['node_modules', 'bower_components'],
88
},
9+
watch: true,
910
module: {
1011
loaders,
1112
},

src/utils/processMethods.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default function processMethods(docFile, component) {
1313
});
1414
}
1515
if (methods) {
16+
docFile.reverse()
1617
Object.keys(methods).forEach(methodName => {
1718
const docPart = docFile.reverse().filter( comment => {
1819
return (comment.longname.indexOf('methods.' + methodName) > -1)

src/utils/processProps.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function processProps(docFile, component) {
1818
listDocProps[propName] = getProp();
1919
});
2020
} else {
21+
docFile.reverse()
2122
Object.keys(props).forEach( key => {
2223
const propName = key;
2324
const docPart = docFile.reverse().filter( comment => {

src/utils/stateDoc.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import getDocFile from './getDocFile';
44
class stateDoc {
55
constructor(){
66
this.file = '';
7-
this.docComponent = false
7+
this.docComponent = {};
8+
this.sourceComponent = '';
89
this.docMixins = [];
910
}
1011

@@ -13,7 +14,7 @@ class stateDoc {
1314
}
1415

1516
saveComponent(source, file){
16-
if (!this.docComponent) {
17+
if (this.isMainComponent(file) && this.sourceComponent !== source) {
1718
const jscodeReqest = getComponentModuleJSCode(source, file);
1819
const doc = getDocFile(jscodeReqest, file);
1920
this.docComponent = doc;
@@ -26,6 +27,14 @@ class stateDoc {
2627
});
2728
}
2829

30+
getDoc(){
31+
let docMixins = [].concat.apply([], this.docMixins)
32+
.filter(function (docPart) {
33+
return docPart.kind !== 'package';
34+
});
35+
return docMixins.concat(this.docComponent);
36+
}
37+
2938
saveMixin(source, file) {
3039
let doc = getDocFile(source, file);
3140
if (this.isMixin(doc)) {
@@ -39,10 +48,21 @@ class stateDoc {
3948
return docPart;
4049
}).filter(docPart => {
4150
return docPart.longname !== 'module.exports'
42-
}).filter(docPart => {
43-
return docPart.kind !== 'package'
4451
})
45-
this.docComponent = this.docComponent.concat(doc);
52+
let index;
53+
this.docMixins.forEach((docMixin, id) => {
54+
const packages = docMixin.filter(function (docPart) {
55+
return docPart.kind === 'package';
56+
})[0];
57+
if (packages && packages.files[0] === file) {
58+
index = id;
59+
}
60+
})
61+
if (index) {
62+
this.docMixins[index] = doc;
63+
} else {
64+
this.docMixins.push(doc)
65+
}
4666
}
4767
}
4868
}

tests/components/button/Button.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
import genericMixin from './genericMixin';
99
import colorMixin from './colorMixin';
1010
11+
/**
12+
* This is an example of creating a reusable grid component and using it with external data.
13+
* @author [Rafael](https://github.com/rafaesc92)
14+
* @version 1.0.5
15+
*/
1116
export default {
1217
name: 'buttonComponent',
1318
mixins: [genericMixin, colorMixin],

tests/components/button/colorMixin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ module.exports = {
1010
type: String,
1111
default: '#333'
1212
},
13+
/**
14+
* Error
15+
*/
16+
size: {
17+
default: 'example'
18+
}
1319
}
1420
}

tests/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ describe('tests grid', () => {
2929
expect(typeof docGrid['description'] !== 'undefined').to.be.true
3030
})
3131

32+
it('should the component have msg prop default equal this is a secret', () => {
33+
expect(docGrid['props']['msg']['defaultValue']['value']).to.equal('"this is a secret"')
34+
})
35+
3236
it('should have methods', () => {
3337
expect(typeof docGrid['methods'] !== 'undefined').to.be.true
3438
})
@@ -56,7 +60,7 @@ describe('tests grid', () => {
5660

5761
describe('tests button', () => {
5862
docButton = api.parse(button);
59-
console.log(JSON.stringify(docGrid, null, 2));
63+
console.log(JSON.stringify(docButton, null, 2));
6064

6165
it('should return an object', () => {
6266
expect(docButton).to.be.an('object')
@@ -70,8 +74,20 @@ describe('tests button', () => {
7074
expect(docButton.description).to.equal('This is an example of creating a reusable grid component and using it with external data.');
7175
})
7276

73-
it('should the component have three tags', () => {
74-
expect(Object.keys(docButton['tags']).length).to.equal(3)
77+
it('should the component have two tags', () => {
78+
expect(Object.keys(docButton['tags']).length).to.equal(2)
79+
})
80+
81+
it('should the component have four props', () => {
82+
expect(Object.keys(docButton['props']).length).to.equal(4)
83+
})
84+
85+
it('should the component have size prop default equal normal', () => {
86+
expect(docButton['props']['size']['defaultValue']['value']).to.equal('"normal"')
87+
})
88+
89+
it('should the component have size prop description equal The size of the button\n`small, normal, large`', () => {
90+
expect(docButton['props']['size']['description']).to.equal('The size of the button\n`small, normal, large`')
7591
})
7692

7793
it('should the component have authors', () => {

0 commit comments

Comments
 (0)