react-native/website/server/extractDocs.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

var docs = require('../react-docgen');
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-03-03 01:31:26 +00:00
var json = docs.parse(
fs.readFileSync(filepath),
function(node, recast) {
2015-03-03 01:31:26 +00:00
return docs.resolver.findExportedReactCreateClassCall(node, recast) ||
docs.resolver.findAllReactCreateClassCalls(node, recast)[0];
}
2015-03-05 02:10:12 +00:00
);
var componentName = getNameFromPath(filepath);
var res = [
'---',
'id: ' + slugify(componentName),
'title: ' + componentName,
2015-03-05 02:10:12 +00:00
'layout: autodocs',
'category: Components',
'permalink: docs/' + slugify(componentName) + '.html',
components[i + 1] && ('next: ' + slugify(getNameFromPath(components[i + 1]))),
'---',
2015-03-05 02:10:12 +00:00
JSON.stringify(json, null, 2),
].filter(function(line) { return line; }).join('\n');
return res;
}
var components = [
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
2015-03-03 01:31:26 +00:00
'../Libraries/Image/Image.ios.js',
'../Libraries/Components/ListView/ListView.js',
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
'../Libraries/Components/ScrollView/ScrollView.ios.js',
2015-03-03 01:31:26 +00:00
'../Libraries/Text/Text.js',
2015-03-05 02:10:12 +00:00
'../Libraries/Image/Image.ios.js',
'../Libraries/Components/TextInput/TextInput.ios.js',
'../Libraries/Components/Touchable/TouchableHighlight.js',
'../Libraries/Components/Touchable/TouchableWithoutFeedback.js',
'../Libraries/Components/View/View.js',
];
module.exports = function() {
return components.map(docsToMarkdown);
};