Skip to content

Commit b60f543

Browse files
committed
Still use prettier for astro files
1 parent a70d6e0 commit b60f543

5 files changed

Lines changed: 126 additions & 132 deletions

File tree

docs/llm.js

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,102 +6,102 @@ import fs from "node:fs/promises";
66
const execAsync = promisify(exec);
77

88
const bins = await import(
9-
path.join(import.meta.dirname, "../node_modules/rescript/cli/common/bins.js")
9+
path.join(import.meta.dirname, "../node_modules/rescript/cli/common/bins.js")
1010
);
1111
const rescriptTools = bins["rescript_tools_exe"];
1212

1313
if (!rescriptTools) {
14-
throw new Error("rescript-tools not found");
14+
throw new Error("rescript-tools not found");
1515
}
1616

1717
async function getDocJson(filePath) {
18-
try {
19-
const command = `${rescriptTools} doc "${filePath}"`;
20-
const options = { maxBuffer: 10 * 1024 * 1024 };
21-
const { stdout, stderr } = await execAsync(command, options);
22-
23-
if (stderr) {
24-
throw new Error(`Error executing command for ${filePath}: ${stderr}`);
25-
}
26-
27-
return JSON.parse(stdout);
28-
} catch (error) {
29-
throw new Error(`Failed to get documentation JSON for ${filePath}:`, error);
18+
try {
19+
const command = `${rescriptTools} doc "${filePath}"`;
20+
const options = { maxBuffer: 10 * 1024 * 1024 };
21+
const { stdout, stderr } = await execAsync(command, options);
22+
23+
if (stderr) {
24+
throw new Error(`Error executing command for ${filePath}: ${stderr}`);
3025
}
26+
27+
return JSON.parse(stdout);
28+
} catch (error) {
29+
throw new Error(`Failed to get documentation JSON for ${filePath}:`, error);
30+
}
3131
}
3232

3333
async function processFile(filePath) {
34-
const json = await getDocJson(filePath);
35-
36-
const moduleName = "WebAPI." + json.name.replace("-WebAPI", "");
37-
38-
const types = [];
39-
const functions = [];
40-
41-
function mkType(item) {
42-
let description = "";
43-
if (item.docstrings.length > 0) {
44-
description = "\n Description: " + item.docstrings.join("\n");
45-
}
46-
let fields = "";
47-
if (item.detail && item.detail.kind === "record") {
48-
fields =
49-
"\n Fields:\n" +
50-
item.detail.items
51-
.map((field) => {
52-
let fieldDoc = "";
53-
if (field.docstrings.length > 0) {
54-
fieldDoc = " - " + field.docstrings.join(" ");
55-
}
56-
return ` - ${field.name}: ${field.signature}${fieldDoc}`;
57-
})
58-
.join("\n");
59-
}
60-
return `- ${item.signature}${description}${fields}`;
61-
}
34+
const json = await getDocJson(filePath);
6235

63-
function mkFunction(item) {
64-
let description = "";
65-
if (item.docstrings.length > 0) {
66-
description = "\n Description: " + item.docstrings.join("\n");
67-
}
68-
return `- ${item.signature}${description}`;
69-
}
36+
const moduleName = "WebAPI." + json.name.replace("-WebAPI", "");
7037

71-
for (const item of json.items) {
72-
switch (item.kind) {
73-
case "type":
74-
types.push(mkType(item));
75-
break;
76-
case "value":
77-
functions.push(mkFunction(item));
78-
break;
79-
}
80-
}
38+
const types = [];
39+
const functions = [];
8140

82-
let typeString = "";
83-
if (types.length > 0) {
84-
typeString = "\n\nTypes:\n\n" + types.join("\n\n");
41+
function mkType(item) {
42+
let description = "";
43+
if (item.docstrings.length > 0) {
44+
description = "\n Description: " + item.docstrings.join("\n");
8545
}
46+
let fields = "";
47+
if (item.detail && item.detail.kind === "record") {
48+
fields =
49+
"\n Fields:\n" +
50+
item.detail.items
51+
.map((field) => {
52+
let fieldDoc = "";
53+
if (field.docstrings.length > 0) {
54+
fieldDoc = " - " + field.docstrings.join(" ");
55+
}
56+
return ` - ${field.name}: ${field.signature}${fieldDoc}`;
57+
})
58+
.join("\n");
59+
}
60+
return `- ${item.signature}${description}${fields}`;
61+
}
8662

87-
let functionString = "";
88-
if (functions.length > 0) {
89-
functionString = "\n\nFunctions:\n\n" + functions.join("\n\n");
63+
function mkFunction(item) {
64+
let description = "";
65+
if (item.docstrings.length > 0) {
66+
description = "\n Description: " + item.docstrings.join("\n");
67+
}
68+
return `- ${item.signature}${description}`;
69+
}
70+
71+
for (const item of json.items) {
72+
switch (item.kind) {
73+
case "type":
74+
types.push(mkType(item));
75+
break;
76+
case "value":
77+
functions.push(mkFunction(item));
78+
break;
9079
}
80+
}
81+
82+
let typeString = "";
83+
if (types.length > 0) {
84+
typeString = "\n\nTypes:\n\n" + types.join("\n\n");
85+
}
9186

92-
return `File: ${json.source.filepath}
87+
let functionString = "";
88+
if (functions.length > 0) {
89+
functionString = "\n\nFunctions:\n\n" + functions.join("\n\n");
90+
}
91+
92+
return `File: ${json.source.filepath}
9393
Module: ${moduleName}${typeString}${functionString}
9494
`;
9595
}
9696

97-
const pattern = "../src/**/*.res"
97+
const pattern = "../src/**/*.res";
9898
const files = [];
99-
for await (const file of fs.glob(pattern, { recursive: true, cwd: import.meta.dirname })) {
100-
files.push(path.join(import.meta.dirname, file));
99+
for await (const file of fs.glob(pattern, { recursive: true, cwd: import.meta.dirname })) {
100+
files.push(path.join(import.meta.dirname, file));
101101
}
102102
files.sort();
103103

104-
const pages = await Promise.all(files.map(processFile))
104+
const pages = await Promise.all(files.map(processFile));
105105
const packageJson = await fs.readFile(path.join(import.meta.dirname, "../package.json"), "utf-8");
106106
let version = JSON.parse(packageJson).version;
107107
const sha = await execAsync("git rev-parse --short HEAD").then(({ stdout }) => stdout.trim());
@@ -111,7 +111,7 @@ const header = `Experimental Rescript WebAPI Documentation ${fullVersion}
111111
This is the API documentation for the experimental WebAPI module version ${fullVersion}.
112112
More information can be found on https://rescript-lang.github.io/experimental-rescript-webapi/
113113
114-
`
114+
`;
115115
const content = pages.join("\n---\n\n");
116116
await fs.writeFile(path.join(import.meta.dirname, "public/llm.txt"), header + content);
117-
console.log("Generated llm.txt");
117+
console.log("Generated llm.txt");

docs/styles/fonts.css

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
font-weight: 700;
99
font-style: normal;
1010
font-display: swap;
11-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
12-
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
13-
U+FEFF, U+FFFD;
11+
unicode-range:
12+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,
13+
U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
1414
}
1515

1616
/* latin */
@@ -23,9 +23,9 @@
2323
font-weight: 400;
2424
font-style: italic;
2525
font-display: swap;
26-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
27-
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
28-
U+FEFF, U+FFFD;
26+
unicode-range:
27+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,
28+
U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
2929
}
3030

3131
/* latin */
@@ -38,9 +38,9 @@
3838
font-weight: 500;
3939
font-style: normal;
4040
font-display: swap;
41-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
42-
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
43-
U+FEFF, U+FFFD;
41+
unicode-range:
42+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,
43+
U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
4444
}
4545

4646
/* latin */
@@ -53,9 +53,9 @@
5353
font-weight: 600;
5454
font-style: normal;
5555
font-display: swap;
56-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
57-
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
58-
U+FEFF, U+FFFD;
56+
unicode-range:
57+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,
58+
U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
5959
}
6060

6161
/* latin */
@@ -68,9 +68,9 @@
6868
font-weight: 400;
6969
font-style: normal;
7070
font-display: swap;
71-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
72-
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
73-
U+FEFF, U+FFFD;
71+
unicode-range:
72+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,
73+
U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
7474
}
7575

7676
/* ROBOTO MONO */
@@ -85,9 +85,9 @@
8585
local("Roboto Mono"),
8686
local("RobotoMono-Regular"),
8787
url("../fonts/roboto-mono-400.woff2") format("woff2");
88-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
89-
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
90-
U+FEFF, U+FFFD;
88+
unicode-range:
89+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,
90+
U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
9191
}
9292

9393
/* latin */
@@ -100,7 +100,7 @@
100100
local("Roboto Mono Bold"),
101101
local("RobotoMono-Bold"),
102102
url("../fonts/roboto-mono-700.woff2") format("woff2");
103-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
104-
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
105-
U+FEFF, U+FFFD;
103+
unicode-range:
104+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,
105+
U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
106106
}

docs/styles/theme.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ https://github.com/rescript-lang/rescript-lang.org/blob/4e4f9520f6fc7a0376db82a0
3030
}
3131
}
3232

33-
body, #starlight__sidebar {
33+
body,
34+
#starlight__sidebar {
3435
--scrollbar-track-background: #222222;
3536
--scrollbar-track-border: #4a4a4a;
3637
--scrollbar-thumb-background: #686868;

docs/utils.js

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ function mapTypeModules(parentModuleLink, file) {
3636
.map((file) => {
3737
const filePath = path.join(folder, file);
3838

39-
const moduleName = file
40-
.replace("$", "")
41-
.replace(folder, "")
42-
.replace(".res", "");
39+
const moduleName = file.replace("$", "").replace(folder, "").replace(".res", "");
4340
const apiRouteParameter = toKebabCase(moduleName);
4441
const link = createTypeModuleLink(parentModuleLink, moduleName);
4542
const typeName = moduleName[0].toLocaleLowerCase() + moduleName.slice(1);
@@ -72,15 +69,14 @@ function mapRescriptFile(srcDir, file) {
7269
}
7370

7471
const srcDir = path.resolve(process.cwd(), "src");
75-
export const apiModules = readdirSync(srcDir).filter(f => f.endsWith(".res")).map(r => mapRescriptFile(srcDir, r));
72+
export const apiModules = readdirSync(srcDir)
73+
.filter((f) => f.endsWith(".res"))
74+
.map((r) => mapRescriptFile(srcDir, r));
7675

7776
async function getRescriptDoc(absoluteFilePath) {
78-
const { stdout, stderr } = await execAsync(
79-
`rescript-tools doc ${absoluteFilePath}`,
80-
{
81-
maxBuffer: 1024 * 1024 * 10, // Increase buffer to 10 MB
82-
},
83-
);
77+
const { stdout, stderr } = await execAsync(`rescript-tools doc ${absoluteFilePath}`, {
78+
maxBuffer: 1024 * 1024 * 10, // Increase buffer to 10 MB
79+
});
8480
if (stderr) {
8581
throw new Error(stderr);
8682
}
@@ -94,8 +90,7 @@ export async function getDoc(absoluteFilePath) {
9490
.filter((item) => item.kind === "type")
9591
.sort((a, b) => a.name.localeCompare(b.name))
9692
.map((type) => {
97-
const documentation =
98-
type.docstrings && micromark(type.docstrings.join("\n"));
93+
const documentation = type.docstrings && micromark(type.docstrings.join("\n"));
9994
return {
10095
name: type.name,
10196
documentation,
@@ -116,8 +111,7 @@ export async function getDoc(absoluteFilePath) {
116111
.filter((item) => item.kind === "value")
117112
.sort((a, b) => a.name.localeCompare(b.name))
118113
.map((value) => {
119-
const documentation =
120-
value.docstrings && micromark(value.docstrings.join("\n"));
114+
const documentation = value.docstrings && micromark(value.docstrings.join("\n"));
121115
return {
122116
name: value.name,
123117
documentation,
@@ -150,24 +144,23 @@ function trimRescriptOutput(output) {
150144
}
151145

152146
const testDir = path.resolve(process.cwd(), "tests");
153-
export const testFiles =
154-
readdirSync(testDir, { recursive: true })
155-
.filter(f => f.endsWith(".res"))
156-
.map(tf => {
157-
const sourcePath = path.join(testDir, tf);
158-
const source = readFileSync(sourcePath, "utf-8");
159-
const outputPath = sourcePath.replace(".res", ".js");
160-
const output = readFileSync(outputPath, "utf-8");
161-
162-
const parts = tf.split(path.sep);
163-
const name = parts[parts.length - 1].replace("__tests.res", "");
164-
165-
return {
166-
sourcePath: sourcePath.replace(testDir,""),
167-
source,
168-
output: trimRescriptOutput(output),
169-
outputPath: outputPath.replace(testDir,""),
170-
name,
171-
};
172-
})
173-
.sort((a, b) => a.name.localeCompare(b.name));
147+
export const testFiles = readdirSync(testDir, { recursive: true })
148+
.filter((f) => f.endsWith(".res"))
149+
.map((tf) => {
150+
const sourcePath = path.join(testDir, tf);
151+
const source = readFileSync(sourcePath, "utf-8");
152+
const outputPath = sourcePath.replace(".res", ".js");
153+
const output = readFileSync(outputPath, "utf-8");
154+
155+
const parts = tf.split(path.sep);
156+
const name = parts[parts.length - 1].replace("__tests.res", "");
157+
158+
return {
159+
sourcePath: sourcePath.replace(testDir, ""),
160+
source,
161+
output: trimRescriptOutput(output),
162+
outputPath: outputPath.replace(testDir, ""),
163+
name,
164+
};
165+
})
166+
.sort((a, b) => a.name.localeCompare(b.name));

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"scripts": {
3535
"test": "node tests/index.js",
3636
"build": "rescript",
37-
"format": "rescript format && oxfmt ./tests/index.js ./package.json ./docs/pages",
38-
"format:check": "rescript format --check && oxfmt ./tests/index.js ./package.json ./docs/pages --check",
37+
"format": "rescript format && oxfmt ./tests/index.js ./package.json ./docs && prettier --write ./docs/pages",
38+
"format:check": "rescript format --check && oxfmt ./tests/index.js ./package.json ./docs --check && prettier --check ./docs/pages",
3939
"docs": "astro dev",
4040
"prebuild:docs": "node docs/llm.js",
4141
"build:docs": "astro build"

0 commit comments

Comments
 (0)