-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import fg from 'fast-glob'; | ||
import { resolve } from 'path'; | ||
import docgen from 'react-docgen-typescript'; | ||
|
||
/** | ||
* Builds the doc types. | ||
*/ | ||
function buildDocs() { | ||
const files = fg.sync('src/**/!(*.stories).tsx'); | ||
|
||
const result = []; | ||
let count = 0; | ||
let fail = 0; | ||
const options = { | ||
savePropValueAsString: true, | ||
// Skip generating docs for HTML attributes | ||
propFilter: (prop) => { | ||
if (prop.declarations !== undefined && prop.declarations.length > 0) { | ||
const hasPropAdditionalDescription = prop.declarations.find((declaration) => { | ||
return !declaration.fileName.includes('node_modules'); | ||
}); | ||
|
||
return Boolean(hasPropAdditionalDescription); | ||
} | ||
|
||
return true; | ||
}, | ||
}; | ||
|
||
const docgenWithTSConfig = docgen.withCustomConfig( | ||
'./tsconfig.json', | ||
options | ||
); | ||
|
||
files.forEach(file => { | ||
console.log('Reading', file); | ||
|
||
try { | ||
const documentation = docgenWithTSConfig.parse(file, options); | ||
if (documentation) { | ||
result.push(...documentation); | ||
count++; | ||
} | ||
} catch (e) { | ||
fail++; | ||
console.error('Error reading', file, e); | ||
} | ||
}); | ||
|
||
const fileName = resolve('dist', 'docs.json'); | ||
writeFileSync(fileName, JSON.stringify(result, null, 2)); | ||
|
||
console.info('Docs created!', fileName); | ||
console.info('Failed:', fail); | ||
console.info('Total Doc:', count); | ||
} | ||
|
||
buildDocs(); |