2015-03-16 22:06:57 +00:00
|
|
|
var docs = require('react-docgen');
|
2015-02-12 22:43:41 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var slugify = require('../core/slugify');
|
2015-03-13 22:30:31 +00:00
|
|
|
var jsDocs = require('../jsdocs/jsdocs.js');
|
2015-02-12 22:43:41 +00:00
|
|
|
|
|
|
|
function getNameFromPath(filepath) {
|
|
|
|
var ext = null;
|
|
|
|
while (ext = path.extname(filepath)) {
|
|
|
|
filepath = path.basename(filepath, ext);
|
|
|
|
}
|
|
|
|
return filepath;
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:03:32 +00:00
|
|
|
function componentsToMarkdown(type, json, filepath, i) {
|
2015-02-12 22:43:41 +00:00
|
|
|
var componentName = getNameFromPath(filepath);
|
|
|
|
|
2015-03-05 05:03:24 +00:00
|
|
|
var docFilePath = '../docs/' + componentName + '.md';
|
|
|
|
if (fs.existsSync(docFilePath)) {
|
|
|
|
json.fullDescription = fs.readFileSync(docFilePath).toString();
|
|
|
|
}
|
2015-03-12 18:03:32 +00:00
|
|
|
json.type = type;
|
2015-03-05 05:03:24 +00:00
|
|
|
|
2015-02-12 22:43:41 +00:00
|
|
|
var res = [
|
|
|
|
'---',
|
|
|
|
'id: ' + slugify(componentName),
|
|
|
|
'title: ' + componentName,
|
2015-03-05 02:10:12 +00:00
|
|
|
'layout: autodocs',
|
2015-03-12 18:03:32 +00:00
|
|
|
'category: ' + type + 's',
|
2015-02-12 22:43:41 +00:00
|
|
|
'permalink: docs/' + slugify(componentName) + '.html',
|
2015-03-12 18:03:32 +00:00
|
|
|
all[i + 1] && ('next: ' + slugify(getNameFromPath(all[i + 1]))),
|
2015-02-12 22:43:41 +00:00
|
|
|
'---',
|
2015-03-05 02:10:12 +00:00
|
|
|
JSON.stringify(json, null, 2),
|
2015-02-12 22:43:41 +00:00
|
|
|
].filter(function(line) { return line; }).join('\n');
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
var components = [
|
2015-03-05 05:03:24 +00:00
|
|
|
'../Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js',
|
2015-03-10 20:55:54 +00:00
|
|
|
'../Libraries/Components/DatePicker/DatePickerIOS.ios.js',
|
2015-03-03 01:31:26 +00:00
|
|
|
'../Libraries/Image/Image.ios.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
'../Libraries/Components/ListView/ListView.js',
|
2015-03-13 22:30:31 +00:00
|
|
|
'../Libraries/Components/MapView/MapView.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
|
2015-03-13 22:30:31 +00:00
|
|
|
'../Libraries/Picker/PickerIOS.ios.js',
|
2015-03-09 18:49:58 +00:00
|
|
|
'../Libraries/Components/ScrollView/ScrollView.js',
|
2015-03-19 20:55:42 +00:00
|
|
|
'../Libraries/Components/SliderIOS/SliderIOS.js',
|
2015-03-10 20:55:54 +00:00
|
|
|
'../Libraries/Components/SwitchIOS/SwitchIOS.ios.js',
|
|
|
|
'../Libraries/Components/TabBarIOS/TabBarIOS.ios.js',
|
2015-03-03 01:31:26 +00:00
|
|
|
'../Libraries/Text/Text.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
'../Libraries/Components/TextInput/TextInput.ios.js',
|
|
|
|
'../Libraries/Components/Touchable/TouchableHighlight.js',
|
2015-03-05 05:03:24 +00:00
|
|
|
'../Libraries/Components/Touchable/TouchableOpacity.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
'../Libraries/Components/Touchable/TouchableWithoutFeedback.js',
|
2015-02-19 00:39:28 +00:00
|
|
|
'../Libraries/Components/View/View.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Components/WebView/WebView.ios.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
];
|
|
|
|
|
2015-03-10 20:55:54 +00:00
|
|
|
var apis = [
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Utilities/AlertIOS.js',
|
2015-03-12 18:03:32 +00:00
|
|
|
'../Libraries/Animation/Animation.js',
|
2015-03-13 22:30:31 +00:00
|
|
|
'../Libraries/AppRegistry/AppRegistry.js',
|
|
|
|
'../Libraries/AppState/AppState.js',
|
|
|
|
'../Libraries/AppStateIOS/AppStateIOS.ios.js',
|
|
|
|
'../Libraries/Storage/AsyncStorage.ios.js',
|
2015-03-12 18:03:32 +00:00
|
|
|
'../Libraries/CameraRoll/CameraRoll.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Interaction/InteractionManager.js',
|
2015-03-12 18:03:32 +00:00
|
|
|
'../Libraries/Animation/LayoutAnimation.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Network/NetInfo.js',
|
2015-03-12 18:03:32 +00:00
|
|
|
'../Libraries/Utilities/PixelRatio.js',
|
|
|
|
'../Libraries/Components/StatusBar/StatusBarIOS.ios.js',
|
|
|
|
'../Libraries/StyleSheet/StyleSheet.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Vibration/VibrationIOS.ios.js',
|
2015-03-10 20:55:54 +00:00
|
|
|
];
|
|
|
|
|
2015-03-12 18:03:32 +00:00
|
|
|
var all = components.concat(apis);
|
|
|
|
|
2015-02-12 22:43:41 +00:00
|
|
|
module.exports = function() {
|
2015-03-12 18:03:32 +00:00
|
|
|
var i = 0;
|
|
|
|
return [].concat(
|
|
|
|
components.map(function(filepath) {
|
|
|
|
var json = docs.parse(
|
|
|
|
fs.readFileSync(filepath),
|
|
|
|
function(node, recast) {
|
|
|
|
return docs.resolver.findExportedReactCreateClassCall(node, recast) ||
|
|
|
|
docs.resolver.findAllReactCreateClassCalls(node, recast)[0];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return componentsToMarkdown('component', json, filepath, i++);
|
|
|
|
}),
|
|
|
|
apis.map(function(filepath) {
|
|
|
|
try {
|
|
|
|
var json = jsDocs(fs.readFileSync(filepath).toString());
|
|
|
|
} catch(e) {
|
|
|
|
console.error('Cannot parse file', filepath);
|
|
|
|
var json = {};
|
|
|
|
}
|
|
|
|
return componentsToMarkdown('api', json, filepath, i++);
|
|
|
|
})
|
|
|
|
);
|
2015-02-12 22:43:41 +00:00
|
|
|
};
|