Skip to content

Commit ecc29aa

Browse files
committed
Adds modified react-docgen scripts and md docs
1 parent caec9e3 commit ecc29aa

File tree

5 files changed

+255
-0
lines changed

5 files changed

+255
-0
lines changed

docs/components/Link.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
`Link` (component)
2+
==================
3+
4+
5+
6+
Props
7+
-----
8+
9+
### `linkData` (required)
10+
11+
type: `object`
12+
13+
14+
### `orientation` (required)
15+
16+
type: `enum('horizontal'|'vertical')`
17+
18+
19+
### `pathFunc` (required)
20+
21+
type: `enum('diagonal'|'elbow')`
22+

docs/components/Node.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
`Node` (component)
2+
==================
3+
4+
5+
6+
Props
7+
-----
8+
9+
### `circleRadius`
10+
11+
type: `number`
12+
defaultValue: `10`
13+
14+
15+
### `circleStyle`
16+
17+
type: `object`
18+
defaultValue: `{
19+
stroke: '#000',
20+
strokeWidth: 2,
21+
fill: 'grey',
22+
}`
23+
24+
25+
### `leafCircleStyle`
26+
27+
type: `object`
28+
defaultValue: `{
29+
stroke: '#000',
30+
strokeWidth: 2,
31+
fill: 'transparent',
32+
}`
33+
34+
35+
### `nodeData` (required)
36+
37+
type: `object`
38+
39+
40+
### `onClick`
41+
42+
type: `func`
43+
44+
45+
### `orientation` (required)
46+
47+
type: `enum('horizontal'|'vertical')`
48+
49+
50+
### `primaryLabel`
51+
52+
type: `string`
53+
54+
55+
### `primaryLabelStyle`
56+
57+
type: `object`
58+
59+
60+
### `secondaryLabels`
61+
62+
type: `object`
63+
64+
65+
### `secondaryLabelsStyle`
66+
67+
type: `object`
68+
69+
70+
### `textAnchor`
71+
72+
type: `string`
73+

docs/components/Tree.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
`Tree` (component)
2+
==================
3+
4+
5+
6+
Props
7+
-----
8+
9+
### `collapsible`
10+
11+
type: `bool`
12+
defaultValue: `true`
13+
14+
15+
### `data` (required)
16+
17+
type: `array`
18+
19+
20+
### `initialDepth`
21+
22+
type: `number`
23+
defaultValue: `undefined`
24+
25+
26+
### `orientation`
27+
28+
type: `enum('horizontal'|'vertical')`
29+
defaultValue: `'horizontal'`
30+
31+
32+
### `pathFunc`
33+
34+
type: `enum('diagonal'|'elbow')`
35+
defaultValue: `'diagonal'`
36+
37+
38+
### `translate`
39+
40+
type: `shape[object Object]`
41+
defaultValue: `{ x: 0, y: 0 }`
42+

scripts/buildDocs.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* This example script expects a JSON blob generated by react-docgen as input,
5+
* e.g. react-docgen components/* | buildDocs.sh
6+
*/
7+
8+
var fs = require('fs');
9+
var generateMarkdown = require('./generateMarkdown');
10+
var path = require('path');
11+
12+
var json = '';
13+
process.stdin.setEncoding('utf8');
14+
process.stdin.on('readable', function() {
15+
var chunk = process.stdin.read();
16+
if (chunk !== null) {
17+
json += chunk;
18+
}
19+
});
20+
21+
process.stdin.on('end', function() {
22+
buildDocs(JSON.parse(json));
23+
});
24+
25+
function buildDocs(api) {
26+
// api is an object keyed by filepath. We use the file name as component name.
27+
var i = 0;
28+
for (var filepath in api) {
29+
console.log(filepath)
30+
var targetDir = 'docs/components/';
31+
var name = getComponentName(filepath);
32+
var markdown = generateMarkdown(name, api[filepath]);
33+
fs.writeFileSync(targetDir + name + '.md', markdown);
34+
process.stdout.write(filepath + ' -> ' + targetDir + name + '.md\n');
35+
i++;
36+
}
37+
}
38+
39+
function getComponentName(filepath) {
40+
var name = path.dirname(filepath).split(path.sep).pop();
41+
return name;
42+
}

scripts/generateMarkdown.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
11+
function stringOfLength(string, length) {
12+
let newString = '';
13+
for (let i = 0; i < length; i++) {
14+
newString += string;
15+
}
16+
return newString;
17+
}
18+
19+
function generateTitle(name) {
20+
const title = `\`${name}\` (component)`;
21+
return `${title}\n${stringOfLength('=', title.length)}\n`;
22+
}
23+
24+
function generateDesciption(description) {
25+
return `${description}\n`;
26+
}
27+
28+
function generatePropType(type) {
29+
let values;
30+
if (Array.isArray(type.value)) {
31+
values = `(${
32+
type.value.map((typeValue) => typeValue.name || typeValue.value).join('|')
33+
})`;
34+
} else {
35+
values = type.value;
36+
}
37+
38+
return `type: \`${type.name}${values || ''}\`\n`;
39+
}
40+
41+
function generatePropDefaultValue(value) {
42+
return `defaultValue: \`${value.value}\`\n`;
43+
}
44+
45+
function generateProp(propName, prop) {
46+
return (
47+
`### \`${propName}\`${prop.required ? ' (required)' : ''}\n` +
48+
`\n${
49+
prop.description ? `${prop.description}\n\n` : ''
50+
}${prop.type ? generatePropType(prop.type) : ''
51+
}${prop.defaultValue ? generatePropDefaultValue(prop.defaultValue) : ''
52+
}\n`
53+
);
54+
}
55+
56+
function generateProps(props) {
57+
const title = 'Props';
58+
59+
return (
60+
`${title}\n${
61+
stringOfLength('-', title.length)}\n` +
62+
`\n${
63+
Object.keys(props).sort().map((propName) => generateProp(propName, props[propName])).join('\n')}`
64+
);
65+
}
66+
67+
function generateMarkdown(name, reactAPI) {
68+
const markdownString =
69+
`${generateTitle(name)}\n${
70+
generateDesciption(reactAPI.description)}\n${
71+
generateProps(reactAPI.props)}`;
72+
73+
return markdownString;
74+
}
75+
76+
module.exports = generateMarkdown;

0 commit comments

Comments
 (0)