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

Commit 078f8ba

Browse files
committed
Merge branch 'master' of https://github.com/Radiergummi/vue-docgen-api into Radiergummi-master
2 parents 9d207e9 + e0eec07 commit 078f8ba

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# vue-docgen-api
1+
# vue-docgen-api (Fork)
22
[![npm](https://img.shields.io/npm/v/vue-docgen-api.svg)](https://www.npmjs.com/package/vue-docgen-api)
33

4+
**This fork adds a `parseSource` method to parse plain sources instead of files only**
5+
46
`vue-docgen-api` is a toolbox to help extracting information from [Vue][] components, and generate documentation from it.
57

68
Use [babel][] and [jsdoc-api][] to compile the code and analyze the contents of the component extracting methods and props. The output is a JavaScript object.
@@ -10,24 +12,22 @@ Use [babel][] and [jsdoc-api][] to compile the code and analyze the contents of
1012
Install the module directly from npm:
1113

1214
```
13-
npm install vue-docgen-api --save-dev
15+
npm install git://github.com/Radiergummi/vue-docgen-api --save-dev
1416
```
1517

1618
## API
1719

1820
The tool can be used programmatically to extract component information and customize the extraction process:
1921

2022
```js
21-
var vueDocs = require('vue-docgen-api');
22-
var componentInfo = vueDocs.parse(filePath);
23-
```
23+
const vueDocs = require('vue-docgen-api');
2424

25-
### parse(filePath)
26-
27-
| Parameter | Type | Description |
28-
| -------------- | ------ | --------------- |
29-
| filePath | string | The file path |
25+
// from file
26+
const componentFileInfo = vueDocs.parseFile(filePath);
3027

28+
// from source
29+
const componentSourceInfo = vueDocs.parseSource(sourceCode, filePath);
30+
```
3131

3232
## Using JSDoc tags
3333

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.1.6",
3+
"version": "2.2.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/main.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import * as utils from './utils';
2-
import parse from './parse';
2+
import { parseFile, parseSource } from './parse';
33

4-
function defaultParse(src) {
5-
return parse(src);
4+
function parseFile(path) {
5+
return parseFile(path);
6+
}
7+
8+
function parseSource(src, path) {
9+
return parseSource(src, path);
610
}
711

812
export {
9-
defaultParse as parse,
13+
parseFile,
14+
parseSource,
1015
utils,
1116
};
1217

src/parse.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import * as utils from './utils';
33
import stateDoc from './utils/stateDoc';
44

5-
export default function parse(file) {
5+
export const parseFile = function(file) {
66
const source = fs.readFileSync(file, { encoding: 'utf-8' });
77
if (source === '') {
88
throw new Error('The document is empty');
@@ -13,3 +13,15 @@ export default function parse(file) {
1313
const vueDoc = utils.getVueDoc(stateDoc, component);
1414
return vueDoc;
1515
}
16+
17+
export const parseSource = function(source, path) {
18+
if (source === '') {
19+
throw new Error('The document is empty');
20+
}
21+
22+
stateDoc.file = path;
23+
stateDoc.saveComponent(source, path);
24+
const component = utils.getSandbox(stateDoc.jscodeReqest, path).default;
25+
const vueDoc = utils.getVueDoc(stateDoc, component);
26+
return vueDoc;
27+
}

0 commit comments

Comments
 (0)