2015-03-23 17:55:49 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
'use strict';
|
2015-02-12 22:43:41 +00:00
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const docgen = require('react-docgen');
|
|
|
|
const docgenHelpers = require('./docgenHelpers');
|
|
|
|
const fs = require('fs');
|
|
|
|
const jsDocs = require('../jsdocs/jsdocs.js');
|
|
|
|
const path = require('path');
|
|
|
|
const slugify = require('../core/slugify');
|
2016-06-21 21:22:44 +00:00
|
|
|
const babel = require('babel-core');
|
|
|
|
const jsdocApi = require('jsdoc-api');
|
|
|
|
const deepAssign = require('deep-assign');
|
2016-04-26 20:18:13 +00:00
|
|
|
|
|
|
|
const ANDROID_SUFFIX = 'android';
|
|
|
|
const CROSS_SUFFIX = 'cross';
|
|
|
|
const IOS_SUFFIX = 'ios';
|
2015-09-14 14:35:58 +00:00
|
|
|
|
|
|
|
function endsWith(str, suffix) {
|
|
|
|
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
|
|
}
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
function removeExtName(filepath) {
|
|
|
|
let ext = path.extname(filepath);
|
|
|
|
while (ext) {
|
2015-02-12 22:43:41 +00:00
|
|
|
filepath = path.basename(filepath, ext);
|
2016-04-26 20:18:13 +00:00
|
|
|
ext = path.extname(filepath);
|
2015-02-12 22:43:41 +00:00
|
|
|
}
|
2016-04-26 20:18:13 +00:00
|
|
|
return filepath;
|
|
|
|
}
|
2015-05-07 19:16:48 +00:00
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
function getNameFromPath(filepath) {
|
|
|
|
filepath = removeExtName(filepath);
|
2015-03-23 22:22:47 +00:00
|
|
|
if (filepath === 'LayoutPropTypes') {
|
|
|
|
return 'Flexbox';
|
2015-05-07 19:16:48 +00:00
|
|
|
} else if (filepath === 'TransformPropTypes') {
|
|
|
|
return 'Transforms';
|
|
|
|
} else if (filepath === 'TabBarItemIOS') {
|
2015-04-21 17:19:36 +00:00
|
|
|
return 'TabBarIOS.Item';
|
2015-09-22 19:54:04 +00:00
|
|
|
} else if (filepath === 'AnimatedImplementation') {
|
|
|
|
return 'Animated';
|
2015-03-23 22:22:47 +00:00
|
|
|
}
|
2015-02-12 22:43:41 +00:00
|
|
|
return filepath;
|
|
|
|
}
|
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
function getPlatformFromPath(filepath) {
|
2016-04-26 20:18:13 +00:00
|
|
|
filepath = removeExtName(filepath);
|
2015-09-14 14:35:58 +00:00
|
|
|
if (endsWith(filepath, 'Android')) {
|
|
|
|
return ANDROID_SUFFIX;
|
|
|
|
} else if (endsWith(filepath, 'IOS')) {
|
|
|
|
return IOS_SUFFIX;
|
|
|
|
}
|
|
|
|
return CROSS_SUFFIX;
|
|
|
|
}
|
|
|
|
|
2016-05-05 16:09:53 +00:00
|
|
|
function getExamplePaths(componentName, componentPlatform) {
|
2016-06-21 21:22:44 +00:00
|
|
|
const componentExample = '../Examples/UIExplorer/' + componentName + 'Example.';
|
|
|
|
let pathsToCheck = [
|
2016-05-05 16:09:53 +00:00
|
|
|
componentExample + 'js',
|
|
|
|
componentExample + componentPlatform + '.js',
|
|
|
|
];
|
|
|
|
if (componentPlatform === CROSS_SUFFIX) {
|
|
|
|
pathsToCheck.push(
|
|
|
|
componentExample + IOS_SUFFIX + '.js',
|
|
|
|
componentExample + ANDROID_SUFFIX + '.js'
|
|
|
|
);
|
|
|
|
}
|
2016-06-21 21:22:44 +00:00
|
|
|
let paths = [];
|
2016-05-05 16:09:53 +00:00
|
|
|
pathsToCheck.map((p) => {
|
|
|
|
if (fs.existsSync(p)) {
|
|
|
|
paths.push(p);
|
2015-03-31 21:05:15 +00:00
|
|
|
}
|
2016-05-05 16:09:53 +00:00
|
|
|
});
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getExamples(componentName, componentPlatform) {
|
2016-06-21 21:22:44 +00:00
|
|
|
const paths = getExamplePaths(componentName, componentPlatform);
|
2016-05-05 16:09:53 +00:00
|
|
|
if (paths) {
|
2016-06-21 21:22:44 +00:00
|
|
|
let examples = [];
|
2016-05-05 16:09:53 +00:00
|
|
|
paths.map((p) => {
|
2016-06-21 21:22:44 +00:00
|
|
|
const platform = p.match(/Example\.(.*)\.js$/);
|
|
|
|
let title = '';
|
2016-05-05 16:09:53 +00:00
|
|
|
if ((componentPlatform === CROSS_SUFFIX) && (platform !== null)) {
|
|
|
|
title = platform[1].toUpperCase();
|
|
|
|
}
|
|
|
|
examples.push(
|
|
|
|
{
|
|
|
|
path: p.replace(/^\.\.\//, ''),
|
|
|
|
title: title,
|
|
|
|
content: fs.readFileSync(p).toString(),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return examples;
|
2015-03-31 19:28:26 +00:00
|
|
|
}
|
2016-05-05 16:09:53 +00:00
|
|
|
return;
|
2015-03-31 19:28:26 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
// Add methods that should not appear in the components documentation.
|
2016-04-26 20:18:13 +00:00
|
|
|
const methodsBlacklist = [
|
2016-04-09 18:12:46 +00:00
|
|
|
// Native methods mixin.
|
|
|
|
'getInnerViewNode',
|
|
|
|
'setNativeProps',
|
|
|
|
// Touchable mixin.
|
|
|
|
'touchableHandlePress' ,
|
|
|
|
'touchableHandleActivePressIn',
|
|
|
|
'touchableHandleActivePressOut',
|
|
|
|
'touchableHandleLongPress',
|
|
|
|
'touchableGetPressRectOffset',
|
|
|
|
'touchableGetHitSlop',
|
|
|
|
'touchableGetHighlightDelayMS',
|
|
|
|
'touchableGetLongPressDelayMS',
|
|
|
|
'touchableGetPressOutDelayMS',
|
|
|
|
// Scrollable mixin.
|
|
|
|
'getScrollableNode',
|
|
|
|
'getScrollResponder',
|
|
|
|
];
|
|
|
|
|
|
|
|
function filterMethods(method) {
|
|
|
|
return method.name[0] !== '_' && methodsBlacklist.indexOf(method.name) === -1;
|
|
|
|
}
|
|
|
|
|
2015-06-30 21:39:49 +00:00
|
|
|
// Determines whether a component should have a link to a runnable example
|
|
|
|
|
2016-04-04 13:04:54 +00:00
|
|
|
function isRunnable(componentName, componentPlatform) {
|
2016-06-21 21:22:44 +00:00
|
|
|
const paths = getExamplePaths(componentName, componentPlatform);
|
2016-05-05 16:09:53 +00:00
|
|
|
if (paths && paths.length > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2015-06-30 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 23:05:30 +00:00
|
|
|
// Hide a component from the sidebar by making it return false from
|
|
|
|
// this function
|
2016-04-26 20:18:13 +00:00
|
|
|
const HIDDEN_COMPONENTS = [
|
2016-04-24 15:12:28 +00:00
|
|
|
'Transforms',
|
|
|
|
'ListViewDataSource',
|
|
|
|
];
|
2015-05-07 23:05:30 +00:00
|
|
|
|
2016-04-24 15:12:28 +00:00
|
|
|
function shouldDisplayInSidebar(componentName) {
|
|
|
|
return HIDDEN_COMPONENTS.indexOf(componentName) === -1;
|
2015-05-07 23:05:30 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
function getNextComponent(idx) {
|
|
|
|
if (all[idx + 1]) {
|
|
|
|
const nextComponentName = getNameFromPath(all[idx + 1]);
|
2015-05-07 23:05:30 +00:00
|
|
|
|
|
|
|
if (shouldDisplayInSidebar(nextComponentName)) {
|
|
|
|
return slugify(nextComponentName);
|
|
|
|
} else {
|
2016-04-26 20:18:13 +00:00
|
|
|
return getNextComponent(idx + 1);
|
2015-05-07 23:05:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 'network';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
function componentsToMarkdown(type, json, filepath, idx, styles) {
|
|
|
|
const componentName = getNameFromPath(filepath);
|
|
|
|
const componentPlatform = getPlatformFromPath(filepath);
|
|
|
|
const docFilePath = '../docs/' + componentName + '.md';
|
2015-09-22 19:54:04 +00:00
|
|
|
|
2015-03-05 05:03:24 +00:00
|
|
|
if (fs.existsSync(docFilePath)) {
|
|
|
|
json.fullDescription = fs.readFileSync(docFilePath).toString();
|
|
|
|
}
|
2015-03-12 18:03:32 +00:00
|
|
|
json.type = type;
|
2015-03-31 17:10:05 +00:00
|
|
|
json.filepath = filepath.replace(/^\.\.\//, '');
|
|
|
|
json.componentName = componentName;
|
2015-09-14 14:35:58 +00:00
|
|
|
json.componentPlatform = componentPlatform;
|
2015-03-19 21:05:07 +00:00
|
|
|
if (styles) {
|
|
|
|
json.styles = styles;
|
|
|
|
}
|
2016-05-05 16:09:53 +00:00
|
|
|
json.examples = getExamples(componentName, componentPlatform);
|
2015-03-05 05:03:24 +00:00
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
if (json.methods) {
|
|
|
|
json.methods = json.methods.filter(filterMethods);
|
|
|
|
}
|
|
|
|
|
2015-05-07 23:05:30 +00:00
|
|
|
// Put Flexbox into the Polyfills category
|
2016-04-26 20:18:13 +00:00
|
|
|
const category = (type === 'style' ? 'Polyfills' : type + 's');
|
|
|
|
const next = getNextComponent(idx);
|
2015-05-07 23:05:30 +00:00
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const res = [
|
2015-02-12 22:43:41 +00:00
|
|
|
'---',
|
|
|
|
'id: ' + slugify(componentName),
|
|
|
|
'title: ' + componentName,
|
2015-03-05 02:10:12 +00:00
|
|
|
'layout: autodocs',
|
2015-05-07 23:05:30 +00:00
|
|
|
'category: ' + category,
|
2015-02-12 22:43:41 +00:00
|
|
|
'permalink: docs/' + slugify(componentName) + '.html',
|
2015-09-14 14:35:58 +00:00
|
|
|
'platform: ' + componentPlatform,
|
2015-05-07 23:05:30 +00:00
|
|
|
'next: ' + next,
|
|
|
|
'sidebar: ' + shouldDisplayInSidebar(componentName),
|
2016-04-04 13:04:54 +00:00
|
|
|
'runnable:' + isRunnable(componentName, componentPlatform),
|
2016-01-31 07:01:14 +00:00
|
|
|
'path:' + json.filepath,
|
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;
|
|
|
|
}
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
let componentCount;
|
2015-03-25 04:13:55 +00:00
|
|
|
|
2016-06-21 21:22:44 +00:00
|
|
|
function getTypedef(filepath, fileContent, json) {
|
|
|
|
let typedefDocgen;
|
|
|
|
try {
|
|
|
|
typedefDocgen = docgen.parse(
|
|
|
|
fileContent,
|
|
|
|
docgenHelpers.findExportedType,
|
|
|
|
[docgenHelpers.typedefHandler]
|
|
|
|
).map((type) => type.typedef);
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore errors due to missing exported type definitions
|
|
|
|
if (e.message.indexOf(docgen.ERROR_MISSING_DEFINITION) !== -1) {
|
|
|
|
console.error('Cannot parse file', filepath, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!json) {
|
|
|
|
return typedefDocgen;
|
|
|
|
}
|
|
|
|
let typedef = typedefDocgen;
|
|
|
|
if (json.typedef && json.typedef.length !== 0) {
|
|
|
|
json.typedef.forEach(def => {
|
|
|
|
const typedefMatch = typedefDocgen.find(t => t.name === def.name);
|
|
|
|
if (typedefMatch) {
|
|
|
|
typedef.name = Object.assign(typedefMatch, def);
|
|
|
|
} else {
|
|
|
|
typedef.push(def);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return typedef;
|
|
|
|
}
|
|
|
|
|
2015-03-25 04:13:55 +00:00
|
|
|
function renderComponent(filepath) {
|
2016-06-21 21:22:44 +00:00
|
|
|
const fileContent = fs.readFileSync(filepath);
|
2016-04-26 20:18:13 +00:00
|
|
|
const json = docgen.parse(
|
2016-06-21 21:22:44 +00:00
|
|
|
fileContent,
|
2015-03-25 04:13:55 +00:00
|
|
|
docgenHelpers.findExportedOrFirst,
|
2016-01-29 10:04:44 +00:00
|
|
|
docgen.defaultHandlers.concat([
|
|
|
|
docgenHelpers.stylePropTypeHandler,
|
|
|
|
docgenHelpers.deprecatedPropTypeHandler,
|
2016-06-21 21:22:44 +00:00
|
|
|
docgenHelpers.jsDocFormatHandler,
|
2016-01-29 10:04:44 +00:00
|
|
|
])
|
2015-03-25 04:13:55 +00:00
|
|
|
);
|
2016-06-21 21:22:44 +00:00
|
|
|
json.typedef = getTypedef(filepath, fileContent);
|
2015-05-07 19:50:41 +00:00
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
return componentsToMarkdown('component', json, filepath, componentCount++, styleDocs);
|
2015-03-25 04:13:55 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 21:22:44 +00:00
|
|
|
function isJsDocFormat(fileContent) {
|
|
|
|
const reComment = /\/\*\*[\s\S]+?\*\//g;
|
|
|
|
const comments = fileContent.match(reComment);
|
|
|
|
if (!comments) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !!comments[0].match(/\s*\*\s+@jsdoc/);
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseAPIJsDocFormat(filepath, fileContent) {
|
|
|
|
const fileName = path.basename(filepath);
|
|
|
|
const babelRC = {
|
|
|
|
'filename': fileName,
|
|
|
|
'sourceFileName': fileName,
|
|
|
|
'plugins': [
|
|
|
|
'transform-flow-strip-types',
|
|
|
|
'babel-plugin-syntax-trailing-function-commas',
|
|
|
|
]
|
2015-03-25 04:13:55 +00:00
|
|
|
};
|
2016-06-21 21:22:44 +00:00
|
|
|
// Babel transform
|
|
|
|
const code = babel.transform(fileContent, babelRC).code;
|
|
|
|
// Parse via jsdocs
|
|
|
|
let jsonParsed = jsdocApi.explainSync({
|
|
|
|
source: code,
|
|
|
|
configure: './jsdocs/jsdoc-conf.json'
|
|
|
|
});
|
|
|
|
// Cleanup jsdocs return
|
|
|
|
jsonParsed = jsonParsed.filter(i => {
|
|
|
|
return !i.undocumented && !/package|file/.test(i.kind);
|
|
|
|
});
|
|
|
|
jsonParsed = jsonParsed.map((identifier) => {
|
|
|
|
delete identifier.comment;
|
|
|
|
return identifier;
|
|
|
|
});
|
|
|
|
jsonParsed.forEach((identifier, index) => {
|
|
|
|
identifier.order = index;
|
|
|
|
});
|
|
|
|
// Group by "kind"
|
|
|
|
let json = {};
|
|
|
|
jsonParsed.forEach((identifier, index) => {
|
|
|
|
let kind = identifier.kind;
|
|
|
|
if (kind === 'function') {
|
|
|
|
kind = 'methods';
|
|
|
|
}
|
|
|
|
if (!json[kind]) {
|
|
|
|
json[kind] = [];
|
|
|
|
}
|
|
|
|
delete identifier.kind;
|
|
|
|
json[kind].push(identifier);
|
|
|
|
});
|
|
|
|
json.typedef = getTypedef(filepath, fileContent, json);
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseAPIInferred(filepath, fileContent) {
|
|
|
|
let json;
|
|
|
|
try {
|
|
|
|
json = jsDocs(fileContent);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Cannot parse file', filepath, e);
|
|
|
|
json = {};
|
|
|
|
}
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTypeName(type) {
|
|
|
|
let typeName;
|
|
|
|
switch (type.name) {
|
|
|
|
case 'signature':
|
|
|
|
typeName = type.type;
|
|
|
|
break;
|
|
|
|
case 'union':
|
|
|
|
typeName = type.value ?
|
|
|
|
type.value.map(getTypeName) :
|
|
|
|
type.elements.map(getTypeName);
|
|
|
|
break;
|
|
|
|
case 'enum':
|
|
|
|
if (typeof type.value === 'string') {
|
|
|
|
typeName = type.value;
|
|
|
|
} else {
|
|
|
|
typeName = 'enum';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '$Enum':
|
|
|
|
if (type.elements[0].signature.properties) {
|
|
|
|
typeName = type.elements[0].signature.properties.map(p => p.key);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'arrayOf':
|
|
|
|
typeName = getTypeName(type.value);
|
|
|
|
break;
|
|
|
|
case 'instanceOf':
|
|
|
|
typeName = type.value;
|
|
|
|
break;
|
|
|
|
case 'func':
|
|
|
|
typeName = 'function';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
typeName = type.alias ? type.alias : type.name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return typeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTypehintRec(typehint) {
|
|
|
|
if (typehint.type === 'simple') {
|
|
|
|
return typehint.value;
|
|
|
|
}
|
|
|
|
if (typehint.type === 'generic') {
|
|
|
|
return getTypehintRec(typehint.value[0]) +
|
|
|
|
'<' + getTypehintRec(typehint.value[1]) + '>';
|
|
|
|
}
|
|
|
|
return JSON.stringify(typehint);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTypehint(typehint) {
|
|
|
|
if (typeof typehint === 'object' && typehint.name) {
|
|
|
|
return getTypeName(typehint);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
var typehint = JSON.parse(typehint);
|
|
|
|
} catch (e) {
|
|
|
|
return typehint.split('|').map(type => type.trim());
|
|
|
|
}
|
|
|
|
return getTypehintRec(typehint);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getJsDocFormatType(entities) {
|
|
|
|
let modEntities = entities;
|
|
|
|
if (entities) {
|
|
|
|
if (typeof entities === 'object' && entities.length) {
|
|
|
|
entities.map((entity, entityIndex) => {
|
|
|
|
if (entity.typehint) {
|
|
|
|
const typeNames = [].concat(getTypehint(entity.typehint));
|
|
|
|
modEntities[entityIndex].type = { names: typeNames };
|
|
|
|
delete modEntities[entityIndex].typehint;
|
|
|
|
}
|
|
|
|
if (entity.name) {
|
|
|
|
const regexOptionalType = /\?$/;
|
|
|
|
if (regexOptionalType.test(entity.name)) {
|
|
|
|
modEntities[entityIndex].optional = true;
|
|
|
|
modEntities[entityIndex].name =
|
|
|
|
entity.name.replace(regexOptionalType, '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const typeNames = [].concat(getTypehint(entities));
|
|
|
|
return { type: { names : typeNames } };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return modEntities;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderAPI(filepath, type) {
|
|
|
|
const fileContent = fs.readFileSync(filepath).toString();
|
|
|
|
let json = parseAPIInferred(filepath, fileContent);
|
|
|
|
if (isJsDocFormat(fileContent)) {
|
|
|
|
let jsonJsDoc = parseAPIJsDocFormat(filepath, fileContent);
|
|
|
|
// Combine method info with jsdoc fomatted content
|
|
|
|
const methods = json.methods;
|
|
|
|
if (methods && methods.length) {
|
|
|
|
let modMethods = methods;
|
|
|
|
methods.map((method, methodIndex) => {
|
|
|
|
modMethods[methodIndex].params = getJsDocFormatType(method.params);
|
|
|
|
modMethods[methodIndex].returns =
|
|
|
|
getJsDocFormatType(method.returntypehint);
|
|
|
|
delete modMethods[methodIndex].returntypehint;
|
|
|
|
});
|
|
|
|
json.methods = modMethods;
|
|
|
|
// Use deep Object.assign so duplicate properties are overwritten.
|
|
|
|
deepAssign(jsonJsDoc.methods, json.methods);
|
|
|
|
}
|
|
|
|
json = jsonJsDoc;
|
|
|
|
}
|
|
|
|
return componentsToMarkdown(type, json, filepath, componentCount++);
|
2015-03-25 04:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderStyle(filepath) {
|
2016-04-26 20:18:13 +00:00
|
|
|
const json = docgen.parse(
|
2015-03-25 04:13:55 +00:00
|
|
|
fs.readFileSync(filepath),
|
|
|
|
docgenHelpers.findExportedObject,
|
|
|
|
[docgen.handlers.propTypeHandler]
|
|
|
|
);
|
2015-05-07 19:50:41 +00:00
|
|
|
|
2015-05-07 23:05:30 +00:00
|
|
|
// Remove deprecated transform props from docs
|
2016-04-26 20:18:13 +00:00
|
|
|
if (filepath === '../Libraries/StyleSheet/TransformPropTypes.js') {
|
2015-05-07 19:50:41 +00:00
|
|
|
['rotation', 'scaleX', 'scaleY', 'translateX', 'translateY'].forEach(function(key) {
|
2016-04-26 20:18:13 +00:00
|
|
|
delete json.props[key];
|
2015-05-07 19:50:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
return componentsToMarkdown('style', json, filepath, componentCount++);
|
2015-03-25 04:13:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const components = [
|
2016-05-26 20:46:58 +00:00
|
|
|
'../Libraries/Components/ActivityIndicator/ActivityIndicator.js',
|
2015-03-10 20:55:54 +00:00
|
|
|
'../Libraries/Components/DatePicker/DatePickerIOS.ios.js',
|
2015-09-14 14:35:58 +00:00
|
|
|
'../Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js',
|
2015-03-03 01:31:26 +00:00
|
|
|
'../Libraries/Image/Image.ios.js',
|
2015-03-21 17:07:45 +00:00
|
|
|
'../Libraries/CustomComponents/ListView/ListView.js',
|
2015-03-13 22:30:31 +00:00
|
|
|
'../Libraries/Components/MapView/MapView.js',
|
2015-08-31 19:23:11 +00:00
|
|
|
'../Libraries/Modal/Modal.js',
|
2015-11-26 05:26:32 +00:00
|
|
|
'../Libraries/CustomComponents/Navigator/Navigator.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
|
2016-04-26 20:18:13 +00:00
|
|
|
'../Libraries/Components/Picker/PickerIOS.ios.js',
|
2016-01-31 01:10:14 +00:00
|
|
|
'../Libraries/Components/Picker/Picker.js',
|
2015-09-14 14:35:58 +00:00
|
|
|
'../Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js',
|
2015-08-31 19:23:11 +00:00
|
|
|
'../Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js',
|
2016-01-09 15:43:02 +00:00
|
|
|
'../Libraries/Components/RefreshControl/RefreshControl.js',
|
2015-03-09 18:49:58 +00:00
|
|
|
'../Libraries/Components/ScrollView/ScrollView.js',
|
2015-05-15 03:22:31 +00:00
|
|
|
'../Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js',
|
2016-04-06 15:50:33 +00:00
|
|
|
'../Libraries/Components/Slider/Slider.js',
|
2015-08-11 17:25:39 +00:00
|
|
|
'../Libraries/Components/SliderIOS/SliderIOS.ios.js',
|
2016-02-03 14:40:39 +00:00
|
|
|
'../Libraries/Components/StatusBar/StatusBar.js',
|
2015-11-18 15:58:21 +00:00
|
|
|
'../Libraries/Components/Switch/Switch.js',
|
2015-03-10 20:55:54 +00:00
|
|
|
'../Libraries/Components/TabBarIOS/TabBarIOS.ios.js',
|
2015-04-21 17:19:36 +00:00
|
|
|
'../Libraries/Components/TabBarIOS/TabBarItemIOS.ios.js',
|
2015-03-03 01:31:26 +00:00
|
|
|
'../Libraries/Text/Text.js',
|
2015-03-31 16:46:45 +00:00
|
|
|
'../Libraries/Components/TextInput/TextInput.js',
|
2015-09-14 14:35:58 +00:00
|
|
|
'../Libraries/Components/ToolbarAndroid/ToolbarAndroid.android.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
'../Libraries/Components/Touchable/TouchableHighlight.js',
|
2015-09-14 14:35:58 +00:00
|
|
|
'../Libraries/Components/Touchable/TouchableNativeFeedback.android.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-10-17 02:25:43 +00:00
|
|
|
'../Libraries/Components/ViewPager/ViewPagerAndroid.android.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Components/WebView/WebView.ios.js',
|
2015-02-12 22:43:41 +00:00
|
|
|
];
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const apis = [
|
2015-06-11 03:41:21 +00:00
|
|
|
'../Libraries/ActionSheetIOS/ActionSheetIOS.js',
|
2015-12-18 14:15:22 +00:00
|
|
|
'../Libraries/Utilities/Alert.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Utilities/AlertIOS.js',
|
2015-09-22 19:54:04 +00:00
|
|
|
'../Libraries/Animated/src/AnimatedImplementation.js',
|
2015-03-13 22:30:31 +00:00
|
|
|
'../Libraries/AppRegistry/AppRegistry.js',
|
2016-01-21 19:43:51 +00:00
|
|
|
'../Libraries/AppState/AppState.js',
|
2015-10-27 18:10:59 +00:00
|
|
|
'../Libraries/Storage/AsyncStorage.js',
|
2015-09-14 14:35:58 +00:00
|
|
|
'../Libraries/Utilities/BackAndroid.android.js',
|
2015-03-12 18:03:32 +00:00
|
|
|
'../Libraries/CameraRoll/CameraRoll.js',
|
2016-03-02 16:47:37 +00:00
|
|
|
'../Libraries/Components/Clipboard/Clipboard.js',
|
2016-02-09 17:15:36 +00:00
|
|
|
'../Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js',
|
2015-10-09 21:44:36 +00:00
|
|
|
'../Libraries/Utilities/Dimensions.js',
|
2015-12-15 15:50:40 +00:00
|
|
|
'../Libraries/Components/Intent/IntentAndroid.android.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Interaction/InteractionManager.js',
|
2015-08-25 18:23:41 +00:00
|
|
|
'../Libraries/LayoutAnimation/LayoutAnimation.js',
|
2016-01-31 08:53:01 +00:00
|
|
|
'../Libraries/Linking/Linking.js',
|
2016-04-24 15:12:28 +00:00
|
|
|
'../Libraries/CustomComponents/ListView/ListViewDataSource.js',
|
2016-04-23 14:56:54 +00:00
|
|
|
'../node_modules/react/lib/NativeMethodsMixin.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Network/NetInfo.js',
|
2016-04-26 03:37:16 +00:00
|
|
|
'../Libraries/Interaction/PanResponder.js',
|
2015-03-12 18:03:32 +00:00
|
|
|
'../Libraries/Utilities/PixelRatio.js',
|
2015-03-25 03:38:29 +00:00
|
|
|
'../Libraries/PushNotificationIOS/PushNotificationIOS.js',
|
2015-03-12 18:03:32 +00:00
|
|
|
'../Libraries/Components/StatusBar/StatusBarIOS.ios.js',
|
|
|
|
'../Libraries/StyleSheet/StyleSheet.js',
|
2016-02-09 17:15:36 +00:00
|
|
|
'../Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js',
|
2015-09-14 14:35:58 +00:00
|
|
|
'../Libraries/Components/ToastAndroid/ToastAndroid.android.js',
|
2015-03-18 03:41:06 +00:00
|
|
|
'../Libraries/Vibration/VibrationIOS.ios.js',
|
2016-03-03 12:08:10 +00:00
|
|
|
'../Libraries/Vibration/Vibration.js',
|
2015-03-10 20:55:54 +00:00
|
|
|
];
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const stylesWithPermalink = [
|
2015-03-19 21:05:07 +00:00
|
|
|
'../Libraries/StyleSheet/LayoutPropTypes.js',
|
2015-05-07 19:16:48 +00:00
|
|
|
'../Libraries/StyleSheet/TransformPropTypes.js',
|
2016-02-04 23:45:34 +00:00
|
|
|
'../Libraries/Components/View/ShadowPropTypesIOS.js',
|
|
|
|
];
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const stylesForEmbed = [
|
2015-03-19 21:05:07 +00:00
|
|
|
'../Libraries/Components/View/ViewStylePropTypes.js',
|
|
|
|
'../Libraries/Text/TextStylePropTypes.js',
|
|
|
|
'../Libraries/Image/ImageStylePropTypes.js',
|
|
|
|
];
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const polyfills = [
|
2016-02-11 14:16:34 +00:00
|
|
|
'../Libraries/Geolocation/Geolocation.js',
|
2015-03-25 04:13:55 +00:00
|
|
|
];
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const all = components
|
2015-03-25 04:13:55 +00:00
|
|
|
.concat(apis)
|
2016-02-04 23:45:34 +00:00
|
|
|
.concat(stylesWithPermalink)
|
2015-03-25 04:13:55 +00:00
|
|
|
.concat(polyfills);
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const styleDocs = stylesForEmbed.reduce(function(docs, filepath) {
|
2015-03-19 21:05:07 +00:00
|
|
|
docs[path.basename(filepath).replace(path.extname(filepath), '')] =
|
|
|
|
docgen.parse(
|
|
|
|
fs.readFileSync(filepath),
|
|
|
|
docgenHelpers.findExportedObject,
|
2016-01-25 17:52:51 +00:00
|
|
|
[
|
|
|
|
docgen.handlers.propTypeHandler,
|
|
|
|
docgen.handlers.propTypeCompositionHandler,
|
|
|
|
docgen.handlers.propDocBlockHandler,
|
|
|
|
]
|
2015-03-19 21:05:07 +00:00
|
|
|
);
|
2015-05-05 22:27:43 +00:00
|
|
|
|
2015-03-19 21:05:07 +00:00
|
|
|
return docs;
|
|
|
|
}, {});
|
2015-03-12 18:03:32 +00:00
|
|
|
|
2015-02-12 22:43:41 +00:00
|
|
|
module.exports = function() {
|
2016-04-26 20:18:13 +00:00
|
|
|
componentCount = 0;
|
2015-03-12 18:03:32 +00:00
|
|
|
return [].concat(
|
2015-03-25 04:13:55 +00:00
|
|
|
components.map(renderComponent),
|
2016-06-21 21:22:44 +00:00
|
|
|
apis.map((filepath) => {
|
|
|
|
return renderAPI(filepath, 'api');
|
|
|
|
}),
|
2016-02-04 23:45:34 +00:00
|
|
|
stylesWithPermalink.map(renderStyle),
|
2016-06-21 21:22:44 +00:00
|
|
|
polyfills.map((filepath) => {
|
|
|
|
return renderAPI(filepath, 'Polyfill');
|
|
|
|
})
|
2015-03-12 18:03:32 +00:00
|
|
|
);
|
2015-02-12 22:43:41 +00:00
|
|
|
};
|