Skip to content

Commit f4b11d6

Browse files
committed
Add logic to prevent duplication of legacy hooks
1 parent b764267 commit f4b11d6

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

.typedoc/extract-returns-and-params.mjs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ function extractReturnsSection(filePath) {
3535
// Generate the new filename: use-auth.mdx -> use-auth-return.mdx
3636
const fileName = path.basename(filePath, '.mdx');
3737
const dirName = path.dirname(filePath);
38-
const newFilePath = path.join(dirName, `${fileName}-return.mdx`);
38+
let outputBaseName = `${fileName}-return`;
39+
let outputDir = dirName;
40+
// Legacy hooks: move into legacy/ and drop the -1
41+
if (fileName === 'use-sign-in-1' || fileName === 'use-sign-up-1') {
42+
outputBaseName = `${fileName.replace(/-1$/, '')}-return`;
43+
outputDir = path.join(dirName, 'legacy');
44+
fs.mkdirSync(outputDir, { recursive: true });
45+
}
46+
const newFilePath = path.join(outputDir, `${outputBaseName}.mdx`);
3947

4048
// Write the extracted Returns section to the new file
4149
fs.writeFileSync(newFilePath, returnsContent, 'utf-8');
@@ -67,10 +75,18 @@ function extractParametersSection(filePath) {
6775
const content = fs.readFileSync(filePath, 'utf-8');
6876
const fileName = path.basename(filePath, '.mdx');
6977
const dirName = path.dirname(filePath);
78+
let outputDir = dirName;
79+
let outputBaseName = fileName;
80+
81+
if (fileName === 'use-sign-in-1' || fileName === 'use-sign-up-1') {
82+
outputDir = path.join(dirName, 'legacy');
83+
outputBaseName = fileName.replace(/-1$/, '');
84+
fs.mkdirSync(outputDir, { recursive: true });
85+
}
7086

7187
// Always use -params suffix
7288
const suffix = '-params';
73-
const targetFileName = `${fileName}${suffix}.mdx`;
89+
const targetFileName = `${outputBaseName}${suffix}.mdx`;
7490
const propsFileName = `${fileName}-props.mdx`;
7591

7692
// Delete any existing -props file (TypeDoc-generated)
@@ -100,13 +116,40 @@ function extractParametersSection(filePath) {
100116
const processedParams = replaceGenericTypesInParamsTable(paramsContent);
101117

102118
// Write to new file
103-
const newFilePath = path.join(dirName, targetFileName);
119+
const newFilePath = path.join(outputDir, targetFileName);
104120
fs.writeFileSync(newFilePath, processedParams, 'utf-8');
105121

106122
console.log(`[extract-returns] Created ${path.relative(process.cwd(), newFilePath)}`);
107123
return true;
108124
}
109125

126+
/**
127+
* Renames legacy hook docs to use a -legacy suffix (without the -1).
128+
* @param {string} filePath
129+
*/
130+
function moveLegacyHookDoc(filePath) {
131+
const fileName = path.basename(filePath, '.mdx');
132+
if (fileName !== 'use-sign-in-1' && fileName !== 'use-sign-up-1') {
133+
return;
134+
}
135+
136+
const dirName = path.dirname(filePath);
137+
const legacyDir = path.join(dirName, 'legacy');
138+
fs.mkdirSync(legacyDir, { recursive: true });
139+
140+
const legacyName = fileName.replace(/-1$/, '');
141+
const legacyPath = path.join(legacyDir, `${legacyName}.mdx`);
142+
143+
if (fs.existsSync(legacyPath)) {
144+
fs.unlinkSync(legacyPath);
145+
}
146+
147+
fs.renameSync(filePath, legacyPath);
148+
console.log(
149+
`[extract-returns] Moved ${path.relative(process.cwd(), filePath)} -> ${path.relative(process.cwd(), legacyPath)}`,
150+
);
151+
}
152+
110153
/**
111154
* Recursively reads all .mdx files in a directory, excluding generated files
112155
* @param {string} dir - The directory to read
@@ -169,6 +212,9 @@ function main() {
169212
if (extractParametersSection(filePath)) {
170213
paramsCount++;
171214
}
215+
216+
// Move legacy hook docs after extraction
217+
moveLegacyHookDoc(filePath);
172218
}
173219

174220
console.log(`[extract-returns] Extracted ${returnsCount} Returns sections`);

0 commit comments

Comments
 (0)