Skip to content

Commit 07a6eaf

Browse files
authored
chore: add docgen-ignore (react-native-elements#3675)
1 parent ce6e9c3 commit 07a6eaf

File tree

7 files changed

+70
-25
lines changed

7 files changed

+70
-25
lines changed

packages/base/.docgenignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/index.tsx
2+
src/*/components/**
3+
**/__tests__/**
4+
**/helpers/**
5+
**/config/**
6+
src/SearchBar/SearchBar-**

packages/themed/.docgenignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**

scripts/.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
"no-console": "off",
4+
"no-unused-vars": "off"
5+
}
6+
}

scripts/docgen/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RNE DocGen
2+
3+
```bash
4+
5+
yarn docs-build-api
6+
7+
```
8+
9+
## Options
10+
11+
```bash
12+
yarn docs-build-api --source='base/src/Avatar/**'
13+
yarn docs-build-api -s='base/src/Avatar/**'
14+
15+
## or
16+
17+
yarn docs-build-api --component='Button' --pkg='base'
18+
yarn docs-build-api -c='Button' -p='base'
19+
20+
```

scripts/docgen/index.ts

+15-24
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,19 @@ import path from 'path';
33
import { Markdown } from './generateMarkdown';
44
import { separateParent } from './parentProps';
55
import { docgenParser } from './docgenParser';
6+
import { findIgnoredComponents } from './utils';
67
import yargs from 'yargs';
78

89
const rootPath = path.join(__dirname, '../../packages/');
910

10-
const ignore = [
11-
// Ignore themed package
12-
rootPath + 'themed/**',
13-
'**/base/**/index.tsx',
14-
'**/src/*/components/**',
15-
'**/__tests__/**',
16-
'**/helpers/**',
17-
'**/config/**',
18-
'**/base/src/SearchBar/SearchBar-**',
19-
];
20-
21-
function main(sourcePath: string) {
22-
const filePaths = glob.sync(
23-
path.join(rootPath, sourcePath || '*/src/**/*.tsx'),
24-
{
25-
absolute: true,
26-
ignore,
27-
onlyFiles: true,
28-
}
29-
);
11+
function main({ source = '*/src/**/*.tsx' }: typeof argv) {
12+
const ignoredFiles = findIgnoredComponents(rootPath);
13+
14+
const filePaths = glob.sync(path.join(rootPath, source), {
15+
absolute: true,
16+
ignore: ignoredFiles,
17+
onlyFiles: true,
18+
});
3019

3120
console.log('Found', filePaths.length, 'components');
3221

@@ -39,8 +28,10 @@ function main(sourcePath: string) {
3928
});
4029
}
4130

42-
const argv = yargs(process.argv.slice(2)).options({
43-
include: { type: 'string', alias: 'i' },
44-
}).argv;
31+
const { argv } = yargs(process.argv.slice(2)).options({
32+
source: { type: 'string', alias: 's' },
33+
component: { type: 'string', alias: 'c' },
34+
pkg: { type: 'string', alias: 'p' },
35+
});
4536

46-
main(argv.include);
37+
main(argv);

scripts/docgen/utils.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { transform, types as t } from '@babel/core';
22
import dedent from 'dedent';
3+
import glob from 'fast-glob';
4+
import { join, dirname } from 'path';
5+
import fs from 'fs';
36

47
export const tabify = (str: string) => {
58
return transform(`<>\n${str}\n</>`, {
@@ -99,3 +102,22 @@ export const filterPropType = (value: string) => {
99102
}
100103
return value;
101104
};
105+
106+
export function findIgnoredComponents(rootPath: string) {
107+
const docgenIgnoreFiles = glob.sync(join(rootPath, '**/.docgenignore'), {
108+
absolute: true,
109+
onlyFiles: true,
110+
});
111+
const ignoredFiles = [];
112+
docgenIgnoreFiles.forEach((filePath) => {
113+
const content = fs.readFileSync(filePath, 'utf-8').trim();
114+
content.split('\n').forEach((componentPath) => {
115+
const trimmedPath = componentPath.trim();
116+
if (trimmedPath) {
117+
ignoredFiles.push(join(dirname(filePath), trimmedPath));
118+
}
119+
});
120+
});
121+
122+
return ignoredFiles;
123+
}

scripts/release/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-console */
21
import path from 'path';
32
import fs from 'fs';
43
import semver from 'semver';

0 commit comments

Comments
 (0)