Skip to content

Commit

Permalink
feat: Vue Support
Browse files Browse the repository at this point in the history
Thanks to @batje, documentation.js now supports Vue! .vue files are parsed for their JavaScript contents by default.
  • Loading branch information
tmcw authored Apr 20, 2018
1 parent 542031e commit f60d90c
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![Coverage Status](https://coveralls.io/repos/github/documentationjs/documentation/badge.svg?branch=master)](https://coveralls.io/github/documentationjs/documentation?branch=master)
[![Inline docs](http://inch-ci.org/github/documentationjs/documentation.svg?branch=master&style=flat-square)](http://inch-ci.org/github/documentationjs/documentation)

* Supports modern JavaScript: ES5, ES2017, JSX, and [Flow](http://flowtype.org/) type annotations.
* Supports modern JavaScript: ES5, ES2017, JSX, Vue and [Flow](http://flowtype.org/) type annotations.
* Infers parameters, types, membership, and more. Write less documentation: let the computer write it for you.
* Integrates with GitHub to link directly from documentation to the code it refers to.
* Customizable output: HTML, JSON, Markdown, and more
Expand Down
277 changes: 277 additions & 0 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,282 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Vue file 1`] = `
Array [
Object {
"augments": Array [],
"context": Object {
"loc": SourceLocation {
"end": Position {
"column": 1,
"line": 19,
},
"start": Position {
"column": 0,
"line": 7,
},
},
},
"description": Object {
"children": Array [
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 29,
"line": 1,
"offset": 28,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "This Vue Component is a test",
},
],
"position": Position {
"end": Object {
"column": 29,
"line": 1,
"offset": 28,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 29,
"line": 1,
"offset": 28,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"errors": Array [],
"examples": Array [],
"loc": SourceLocation {
"end": Position {
"column": 3,
"line": 6,
},
"start": Position {
"column": 0,
"line": 3,
},
},
"members": Object {
"events": Array [],
"global": Array [],
"inner": Array [],
"instance": Array [],
"static": Array [],
},
"name": "vue.input",
"namespace": "vue.input",
"params": Array [],
"path": Array [
Object {
"kind": undefined,
"name": "vue.input",
},
],
"properties": Array [],
"returns": Array [
Object {
"description": Object {
"children": Array [
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "vue-tested component",
},
],
"position": Position {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 21,
"line": 1,
"offset": 20,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"title": "returns",
"type": Object {
"name": "vue-tested",
"type": "NameExpression",
},
},
],
"sees": Array [],
"tags": Array [
Object {
"description": "vue-tested component",
"lineNumber": 2,
"title": "returns",
"type": Object {
"name": "vue-tested",
"type": "NameExpression",
},
},
],
"throws": Array [],
"todos": Array [],
},
Object {
"augments": Array [],
"context": Object {
"loc": SourceLocation {
"end": Position {
"column": 3,
"line": 17,
},
"start": Position {
"column": 2,
"line": 14,
},
},
},
"description": Object {
"children": Array [
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 17,
"line": 1,
"offset": 16,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "This is a number",
},
],
"position": Position {
"end": Object {
"column": 17,
"line": 1,
"offset": 16,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 17,
"line": 1,
"offset": 16,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"errors": Array [],
"examples": Array [],
"loc": SourceLocation {
"end": Position {
"column": 5,
"line": 13,
},
"start": Position {
"column": 2,
"line": 11,
},
},
"members": Object {
"events": Array [],
"global": Array [],
"inner": Array [],
"instance": Array [],
"static": Array [],
},
"name": "myNumber",
"namespace": "myNumber",
"params": Array [],
"path": Array [
Object {
"kind": undefined,
"name": "myNumber",
},
],
"properties": Array [],
"returns": Array [],
"sees": Array [],
"tags": Array [],
"throws": Array [],
"todos": Array [],
},
]
`;

exports[`config 1`] = `
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

Expand Down
28 changes: 28 additions & 0 deletions __tests__/fixture/vue.input.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div>not relevant</div>
</template>

<script>
/**
* This Vue Component is a test
* @returns {vue-tested} vue-tested component
*/
export default {
props: {
/**
* This is a number
*/
myNumber: {
default: 42,
type: Number
}
}
}
</script>

<style>
</style>
7 changes: 7 additions & 0 deletions __tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,10 @@ test('.lint with bad input', async function() {
expect(err).toBeTruthy();
}
});

test('Vue file', async function() {
await pify(chdir)(__dirname);
const data = await documentation.build('__tests__/fixture/vue.input.vue', {});
normalize(data);
expect(data).toMatchSnapshot();
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"vfile-sort": "^2.1.0",
"vinyl": "^2.1.0",
"vinyl-fs": "^3.0.2",
"vue-template-compiler": "^2.5.16",
"yargs": "^9.0.1"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const sort = require('./sort');
const nest = require('./nest');
const filterAccess = require('./filter_access');
const dependency = require('./input/dependency');
const shallow = require('./input/shallow');
const parseJavaScript = require('./parsers/javascript');
const parseVueScript = require('./parsers/vue');
const github = require('./github');
const hierarchy = require('./hierarchy');
const inferName = require('./infer/name');
Expand Down Expand Up @@ -103,6 +105,9 @@ function buildInternal(inputsAndConfig) {
sourceFile.source = fs.readFileSync(sourceFile.file, 'utf8');
}

if (path.extname(sourceFile.file) === '.vue') {

This comment has been minimized.

Copy link
@bodia-uz

bodia-uz Apr 23, 2018

Contributor

We use documentation with source option, not with file.
This commit breaks this ability.

This comment has been minimized.

Copy link
@batje

batje Apr 23, 2018

Contributor

Is there anything in .file? So, would the following fix this?

if ((sourceFile.file) && (path.extname(sourceFile.file) === '.vue')) {

Sorry, not sure how to reproduce this myself.

This comment has been minimized.

Copy link
@bodia-uz

bodia-uz Apr 23, 2018

Contributor

file is undefined.
Here is the issue with usage example:
#1057

return parseVueScript(sourceFile, config).map(buildPipeline);
}
return parseJavaScript(sourceFile, config).map(buildPipeline);
}).filter(Boolean);

Expand Down
3 changes: 2 additions & 1 deletion src/merge_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ function mergeConfig(config: Object): Promise<DocumentationConfig> {
'js',
'jsx',
'es5',
'es6'
'es6',
'vue'
]);

return mergeConfigFile(config).then(mergePackage);
Expand Down
19 changes: 19 additions & 0 deletions src/parsers/vue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* @flow */

const parseJavaScript = require('./javascript');
const vuecompiler = require('vue-template-compiler');

/**
* Receives a module-dep item,
* reads the file, parses the VueScript, and parses the JSDoc.
*
* @param {Object} data a chunk of data provided by module-deps
* @param {Object} config config
* @returns {Array<Object>} an array of parsed comments
*/
function parseVueScript(data: Object, config: DocumentationConfig) {
data.source = vuecompiler.parseComponent(data.source).script.content;
return parseJavaScript(data, config);
}

module.exports = parseVueScript;
Loading

0 comments on commit f60d90c

Please sign in to comment.