2015-02-12 22:43:41 +00:00
|
|
|
var docs = require('../react-docgen');
|
2015-02-19 00:39:28 +00:00
|
|
|
var findExportedReactCreateClassCall = require(
|
|
|
|
'../react-docgen/dist/strategies/findExportedReactCreateClassCall'
|
|
|
|
);
|
|
|
|
var findAllReactCreateClassCalls = require(
|
|
|
|
'../react-docgen/dist/strategies/findAllReactCreateClassCalls'
|
|
|
|
);
|
2015-02-12 22:43:41 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var slugify = require('../core/slugify');
|
|
|
|
|
|
|
|
function getNameFromPath(filepath) {
|
|
|
|
var ext = null;
|
|
|
|
while (ext = path.extname(filepath)) {
|
|
|
|
filepath = path.basename(filepath, ext);
|
|
|
|
}
|
|
|
|
return filepath;
|
|
|
|
}
|
|
|
|
|
|
|
|
function docsToMarkdown(filepath, i) {
|
2015-02-19 00:39:28 +00:00
|
|
|
var json = docs.parseSource(
|
|
|
|
fs.readFileSync(filepath),
|
|
|
|
function(node, recast) {
|
|
|
|
return findExportedReactCreateClassCall(node, recast) ||
|
|
|
|
findAllReactCreateClassCalls(node, recast)[0];
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2015-02-12 22:43:41 +00:00
|
|
|
var componentName = getNameFromPath(filepath);
|
|
|
|
|
|
|
|
var res = [
|
|
|
|
'---',
|
|
|
|
'id: ' + slugify(componentName),
|
|
|
|
'title: ' + componentName,
|
|
|
|
'layout: docs',
|
|
|
|
'category: Components',
|
|
|
|
'permalink: docs/' + slugify(componentName) + '.html',
|
|
|
|
components[i + 1] && ('next: ' + slugify(getNameFromPath(components[i + 1]))),
|
|
|
|
'---',
|
|
|
|
' ',
|
|
|
|
json.description,
|
|
|
|
' ',
|
|
|
|
'# Props',
|
|
|
|
'```',
|
|
|
|
JSON.stringify(json.props, null, 2),
|
|
|
|
'```',
|
|
|
|
].filter(function(line) { return line; }).join('\n');
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
var components = [
|
|
|
|
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
|
|
|
|
'../Libraries/Components/Image/Image.ios.js',
|
|
|
|
'../Libraries/Components/ListView/ListView.js',
|
|
|
|
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
|
|
|
|
'../Libraries/Components/ScrollView/ScrollView.ios.js',
|
|
|
|
'../Libraries/Components/Text/Text.js',
|
|
|
|
'../Libraries/Components/TextInput/TextInput.ios.js',
|
|
|
|
'../Libraries/Components/Touchable/TouchableHighlight.js',
|
|
|
|
'../Libraries/Components/Touchable/TouchableWithoutFeedback.js',
|
2015-02-19 00:39:28 +00:00
|
|
|
'../Libraries/Components/View/View.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
module.exports = function() {
|
|
|
|
return components.map(docsToMarkdown);
|
|
|
|
};
|