-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
1017f5d
commit 8e177fa
Showing
6 changed files
with
143 additions
and
5 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 |
---|---|---|
|
@@ -82,3 +82,6 @@ out | |
|
||
# File system stuff | ||
**/.DS_Store | ||
|
||
# Auto-generated documentation | ||
__tmpDocs |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,83 @@ | ||
const fs = require('fs') | ||
const prettier = require('prettier') | ||
|
||
function splitIntoMultipleFiles() { | ||
const cwd = process.cwd() | ||
|
||
const rootFile = fs.readFileSync(`${cwd}/__tmpDocs/modules.md`, 'utf8') | ||
// typedoc-plugin-markdown generates a single file with all the docs separated by "___" | ||
const files = rootFile.split('___') | ||
|
||
for (const file of files) { | ||
try { | ||
const content = file.split('\n') | ||
const componentName = content | ||
// Find the line that starts with "###", which is the component/method/hook name | ||
.find((line) => line.startsWith('###')) | ||
.replace('###', '') | ||
.trim() | ||
|
||
// Means that this is a component | ||
const isPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(componentName) | ||
|
||
// Means that this is a hook, matches camelCase methods starting with "use" | ||
const isHook = /^use[A-Z][a-zA-Z0-9]*$/.test(componentName) | ||
|
||
if (isHook) { | ||
const kebabCaseName = componentName | ||
.replace(/([a-z0-9])([A-Z])/g, '$1-$2') | ||
.toLowerCase() | ||
|
||
const folderPath = `${cwd}/__tmpDocs/hooks/${kebabCaseName}` | ||
fs.mkdirSync(folderPath, { | ||
recursive: true, | ||
}) | ||
|
||
const filePath = `${folderPath}/code.mdx` | ||
fs.writeFileSync(filePath, file) | ||
prettify(filePath) | ||
|
||
continue | ||
} | ||
|
||
if (isPascalCase) { | ||
const kebabCaseName = componentName | ||
.replace(/([a-z0-9])([A-Z])/g, '$1-$2') | ||
.toLowerCase() | ||
|
||
const folderPath = `${cwd}/__tmpDocs/components/${kebabCaseName}` | ||
fs.mkdirSync(folderPath, { | ||
recursive: true, | ||
}) | ||
|
||
const filePath = `${folderPath}/code.mdx` | ||
fs.writeFileSync(filePath, file) | ||
|
||
prettify(filePath) | ||
|
||
continue | ||
} | ||
|
||
const filePath = `${cwd}/__tmpDocs/${componentName}.md` | ||
fs.writeFileSync(filePath, file) | ||
prettify(filePath) | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
} | ||
|
||
function prettify(filePath) { | ||
const prettierConfigPath = require.resolve('../.prettierrc') | ||
const prettierConfig = require(prettierConfigPath) | ||
const prettierOptions = { | ||
...prettierConfig, | ||
parser: 'markdown', | ||
} | ||
|
||
const file = fs.readFileSync(filePath, 'utf8') | ||
const formatted = prettier.format(file, prettierOptions) | ||
fs.writeFileSync(filePath, formatted) | ||
} | ||
|
||
splitIntoMultipleFiles() |
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,13 @@ | ||
{ | ||
"$schema": "https://typedoc.org/schema.json", | ||
"entryPoints": [ | ||
"packages/components/src/index.ts", | ||
"packages/raccoon-next/src/index.ts", | ||
"packages/raccoon-io/src/index.ts" | ||
], | ||
"exclude": [ | ||
"packages/components/src/**/*+(index|.vitest|.e2e|.test|.stories).(ts|tsx)" | ||
], | ||
"tsconfig": "packages/components/tsconfig.json", | ||
"out": "__tmpDocs" | ||
} |