forked from facebook/react-native-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-api-docs.js
More file actions
51 lines (43 loc) · 1.48 KB
/
sync-api-docs.js
File metadata and controls
51 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// ***** EXPERIMENTAL *****
// Updates the API docs from the React Native source code.
'use strict';
const process = require('process');
const fs = require('fs-extra');
const path = require('path');
const extractDocsFromRN = require('./extractDocsFromRN');
const preprocessGeneratedApiDocs = require('./preprocessGeneratedApiDocs');
const generateMarkdown = require('./generateMarkdown');
const {titleToId} = require('./utils');
const DOCS_ROOT_DIR = path.resolve(__dirname, '..', 'docs');
async function generateApiDocs(rnPath) {
const apiDocs = await extractDocsFromRN(rnPath);
preprocessGeneratedApiDocs(apiDocs);
await Promise.all(
apiDocs.map(async ({component, file}, index) => {
if (!component.displayName) {
console.log(
`react-docgen data for ${path.basename(file)} was malformed, skipping`
);
return;
}
const id = titleToId(component.displayName);
const componentMarkdown = generateMarkdown(
{title: component.displayName, id: id},
component
);
const outFile = path.join(DOCS_ROOT_DIR, id + '.md');
console.log('Generated ' + outFile);
await fs.writeFile(outFile, componentMarkdown, 'utf8');
})
);
}
async function main(args) {
await generateApiDocs(args[0]);
}
main(process.argv.slice(2));