This repository was archived by the owner on Mar 8, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +33
-16
lines changed Expand file tree Collapse file tree 4 files changed +33
-16
lines changed Original file line number Diff line number Diff line change 1
- # vue-docgen-api
1
+ # vue-docgen-api (Fork)
2
2
[ ![ npm] ( https://img.shields.io/npm/v/vue-docgen-api.svg )] ( https://www.npmjs.com/package/vue-docgen-api )
3
3
4
+ ** This fork adds a ` parseSource ` method to parse plain sources instead of files only**
5
+
4
6
` vue-docgen-api ` is a toolbox to help extracting information from [ Vue] [ ] components, and generate documentation from it.
5
7
6
8
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
10
12
Install the module directly from npm:
11
13
12
14
```
13
- npm install vue-docgen-api --save-dev
15
+ npm install git://github.com/Radiergummi/ vue-docgen-api --save-dev
14
16
```
15
17
16
18
## API
17
19
18
20
The tool can be used programmatically to extract component information and customize the extraction process:
19
21
20
22
``` js
21
- var vueDocs = require (' vue-docgen-api' );
22
- var componentInfo = vueDocs .parse (filePath);
23
- ```
23
+ const vueDocs = require (' vue-docgen-api' );
24
24
25
- ### parse(filePath)
26
-
27
- | Parameter | Type | Description |
28
- | -------------- | ------ | --------------- |
29
- | filePath | string | The file path |
25
+ // from file
26
+ const componentFileInfo = vueDocs .parseFile (filePath);
30
27
28
+ // from source
29
+ const componentSourceInfo = vueDocs .parseSource (sourceCode, filePath);
30
+ ```
31
31
32
32
## Using JSDoc tags
33
33
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " vue-docgen-api" ,
3
- "version" : " 2.1 .6" ,
3
+ "version" : " 2.2 .6" ,
4
4
"description" : " Toolbox to extract information from Vue component files for documentation generation purposes." ,
5
5
"bugs" : {
6
6
"url" : " https://github.com/vue-styleguidist/vue-docgen-api/issues"
Original file line number Diff line number Diff line change 1
1
import * as utils from './utils' ;
2
- import parse from './parse' ;
2
+ import { parseFile , parseSource } from './parse' ;
3
3
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 ) ;
6
10
}
7
11
8
12
export {
9
- defaultParse as parse ,
13
+ parseFile ,
14
+ parseSource ,
10
15
utils ,
11
16
} ;
12
17
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import fs from 'fs';
2
2
import * as utils from './utils' ;
3
3
import stateDoc from './utils/stateDoc' ;
4
4
5
- export default function parse ( file ) {
5
+ export const parseFile = function ( file ) {
6
6
const source = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
7
7
if ( source === '' ) {
8
8
throw new Error ( 'The document is empty' ) ;
@@ -13,3 +13,15 @@ export default function parse(file) {
13
13
const vueDoc = utils . getVueDoc ( stateDoc , component ) ;
14
14
return vueDoc ;
15
15
}
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
+ }
You can’t perform that action at this time.
0 commit comments