-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: init doc-props script * fix: comment WuiProvider propTypes on /installation * chore: add script for all components * fix: lint * fix: missing props * fix: display React props name instead values * fix: no props on components * chore: fix scoped components props * fix: lint * fix: prevent 137 code on circleci
- Loading branch information
Showing
81 changed files
with
338 additions
and
166 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 |
---|---|---|
@@ -1,57 +1,28 @@ | ||
const isComponentFile = file => { | ||
if (file === 'index.js') { | ||
return true | ||
} | ||
|
||
const [name, extension] = file.split('.') | ||
const firstLetter = name[0] | ||
|
||
// Components start with capital letter e.g. Title.js | ||
if (extension === 'js' && firstLetter === firstLetter.toUpperCase()) { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
const path = require('path') | ||
const fs = require('fs/promises') | ||
|
||
export async function getStaticProps() { | ||
// Only import on server | ||
const reactDocs = require('react-docgen') | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
let propTypes = {} | ||
|
||
// Use react-docgen to get proptypes | ||
const cwd = process.cwd() | ||
const packages = fs.readdirSync(path.join(cwd, 'packages')) | ||
|
||
// Loop through all packages… | ||
packages.forEach(packageName => { | ||
const componentFiles = fs | ||
.readdirSync(path.join(cwd, `packages/${packageName}`)) | ||
.filter(isComponentFile) | ||
|
||
// Loop through all component files for a package and add to prepped propTypes object | ||
componentFiles.forEach(file => { | ||
const content = fs.readFileSync(path.join(cwd, `packages/${packageName}/${file}`), 'utf8') | ||
try { | ||
const { props } = reactDocs.parse(content) | ||
if (!props) { | ||
return | ||
} | ||
|
||
let key = packageName | ||
if (file !== 'index.js') { | ||
const [filename] = file.split('.') | ||
key = `${key}.${filename}` | ||
} | ||
propTypes[key] = props | ||
} catch (e) { | ||
console.error({ packageName, file, e: e.message }) | ||
return | ||
} | ||
}) | ||
const propTypes = {} | ||
const packages = await fs.readdir(path.join(process.cwd(), 'docs', 'pages', 'components')) | ||
|
||
packages.forEach(file => { | ||
const packageName = file.replace('.mdx', '') | ||
|
||
try { | ||
const packageProps = require(`@welcome-ui/${packageName}/dist/${packageName}.doc.json`) | ||
|
||
Object.keys(packageProps).forEach(key => { | ||
propTypes[key] = packageProps[key] | ||
}) | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(`@welcome-ui/${packageName}/dist/${packageName}.doc.json is missing`) | ||
} | ||
}) | ||
return { props: { propTypes } } | ||
|
||
return { | ||
props: { | ||
propTypes, | ||
}, | ||
} | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.