Skip to content

Commit ac0b300

Browse files
authored
updates for realtime entities (#76)
* updates for realtime entities * hide stuff not ready to document yet * new command for creating and copying docs locally
1 parent 3c234f1 commit ac0b300

11 files changed

Lines changed: 346 additions & 63 deletions

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"docs": "typedoc",
2020
"prepublishOnly": "npm run build",
2121
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
22+
"create-docs-local": "npm run create-docs && npm run copy-docs-local",
2223
"push-docs": "node scripts/mintlify-post-processing/push-to-docs-repo.js",
24+
"copy-docs-local": "node scripts/mintlify-post-processing/copy-to-local-docs.js",
2325
"create-docs:generate": "typedoc",
2426
"create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"
2527
},
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Local docs copy script - copies SDK docs to a local mintlify-docs repo.
5+
*
6+
* Usage:
7+
* node copy-to-local-docs.js [--target <path-to-mintlify-docs>]
8+
*
9+
* Options:
10+
* --target <path> Path to the mintlify-docs repo. Defaults to ../mintlify-docs
11+
* (assumes both repos are in the same parent folder)
12+
*
13+
* Examples:
14+
* node copy-to-local-docs.js
15+
* node copy-to-local-docs.js --target ~/Projects/mintlify-docs
16+
* npm run copy-docs-local
17+
* npm run copy-docs-local -- --target ~/Projects/mintlify-docs
18+
*/
19+
20+
import fs from "fs";
21+
import path from "path";
22+
23+
console.debug = () => {}; // Disable debug logging. Comment this out to enable debug logging.
24+
25+
const DOCS_SOURCE_PATH = path.join(import.meta.dirname, "../../docs/content");
26+
const CATEGORY_MAP_PATH = path.join(import.meta.dirname, "./category-map.json");
27+
28+
// Default: assume mintlify-docs is a sibling directory to javascript-sdk
29+
const SDK_ROOT = path.join(import.meta.dirname, "../..");
30+
const DEFAULT_TARGET = path.join(SDK_ROOT, "../mintlify-docs");
31+
32+
function parseArgs() {
33+
const args = process.argv.slice(2);
34+
let target = DEFAULT_TARGET;
35+
36+
for (let i = 0; i < args.length; i++) {
37+
const arg = args[i];
38+
39+
if ((arg === "--target" || arg === "-t") && i + 1 < args.length) {
40+
target = args[++i];
41+
// Expand ~ to home directory
42+
if (target.startsWith("~")) {
43+
target = path.join(process.env.HOME, target.slice(1));
44+
}
45+
// Resolve to absolute path
46+
target = path.resolve(target);
47+
}
48+
49+
if (arg === "--help" || arg === "-h") {
50+
console.log(`
51+
Local docs copy script - copies SDK docs to a local mintlify-docs repo.
52+
53+
Usage:
54+
node copy-to-local-docs.js [--target <path-to-mintlify-docs>]
55+
56+
Options:
57+
--target, -t <path> Path to the mintlify-docs repo.
58+
Defaults to ../mintlify-docs (sibling directory)
59+
--help, -h Show this help message
60+
61+
Examples:
62+
node copy-to-local-docs.js
63+
node copy-to-local-docs.js --target ~/Projects/mintlify-docs
64+
npm run copy-docs-local
65+
npm run copy-docs-local -- --target ~/Projects/mintlify-docs
66+
`);
67+
process.exit(0);
68+
}
69+
}
70+
71+
return { target };
72+
}
73+
74+
function scanSdkDocs(sdkDocsDir) {
75+
const result = {};
76+
77+
// Get a list of all the subdirectories in the sdkDocsDir
78+
const subdirectories = fs
79+
.readdirSync(sdkDocsDir)
80+
.filter((file) => fs.statSync(path.join(sdkDocsDir, file)).isDirectory());
81+
console.log(`Subdirectories: ${subdirectories}`);
82+
83+
for (const subdirectory of subdirectories) {
84+
const subdirectoryPath = path.join(sdkDocsDir, subdirectory);
85+
const files = fs
86+
.readdirSync(subdirectoryPath)
87+
.filter((file) => file.endsWith(".mdx"));
88+
result[subdirectory] = files.map((file) => path.basename(file, ".mdx"));
89+
}
90+
return result;
91+
}
92+
93+
function updateDocsJson(repoDir, sdkFiles) {
94+
const docsJsonPath = path.join(repoDir, "docs.json");
95+
let categoryMap = {};
96+
try {
97+
categoryMap = JSON.parse(fs.readFileSync(CATEGORY_MAP_PATH, "utf8"));
98+
} catch (e) {
99+
console.error(`Error: Category map file not found: ${CATEGORY_MAP_PATH}`);
100+
process.exit(1);
101+
}
102+
103+
console.log(`Reading docs.json from ${docsJsonPath}...`);
104+
const docsContent = fs.readFileSync(docsJsonPath, "utf8");
105+
const docs = JSON.parse(docsContent);
106+
107+
// Build the new SDK Reference groups
108+
const groupMap = new Map(); // group name -> pages array
109+
110+
const addToGroup = (groupName, pages) => {
111+
if (!groupName || pages.length === 0) return;
112+
if (!groupMap.has(groupName)) {
113+
groupMap.set(groupName, []);
114+
}
115+
groupMap.get(groupName).push(...pages);
116+
};
117+
118+
if (sdkFiles.functions?.length > 0 && categoryMap.functions) {
119+
addToGroup(
120+
categoryMap.functions,
121+
sdkFiles.functions.map((file) => `sdk-docs/functions/${file}`)
122+
);
123+
}
124+
125+
if (sdkFiles.interfaces?.length > 0 && categoryMap.interfaces) {
126+
addToGroup(
127+
categoryMap.interfaces,
128+
sdkFiles.interfaces.map((file) => `sdk-docs/interfaces/${file}`)
129+
);
130+
}
131+
132+
if (sdkFiles.classes?.length > 0 && categoryMap.classes) {
133+
addToGroup(
134+
categoryMap.classes,
135+
sdkFiles.classes.map((file) => `sdk-docs/classes/${file}`)
136+
);
137+
}
138+
139+
if (sdkFiles["type-aliases"]?.length > 0 && categoryMap["type-aliases"]) {
140+
addToGroup(
141+
categoryMap["type-aliases"],
142+
sdkFiles["type-aliases"].map((file) => `sdk-docs/type-aliases/${file}`)
143+
);
144+
}
145+
146+
// Convert map to array of nested groups for SDK Reference
147+
const sdkReferencePages = Array.from(groupMap.entries()).map(
148+
([groupName, pages]) => ({
149+
group: groupName,
150+
pages: pages.sort(), // Sort pages alphabetically within each group
151+
})
152+
);
153+
154+
console.debug(
155+
`SDK Reference pages: ${JSON.stringify(sdkReferencePages, null, 2)}`
156+
);
157+
158+
// Navigate to: Developers tab -> SDK group -> SDK Reference group
159+
const developersTab = docs.navigation.tabs.find(
160+
(tab) => tab.tab === "Developers"
161+
);
162+
163+
if (!developersTab) {
164+
console.error("Could not find 'Developers' tab in docs.json");
165+
process.exit(1);
166+
}
167+
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");
170+
171+
if (!sdkGroup) {
172+
console.error("Could not find 'SDK' group in Developers tab");
173+
process.exit(1);
174+
}
175+
176+
// Find SDK Reference within SDK's pages (it's a nested group object)
177+
const sdkRefIndex = sdkGroup.pages.findIndex(
178+
(page) => typeof page === "object" && page.group === "SDK Reference"
179+
);
180+
181+
if (sdkRefIndex === -1) {
182+
console.error("Could not find 'SDK Reference' group in SDK");
183+
process.exit(1);
184+
}
185+
186+
// Update the SDK Reference pages with our generated groups
187+
sdkGroup.pages[sdkRefIndex] = {
188+
group: "SDK Reference",
189+
icon: "brackets-curly",
190+
pages: sdkReferencePages,
191+
};
192+
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+
202+
// Write updated docs.json
203+
console.log(`Writing updated docs.json to ${docsJsonPath}...`);
204+
fs.writeFileSync(docsJsonPath, JSON.stringify(docs, null, 2) + "\n", "utf8");
205+
206+
console.log("Successfully updated docs.json");
207+
}
208+
209+
function main() {
210+
const { target } = parseArgs();
211+
212+
console.log(`Source: ${DOCS_SOURCE_PATH}`);
213+
console.log(`Target: ${target}`);
214+
215+
// Validate source exists
216+
if (
217+
!fs.existsSync(DOCS_SOURCE_PATH) ||
218+
!fs.statSync(DOCS_SOURCE_PATH).isDirectory()
219+
) {
220+
console.error(`Error: docs directory does not exist: ${DOCS_SOURCE_PATH}`);
221+
console.error("Have you run 'npm run create-docs' first?");
222+
process.exit(1);
223+
}
224+
225+
// Validate target exists and looks like a mintlify-docs repo
226+
if (!fs.existsSync(target) || !fs.statSync(target).isDirectory()) {
227+
console.error(`Error: target directory does not exist: ${target}`);
228+
process.exit(1);
229+
}
230+
231+
const docsJsonPath = path.join(target, "docs.json");
232+
if (!fs.existsSync(docsJsonPath)) {
233+
console.error(
234+
`Error: docs.json not found in ${target}. Is this a mintlify-docs repo?`
235+
);
236+
process.exit(1);
237+
}
238+
239+
try {
240+
// Remove the existing sdk-docs directory
241+
const sdkDocsTarget = path.join(target, "sdk-docs");
242+
if (fs.existsSync(sdkDocsTarget)) {
243+
console.log(`Removing existing sdk-docs directory...`);
244+
fs.rmSync(sdkDocsTarget, { recursive: true, force: true });
245+
}
246+
247+
// Copy the docs directory to the target
248+
console.log(`Copying docs to ${sdkDocsTarget}...`);
249+
fs.cpSync(DOCS_SOURCE_PATH, sdkDocsTarget, { recursive: true });
250+
251+
// Scan the sdk-docs directory
252+
const sdkFiles = scanSdkDocs(sdkDocsTarget);
253+
console.debug(`SDK files: ${JSON.stringify(sdkFiles, null, 2)}`);
254+
255+
// Update the docs.json file
256+
updateDocsJson(target, sdkFiles);
257+
258+
console.log("\n✅ Successfully copied SDK docs to local mintlify-docs repo");
259+
console.log(`\nTo preview the docs, run 'mintlify dev' in ${target}`);
260+
} catch (e) {
261+
console.error(`Error: Failed to copy docs: ${e}`);
262+
process.exit(1);
263+
}
264+
}
265+
266+
main();

scripts/mintlify-post-processing/push-to-docs-repo.js

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,7 @@ function updateDocsJson(repoDir, sdkFiles) {
5858
const docsContent = fs.readFileSync(docsJsonPath, "utf8");
5959
const docs = JSON.parse(docsContent);
6060

61-
// Find the "SDK Reference" tab
62-
const sdkTabIndex = docs.navigation.tabs.findIndex(
63-
(tab) => tab.tab === "SDK Reference"
64-
);
65-
let sdkTab = docs.navigation.tabs[sdkTabIndex];
66-
67-
if (sdkTabIndex === -1) {
68-
console.log(
69-
"Could not find 'SDK Reference' tab in docs.json. Creating it..."
70-
);
71-
sdkTab = {
72-
tab: "SDK Reference",
73-
groups: [],
74-
};
75-
}
76-
77-
// Update the groups - merge categories that map to the same group name
61+
// Build the new SDK Reference groups
7862
const groupMap = new Map(); // group name -> pages array
7963

8064
const addToGroup = (groupName, pages) => {
@@ -113,43 +97,62 @@ function updateDocsJson(repoDir, sdkFiles) {
11397
);
11498
}
11599

116-
// Convert map to array of groups
117-
const newGroups = Array.from(groupMap.entries()).map(
100+
// Convert map to array of nested groups for SDK Reference
101+
const sdkReferencePages = Array.from(groupMap.entries()).map(
118102
([groupName, pages]) => ({
119103
group: groupName,
120104
pages: pages.sort(), // Sort pages alphabetically within each group
121105
})
122106
);
123107

124-
const newGroupNames = new Set(newGroups.map((group) => group.group));
125-
const preservedGroups = [];
126-
let insertionIndex;
108+
console.debug(
109+
`SDK Reference pages: ${JSON.stringify(sdkReferencePages, null, 2)}`
110+
);
127111

128-
for (const existingGroup of sdkTab.groups ?? []) {
129-
if (newGroupNames.has(existingGroup.group)) {
130-
if (insertionIndex === undefined) {
131-
insertionIndex = preservedGroups.length;
132-
}
133-
continue;
134-
}
135-
preservedGroups.push(existingGroup);
112+
// Navigate to: Developers tab -> SDK group -> SDK Reference group
113+
const developersTab = docs.navigation.tabs.find(
114+
(tab) => tab.tab === "Developers"
115+
);
116+
117+
if (!developersTab) {
118+
console.error("Could not find 'Developers' tab in docs.json");
119+
process.exit(1);
136120
}
137121

138-
const finalGroups = [...preservedGroups];
139-
const targetIndex = insertionIndex ?? finalGroups.length;
140-
finalGroups.splice(targetIndex, 0, ...newGroups);
141-
sdkTab.groups = finalGroups;
122+
// Find the SDK group (it's a top-level group in the Developers tab)
123+
const sdkGroup = developersTab.groups.find((g) => g.group === "SDK");
142124

143-
if (sdkTabIndex === -1) {
144-
docs.navigation.tabs.push(sdkTab);
145-
} else {
146-
docs.navigation.tabs[sdkTabIndex] = sdkTab;
125+
if (!sdkGroup) {
126+
console.error("Could not find 'SDK' group in Developers tab");
127+
process.exit(1);
147128
}
148129

149-
console.debug(
150-
`New groups for docs.json: ${JSON.stringify(newGroups, null, 2)}`
130+
// Find SDK Reference within SDK's pages (it's a nested group object)
131+
const sdkRefIndex = sdkGroup.pages.findIndex(
132+
(page) => typeof page === "object" && page.group === "SDK Reference"
151133
);
152134

135+
if (sdkRefIndex === -1) {
136+
console.error("Could not find 'SDK Reference' group in SDK");
137+
process.exit(1);
138+
}
139+
140+
// Update the SDK Reference pages with our generated groups
141+
sdkGroup.pages[sdkRefIndex] = {
142+
group: "SDK Reference",
143+
icon: "brackets-curly",
144+
pages: sdkReferencePages,
145+
};
146+
147+
// Remove the old standalone "SDK Reference" tab if it exists
148+
const oldSdkTabIndex = docs.navigation.tabs.findIndex(
149+
(tab) => tab.tab === "SDK Reference"
150+
);
151+
if (oldSdkTabIndex !== -1) {
152+
console.log("Removing old standalone 'SDK Reference' tab...");
153+
docs.navigation.tabs.splice(oldSdkTabIndex, 1);
154+
}
155+
153156
// Write updated docs.json
154157
console.log(`Writing updated docs.json to ${docsJsonPath}...`);
155158
fs.writeFileSync(docsJsonPath, JSON.stringify(docs, null, 2) + "\n", "utf8");

src/client.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface Base44Client {
9090
/** {@link AppLogsModule | App logs module} for tracking app usage. */
9191
appLogs: AppLogsModule;
9292
/**
93-
* Analytics module for tracking app usage.
93+
* {@link AnalyticsModule | Analytics module} for tracking app usage.
9494
* @internal
9595
*/
9696
analytics: AnalyticsModule;

0 commit comments

Comments
 (0)