Skip to content

Commit 6db6cb5

Browse files
committed
feat(typescript): add working typescript example
update all dependencies make markdown rendering faster
1 parent 34d2538 commit 6db6cb5

File tree

12 files changed

+1611
-1066
lines changed

12 files changed

+1611
-1066
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ Use `headline` to add a custom `h1` title.
135135

136136
[More information](https://vuepress.vuejs.org/guide/markdown.html#front-matter)
137137

138+
## Typescript
139+
140+
To use typescript, you have to install these dev-dependencies:
141+
142+
```bash
143+
yarn add -D typescript jsdoc-babel @babel/cli @babel/core @babel/preset-env @babel/preset-typescript jsdoc-to-markdown
144+
```
145+
146+
Next, you have to add a `jsdoc.json` to your project with some settings and add it with the `-c` parameter.
147+
You can find a full working example with all settings inside the `./example` folder.
148+
The example shows also how to use babel-`plugins`.
149+
138150
## Example
139151

140152
The `./example` folder includes a full working vuepress-jsdoc example.

cmds/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async function generate(argv) {
109109
try {
110110
// render file
111111
mdFileData = await jsdoc2md.render({
112-
source: fileData,
112+
files: [`${folder}/${file}`],
113113
configure: configPath,
114114
partial: [
115115
path.resolve(__filename, '../../template/header.hbs'),

example/documentation/code/Icon.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Icon
3+
---
4+
5+
# Icon
6+
7+
## Constants
8+
9+
<dl>
10+
<dt><a href="#ButtonTextWrapper">ButtonTextWrapper</a></dt>
11+
<dd><p>This is the ButtonTextWrapper</p>
12+
</dd>
13+
</dl>
14+
15+
## Functions
16+
17+
<dl>
18+
<dt><a href="#Button">Button(props)</a></dt>
19+
<dd><p>Test</p>
20+
</dd>
21+
</dl>
22+
23+
<a name="ButtonTextWrapper"></a>
24+
25+
## ButtonTextWrapper
26+
This is the ButtonTextWrapper
27+
28+
**Kind**: global constant
29+
<a name="Button"></a>
30+
31+
## Button(props)
32+
Test
33+
34+
**Kind**: global function
35+
36+
| Param |
37+
| --- |
38+
| props |
39+

example/documentation/code/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
exports.fileTree = [
2+
{ name: 'Icon', path: '/Icon', fullPath: './documentation/code/Icon' },
23
{ name: 'class-constructor', path: '/class-constructor', fullPath: './documentation/code/class-constructor' },
34
{ name: 'class', path: '/class', fullPath: './documentation/code/class' },
45
{
@@ -28,7 +29,7 @@ exports.sidebarTree = (title = 'Mainpage') => ({
2829
{
2930
title: 'API',
3031
collapsable: false,
31-
children: [['', '' + title + ''], 'class-constructor', 'class', 'methods', 'objects', 'test']
32+
children: [['', '' + title + ''], 'Icon', 'class-constructor', 'class', 'methods', 'objects', 'test']
3233
},
3334
{ title: 'lib', collapsable: false, children: ['lib/dmd-options', 'lib/jsdoc-to-markdown'] },
3435
{ title: 'subfolder', collapsable: false, children: ['subfolder/subfolder.1/variables', 'subfolder/variables'] }

example/documentation/code/methods.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: A normal ES6 Methodf jdhsfkj dsfhdskjf dksjfhdks j
2+
title: A normal ES6 Method
33
headline: Custom Title!
44
---
55

example/jsdoc.json

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
{
2-
"plugins": [],
3-
"recurseDepth": 10,
4-
"source": {
5-
"includePattern": ".+\\.j(doc|x)?$",
6-
"excludePattern": "(^|\\/|\\\\)_"
7-
},
8-
"sourceType": "module",
9-
"tags": {
10-
"allowUnknownTags": true,
11-
"dictionaries": ["jsdoc", "closure"]
2+
"plugins": ["node_modules/jsdoc-babel"],
3+
"babel": {
4+
"extensions": ["ts", "tsx"],
5+
"ignore": ["**/*.(test|spec).ts"],
6+
"babelrc": false,
7+
"presets": [
8+
[
9+
"@babel/preset-env",
10+
{
11+
"targets": { "node": true }
12+
}
13+
],
14+
"@babel/preset-typescript"
15+
],
16+
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/proposal-object-rest-spread"]
1217
},
1318
"templates": {
1419
"cleverLinks": false,
1520
"monospaceLinks": false
21+
},
22+
"recurseDepth": 10,
23+
"source": {
24+
"includePattern": ".+\\.(js|ts)(doc|x)?$",
25+
"excludePattern": ".+\\.(test|spec).ts"
1626
}
1727
}

example/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"docs": "../bin/vuepress-jsdoc.js --source=./src --dist=./documentation --title=API --exclude=*.test.js --partials=./partials/*.hbs",
7+
"docs": "../bin/vuepress-jsdoc.js -c ./jsdoc.json --source=./src --dist=./documentation --title=API --exclude=*.test.js --partials=./partials/*.hbs",
88
"dev": "vuepress dev documentation",
99
"build": "vuepress build documentation"
1010
},
1111
"keywords": [],
1212
"author": "",
1313
"license": "ISC",
1414
"dependencies": {
15-
"vuepress": "^1.3.0"
15+
"vuepress": "^1.4.0"
16+
},
17+
"devDependencies": {
18+
"@babel/cli": "^7.8.4",
19+
"@babel/core": "^7.9.0",
20+
"@babel/plugin-proposal-class-properties": "^7.8.3",
21+
"@babel/preset-env": "^7.9.5",
22+
"@babel/preset-typescript": "^7.9.0",
23+
"jsdoc-babel": "^0.5.0",
24+
"jsdoc-to-markdown": "^5.0.3",
25+
"typescript": "^3.8.3"
1626
}
1727
}

example/src/Icon.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { FunctionComponent } from 'react';
2+
import styled from 'styled-components/native';
3+
4+
/**
5+
* This is the ButtonTextWrapper
6+
*/
7+
const ButtonTextWrapper = styled.View`
8+
height: 40px;
9+
width: 300px;
10+
`;
11+
12+
/**
13+
* Props interface
14+
*/
15+
interface Props {
16+
text: string;
17+
}
18+
19+
/**
20+
* Test
21+
* @param props
22+
*/
23+
const Button: FunctionComponent<Props> = props => {
24+
return <ButtonTextWrapper>{props.text}</ButtonTextWrapper>;
25+
};
26+
27+
export default Icon;

example/src/methods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @vuepress
33
* ---
4-
* title: A normal ES6 Methodf jdhsfkj dsfhdskjf dksjfhdks j
4+
* title: A normal ES6 Method
55
* headline: Custom Title!
66
* ---
77
*/

0 commit comments

Comments
 (0)