Skip to content

Commit 6918c46

Browse files
committed
fix docs scripts for new stucture
1 parent 15d3777 commit 6918c46

File tree

4 files changed

+127
-335
lines changed

4 files changed

+127
-335
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"prepublishOnly": "npm run build",
2121
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
2222
"create-docs-local": "npm run create-docs && npm run copy-docs-local",
23-
"push-docs": "node scripts/mintlify-post-processing/push-to-docs-repo.js",
2423
"copy-docs-local": "node scripts/mintlify-post-processing/copy-to-local-docs.js",
2524
"create-docs:generate": "typedoc",
2625
"create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"

scripts/mintlify-post-processing/copy-to-local-docs.js

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Examples:
7171
return { target };
7272
}
7373

74+
// Target location within mintlify-docs for SDK reference docs
75+
const SDK_DOCS_TARGET_PATH = "developers/references/sdk/docs";
76+
7477
function scanSdkDocs(sdkDocsDir) {
7578
const result = {};
7679

@@ -104,7 +107,8 @@ function updateDocsJson(repoDir, sdkFiles) {
104107
const docsContent = fs.readFileSync(docsJsonPath, "utf8");
105108
const docs = JSON.parse(docsContent);
106109

107-
// Build the new SDK Reference groups
110+
// Build the new SDK Reference groups using the new path structure
111+
const basePath = SDK_DOCS_TARGET_PATH;
108112
const groupMap = new Map(); // group name -> pages array
109113

110114
const addToGroup = (groupName, pages) => {
@@ -118,28 +122,28 @@ function updateDocsJson(repoDir, sdkFiles) {
118122
if (sdkFiles.functions?.length > 0 && categoryMap.functions) {
119123
addToGroup(
120124
categoryMap.functions,
121-
sdkFiles.functions.map((file) => `sdk-docs/functions/${file}`)
125+
sdkFiles.functions.map((file) => `${basePath}/functions/${file}`)
122126
);
123127
}
124128

125129
if (sdkFiles.interfaces?.length > 0 && categoryMap.interfaces) {
126130
addToGroup(
127131
categoryMap.interfaces,
128-
sdkFiles.interfaces.map((file) => `sdk-docs/interfaces/${file}`)
132+
sdkFiles.interfaces.map((file) => `${basePath}/interfaces/${file}`)
129133
);
130134
}
131135

132136
if (sdkFiles.classes?.length > 0 && categoryMap.classes) {
133137
addToGroup(
134138
categoryMap.classes,
135-
sdkFiles.classes.map((file) => `sdk-docs/classes/${file}`)
139+
sdkFiles.classes.map((file) => `${basePath}/classes/${file}`)
136140
);
137141
}
138142

139143
if (sdkFiles["type-aliases"]?.length > 0 && categoryMap["type-aliases"]) {
140144
addToGroup(
141145
categoryMap["type-aliases"],
142-
sdkFiles["type-aliases"].map((file) => `sdk-docs/type-aliases/${file}`)
146+
sdkFiles["type-aliases"].map((file) => `${basePath}/type-aliases/${file}`)
143147
);
144148
}
145149

@@ -155,7 +159,7 @@ function updateDocsJson(repoDir, sdkFiles) {
155159
`SDK Reference pages: ${JSON.stringify(sdkReferencePages, null, 2)}`
156160
);
157161

158-
// Navigate to: Developers tab -> SDK group -> SDK Reference group
162+
// Navigate to: Developers tab -> anchors -> References anchor -> groups -> JavaScript SDK -> SDK Reference
159163
const developersTab = docs.navigation.tabs.find(
160164
(tab) => tab.tab === "Developers"
161165
);
@@ -165,40 +169,45 @@ function updateDocsJson(repoDir, sdkFiles) {
165169
process.exit(1);
166170
}
167171

168-
// Find the SDK group (it's a top-level group in the Developers tab)
169-
const sdkGroup = developersTab.groups.find((g) => g.group === "SDK");
172+
// Find the References anchor (new structure uses anchors instead of groups at tab level)
173+
const referencesAnchor = developersTab.anchors?.find(
174+
(anchor) => anchor.anchor === "References"
175+
);
170176

171-
if (!sdkGroup) {
172-
console.error("Could not find 'SDK' group in Developers tab");
177+
if (!referencesAnchor) {
178+
console.error("Could not find 'References' anchor in Developers tab");
173179
process.exit(1);
174180
}
175181

176-
// Find SDK Reference within SDK's pages (it's a nested group object)
177-
const sdkRefIndex = sdkGroup.pages.findIndex(
182+
// Find the JavaScript SDK group within the References anchor
183+
const jsSdkGroup = referencesAnchor.groups?.find(
184+
(g) => g.group === "JavaScript SDK"
185+
);
186+
187+
if (!jsSdkGroup) {
188+
console.error(
189+
"Could not find 'JavaScript SDK' group in References anchor"
190+
);
191+
process.exit(1);
192+
}
193+
194+
// Find SDK Reference within JavaScript SDK's pages (it's a nested group object)
195+
const sdkRefIndex = jsSdkGroup.pages.findIndex(
178196
(page) => typeof page === "object" && page.group === "SDK Reference"
179197
);
180198

181199
if (sdkRefIndex === -1) {
182-
console.error("Could not find 'SDK Reference' group in SDK");
200+
console.error("Could not find 'SDK Reference' group in JavaScript SDK");
183201
process.exit(1);
184202
}
185203

186204
// Update the SDK Reference pages with our generated groups
187-
sdkGroup.pages[sdkRefIndex] = {
205+
jsSdkGroup.pages[sdkRefIndex] = {
188206
group: "SDK Reference",
189207
icon: "brackets-curly",
190208
pages: sdkReferencePages,
191209
};
192210

193-
// Remove the old standalone "SDK Reference" tab if it exists
194-
const oldSdkTabIndex = docs.navigation.tabs.findIndex(
195-
(tab) => tab.tab === "SDK Reference"
196-
);
197-
if (oldSdkTabIndex !== -1) {
198-
console.log("Removing old standalone 'SDK Reference' tab...");
199-
docs.navigation.tabs.splice(oldSdkTabIndex, 1);
200-
}
201-
202211
// Write updated docs.json
203212
console.log(`Writing updated docs.json to ${docsJsonPath}...`);
204213
fs.writeFileSync(docsJsonPath, JSON.stringify(docs, null, 2) + "\n", "utf8");
@@ -237,13 +246,16 @@ function main() {
237246
}
238247

239248
try {
240-
// Remove the existing sdk-docs directory
241-
const sdkDocsTarget = path.join(target, "sdk-docs");
249+
// Remove the existing SDK docs directory at the new location
250+
const sdkDocsTarget = path.join(target, SDK_DOCS_TARGET_PATH);
242251
if (fs.existsSync(sdkDocsTarget)) {
243-
console.log(`Removing existing sdk-docs directory...`);
252+
console.log(`Removing existing SDK docs directory at ${SDK_DOCS_TARGET_PATH}...`);
244253
fs.rmSync(sdkDocsTarget, { recursive: true, force: true });
245254
}
246255

256+
// Ensure parent directories exist
257+
fs.mkdirSync(sdkDocsTarget, { recursive: true });
258+
247259
// Copy the docs directory to the target
248260
console.log(`Copying docs to ${sdkDocsTarget}...`);
249261
fs.cpSync(DOCS_SOURCE_PATH, sdkDocsTarget, { recursive: true });
@@ -261,7 +273,15 @@ function main() {
261273
// Update the docs.json file
262274
updateDocsJson(target, sdkFiles);
263275

276+
// Also remove the old sdk-docs location if it exists (migration cleanup)
277+
const oldSdkDocsLocation = path.join(target, "sdk-docs");
278+
if (fs.existsSync(oldSdkDocsLocation)) {
279+
console.log(`Removing old sdk-docs directory at root level...`);
280+
fs.rmSync(oldSdkDocsLocation, { recursive: true, force: true });
281+
}
282+
264283
console.log("\n✅ Successfully copied SDK docs to local mintlify-docs repo");
284+
console.log(` Target: ${SDK_DOCS_TARGET_PATH}`);
265285
console.log(`\nTo preview the docs, run 'mintlify dev' in ${target}`);
266286
} catch (e) {
267287
console.error(`Error: Failed to copy docs: ${e}`);

scripts/mintlify-post-processing/file-processing/file-processing.js

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,56 @@ const APPENDED_ARTICLES_PATH = path.join(
3333
// Controlled via env var so we can re-enable Panel injection when needed.
3434
const PANELS_ENABLED = process.env.MINTLIFY_INCLUDE_PANELS === "true";
3535

36-
const MODULE_RENAMES = {
37-
AgentsModule: "agents",
38-
AnalyticsModule: "analytics",
39-
AppLogsModule: "app-logs",
40-
AuthModule: "auth",
41-
ConnectorsModule: "connectors",
42-
EntitiesModule: "entities",
43-
FunctionsModule: "functions",
44-
IntegrationsModule: "integrations",
45-
SsoModule: "sso",
46-
};
47-
48-
const REVERSE_MODULE_RENAMES = Object.entries(MODULE_RENAMES).reduce(
49-
(acc, [k, v]) => {
50-
acc[v] = k;
51-
return acc;
52-
},
53-
{}
54-
);
36+
/**
37+
* Converts a PascalCase module name to kebab-case.
38+
* E.g., "AgentsModule" -> "agents", "AppLogsModule" -> "app-logs"
39+
*
40+
* @param {string} name - The PascalCase name (e.g., "AgentsModule")
41+
* @returns {string | null} - The kebab-case name, or null if not a module name
42+
*/
43+
function deriveModuleRename(name) {
44+
if (!name.endsWith("Module")) {
45+
return null;
46+
}
47+
48+
// Remove "Module" suffix
49+
const withoutModule = name.slice(0, -6);
50+
51+
// Convert PascalCase to kebab-case
52+
// Insert hyphen before each capital letter (except the first), then lowercase
53+
const kebabCase = withoutModule
54+
.replace(/([a-z])([A-Z])/g, "$1-$2")
55+
.toLowerCase();
56+
57+
return kebabCase;
58+
}
59+
60+
/**
61+
* Checks if a name is a module name (ends with "Module") and returns its renamed version.
62+
* Uses the derived rename algorithm.
63+
*
64+
* @param {string} name - The name to check
65+
* @returns {string | null} - The renamed version, or null if not a module
66+
*/
67+
function getModuleRename(name) {
68+
return deriveModuleRename(name);
69+
}
70+
71+
/**
72+
* Checks if a name is a renamed module (kebab-case) and returns its original name.
73+
*
74+
* @param {string} name - The kebab-case name to check
75+
* @returns {string | null} - The original PascalCase module name, or null if not found
76+
*/
77+
function getReverseModuleRename(name) {
78+
// Convert kebab-case back to PascalCase and add "Module" suffix
79+
const pascalCase = name
80+
.split("-")
81+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
82+
.join("");
83+
84+
return `${pascalCase}Module`;
85+
}
5586

5687
/**
5788
* Get list of linked type names that should be suppressed
@@ -170,8 +201,9 @@ Access to additional integration packages.
170201
// If filename has extension, strip it for checking map
171202
const nameWithoutExt = filename.replace(/\.mdx?$/, "");
172203

173-
if (MODULE_RENAMES[nameWithoutExt]) {
174-
pathParts[pathParts.length - 1] = MODULE_RENAMES[nameWithoutExt];
204+
const moduleRename = getModuleRename(nameWithoutExt);
205+
if (moduleRename) {
206+
pathParts[pathParts.length - 1] = moduleRename;
175207
linkPath = pathParts.join("/");
176208
}
177209

@@ -223,15 +255,22 @@ function performModuleRenames(dir) {
223255
let targetName = nameWithoutExt;
224256
let needsRename = false;
225257

226-
if (MODULE_RENAMES[nameWithoutExt]) {
227-
targetName = MODULE_RENAMES[nameWithoutExt];
258+
const moduleRename = getModuleRename(nameWithoutExt);
259+
if (moduleRename) {
260+
targetName = moduleRename;
228261
needsRename = true;
229-
} else if (REVERSE_MODULE_RENAMES[nameWithoutExt]) {
230-
// It's already renamed (e.g. "entities"), but we should ensure title is correct
231-
targetName = nameWithoutExt;
262+
} else if (nameWithoutExt.match(/^[a-z]+(-[a-z]+)*$/)) {
263+
// It's already in kebab-case (e.g. "entities", "app-logs"), might be a renamed module
264+
// Check if we can derive an original module name from it
265+
const possibleOriginal = getReverseModuleRename(nameWithoutExt);
266+
if (possibleOriginal) {
267+
targetName = nameWithoutExt;
268+
}
232269
}
233270

234-
if (needsRename || REVERSE_MODULE_RENAMES[targetName]) {
271+
// Process if it needs renaming OR if it looks like a module file (for title updates)
272+
const isModuleFile = needsRename || nameWithoutExt.match(/^[a-z]+(-[a-z]+)*$/);
273+
if (isModuleFile) {
235274
const newPath = path.join(dir, `${targetName}.mdx`); // Always use .mdx
236275

237276
let content = fs.readFileSync(entryPath, "utf-8");
@@ -420,12 +459,16 @@ function processAllFiles(dir, linkedTypeNames, exposedTypeNames) {
420459
const relativePath = path.relative(DOCS_DIR, entryPath);
421460
const isTypeDoc = isTypeDocPath(relativePath);
422461

423-
// Check if exposed. Handle renamed modules by checking reverse map.
462+
// Check if exposed. Handle renamed modules by deriving the original name.
424463
// Use both the raw filename and any potential original name
425-
const originalName = REVERSE_MODULE_RENAMES[fileName] || fileName;
464+
// If the filename is kebab-case, it might be a renamed module
465+
const possibleOriginalModule = fileName.match(/^[a-z]+(-[a-z]+)*$/)
466+
? getReverseModuleRename(fileName)
467+
: null;
468+
const originalName = possibleOriginalModule || fileName;
426469

427470
// If it's a renamed module (e.g. "entities"), treat it as exposed if "EntitiesModule" is exposed
428-
const isRenamedModule = !!REVERSE_MODULE_RENAMES[fileName];
471+
const isRenamedModule = !!possibleOriginalModule;
429472

430473
const isExposedType =
431474
!isTypeDoc ||
@@ -627,12 +670,13 @@ function applyAppendedArticles(appendedArticles) {
627670
continue;
628671
}
629672

630-
// Check if host was renamed
673+
// Check if host was renamed (derives rename automatically for *Module names)
631674
let effectiveHostKey = hostKey;
632675
const pathParts = hostKey.split("/");
633676
const hostName = pathParts[pathParts.length - 1];
634-
if (MODULE_RENAMES[hostName]) {
635-
pathParts[pathParts.length - 1] = MODULE_RENAMES[hostName];
677+
const hostModuleRename = getModuleRename(hostName);
678+
if (hostModuleRename) {
679+
pathParts[pathParts.length - 1] = hostModuleRename;
636680
effectiveHostKey = pathParts.join("/");
637681
}
638682

@@ -650,12 +694,13 @@ function applyAppendedArticles(appendedArticles) {
650694
const collectedHeadings = PANELS_ENABLED ? [] : null;
651695

652696
for (const appendKey of appendList) {
653-
// Check if appended file was renamed (unlikely for EntityHandler but good for consistency)
697+
// Check if appended file was renamed (derives rename automatically for *Module names)
654698
let effectiveAppendKey = appendKey;
655699
const appendParts = appendKey.split("/");
656700
const appendName = appendParts[appendParts.length - 1];
657-
if (MODULE_RENAMES[appendName]) {
658-
appendParts[appendParts.length - 1] = MODULE_RENAMES[appendName];
701+
const appendModuleRename = getModuleRename(appendName);
702+
if (appendModuleRename) {
703+
appendParts[appendParts.length - 1] = appendModuleRename;
659704
effectiveAppendKey = appendParts.join("/");
660705
}
661706

0 commit comments

Comments
 (0)