Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# vue-docgen-api
# vue-docgen-api (Fork)
[![npm](https://img.shields.io/npm/v/vue-docgen-api.svg)](https://www.npmjs.com/package/vue-docgen-api)

**This fork adds a `parseSource` method to parse plain sources instead of files only**

`vue-docgen-api` is a toolbox to help extracting information from [Vue][] components, and generate documentation from it.

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.
Expand All @@ -10,24 +12,22 @@ Use [babel][] and [jsdoc-api][] to compile the code and analyze the contents of
Install the module directly from npm:

```
npm install vue-docgen-api --save-dev
npm install git://github.com/Radiergummi/vue-docgen-api --save-dev
```

## API

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

```js
var vueDocs = require('vue-docgen-api');
var componentInfo = vueDocs.parse(filePath);
```
const vueDocs = require('vue-docgen-api');

### parse(filePath)

| Parameter | Type | Description |
| -------------- | ------ | --------------- |
| filePath | string | The file path |
// from file
const componentFileInfo = vueDocs.parseFile(filePath);

// from source
const componentSourceInfo = vueDocs.parseSource(sourceCode, filePath);
```

## Using JSDoc tags

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-docgen-api",
"version": "2.1.6",
"version": "2.2.6",
"description": "Toolbox to extract information from Vue component files for documentation generation purposes.",
"bugs": {
"url": "https://github.com/vue-styleguidist/vue-docgen-api/issues"
Expand Down
13 changes: 9 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as utils from './utils';
import parse from './parse';
import { parseFile, parseSource } from './parse';

function defaultParse(src) {
return parse(src);
function parseFile(path) {
return parseFile(path);
}

function parseSource(src, path) {
return parseSource(src, path);
}

export {
defaultParse as parse,
parseFile,
parseSource,
utils,
};

14 changes: 13 additions & 1 deletion src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import * as utils from './utils';
import stateDoc from './utils/stateDoc';

export default function parse(file) {
export const parseFile = function(file) {
const source = fs.readFileSync(file, { encoding: 'utf-8' });
if (source === '') {
throw new Error('The document is empty');
Expand All @@ -13,3 +13,15 @@ export default function parse(file) {
const vueDoc = utils.getVueDoc(stateDoc, component);
return vueDoc;
}

export const parseSource = function(source, path) {
if (source === '') {
throw new Error('The document is empty');
}

stateDoc.file = path;
stateDoc.saveComponent(source, path);
const component = utils.getSandbox(stateDoc.jscodeReqest, path).default;
const vueDoc = utils.getVueDoc(stateDoc, component);
return vueDoc;
}