From a70d6e0c9ef9850bb3fff9be10c795a65031c0fc Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 26 Jan 2026 08:27:47 +0100 Subject: [PATCH 1/2] Use oxfmt --- .github/workflows/ci.yml | 5 +- .../docs/contributing/api-modelling.mdx | 16 +- .../contributing/api-module-structure.mdx | 4 +- .../docs/contributing/code-generation.mdx | 5 +- .../docs/contributing/getting-started.mdx | 4 +- .../contributing/module-type-structure.mdx | 23 +- docs/content/docs/contributing/testing.mdx | 5 +- docs/content/docs/index.mdx | 12 +- package-lock.json | 231 ++++++++++++++++++ package.json | 44 ++-- 10 files changed, 277 insertions(+), 72 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d623da6..7a3b9ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,9 @@ jobs: - name: Install dependencies run: npm ci + - name: Check formatting + run: npm run format:check + - name: Rebuild ReScript code run: npm run build @@ -81,4 +84,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v4 \ No newline at end of file + uses: actions/deploy-pages@v4 diff --git a/docs/content/docs/contributing/api-modelling.mdx b/docs/content/docs/contributing/api-modelling.mdx index b0f33ff..5313035 100644 --- a/docs/content/docs/contributing/api-modelling.mdx +++ b/docs/content/docs/contributing/api-modelling.mdx @@ -112,11 +112,7 @@ String(unsafeConversation(t)) } ` - + We can now use `FillStyle.decode` to get the actual value of the `fillStyle` property. And use `FillStyle.fromString`, `FillStyle.fromCanvasGradient`, and `FillStyle.fromCanvasPattern` to set the value. @@ -135,11 +131,5 @@ switch ctx.fillStyle->FillStyle.decode { } ``` - -Try and use `decoded` and `decode` as conventions for the type and function -names. + +Try and use `decoded` and `decode` as conventions for the type and function names. diff --git a/docs/content/docs/contributing/api-module-structure.mdx b/docs/content/docs/contributing/api-module-structure.mdx index d872494..45781e8 100644 --- a/docs/content/docs/contributing/api-module-structure.mdx +++ b/docs/content/docs/contributing/api-module-structure.mdx @@ -51,8 +51,8 @@ type htmlSpanElement = { ``` ```ReScript diff --git a/docs/content/docs/contributing/code-generation.mdx b/docs/content/docs/contributing/code-generation.mdx index d54e9b2..98d6d85 100644 --- a/docs/content/docs/contributing/code-generation.mdx +++ b/docs/content/docs/contributing/code-generation.mdx @@ -64,10 +64,7 @@ interfaceHierarchy = [ name: "Temp", entries: [ enums(["WebGLPowerPreference"]), - dictionaries([ - "ImageBitmapRenderingContextSettings", - "WebGLContextAttributes", - ]), + dictionaries(["ImageBitmapRenderingContextSettings", "WebGLContextAttributes"]), ], opens: [], }, diff --git a/docs/content/docs/contributing/getting-started.mdx b/docs/content/docs/contributing/getting-started.mdx index 762e8d6..42cf96d 100644 --- a/docs/content/docs/contributing/getting-started.mdx +++ b/docs/content/docs/contributing/getting-started.mdx @@ -7,8 +7,8 @@ slug: "01-getting-started" import { Aside } from "@astrojs/starlight/components"; The [WebAPI](https://developer.mozilla.org/en-US/docs/Web/API) are vast and ever-growing. We need your help to make them better. diff --git a/docs/content/docs/contributing/module-type-structure.mdx b/docs/content/docs/contributing/module-type-structure.mdx index 904696d..bb5b58f 100644 --- a/docs/content/docs/contributing/module-type-structure.mdx +++ b/docs/content/docs/contributing/module-type-structure.mdx @@ -45,9 +45,9 @@ open DOMAPI // A concrete type for \`T.t\` is passed later using the \`include\` keyword. module Impl = (T: { type t }) => { -/** +/\*_ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLElement/focus) -*/ +_/ @send external focus: (T.t, ~options: focusOptions=?) => unit = "focus" @@ -56,11 +56,7 @@ external focus: (T.t, ~options: focusOptions=?) => unit = "focus" include Impl({ type t = htmlElement }) `; - + export const buttonModule = ` open DOMAPI @@ -70,17 +66,12 @@ include HTMLElement.Impl({ type t = htmlButtonElement }) // Add additional methods specific to HTMLButtonElement: -/** +/\*_ Returns whether a form will validate when it is submitted, without having to submit it. -[Read more on MDN]( - https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/checkValidity) -*/ +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/checkValidity) +_/ @send external checkValidity: htmlButtonElement => bool = "checkValidity" `; - + diff --git a/docs/content/docs/contributing/testing.mdx b/docs/content/docs/contributing/testing.mdx index d5c61a2..a5e8eaf 100644 --- a/docs/content/docs/contributing/testing.mdx +++ b/docs/content/docs/contributing/testing.mdx @@ -36,9 +36,8 @@ npm test If any of the existing tests have different ouput JavaScript, you will see a diff in the output and the test will fail. ## Why add tests? diff --git a/docs/content/docs/index.mdx b/docs/content/docs/index.mdx index 15d4e4a..20b01cf 100644 --- a/docs/content/docs/index.mdx +++ b/docs/content/docs/index.mdx @@ -27,18 +27,10 @@ Install the package using your favorite package manager: - + - + diff --git a/package-lock.json b/package-lock.json index d33aaf9..29da748 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@astrojs/starlight": "0.37.4", "astro": "^5.10.1", "micromark": "^4.0.1", + "oxfmt": "^0.26.0", "prettier": "^3.3.3", "prettier-plugin-astro": "^0.14.1", "rescript": ">=12.0.0 <13", @@ -1235,6 +1236,118 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/@oxfmt/darwin-arm64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/darwin-arm64/-/darwin-arm64-0.26.0.tgz", + "integrity": "sha512-AAGc+8CffkiWeVgtWf4dPfQwHEE5c/j/8NWH7VGVxxJRCZFdmWcqCXprvL2H6qZFewvDLrFbuSPRCqYCpYGaTQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oxfmt/darwin-x64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/darwin-x64/-/darwin-x64-0.26.0.tgz", + "integrity": "sha512-xFx5ijCTjw577wJvFlZEMmKDnp3HSCcbYdCsLRmC5i3TZZiDe9DEYh3P46uqhzj8BkEw1Vm1ZCWdl48aEYAzvQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oxfmt/linux-arm64-gnu": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-arm64-gnu/-/linux-arm64-gnu-0.26.0.tgz", + "integrity": "sha512-GubkQeQT5d3B/Jx/IiR7NMkSmXrCZcVI0BPh1i7mpFi8HgD1hQ/LbhiBKAMsMqs5bbugdQOgBEl8bOhe8JhW1g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxfmt/linux-arm64-musl": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-arm64-musl/-/linux-arm64-musl-0.26.0.tgz", + "integrity": "sha512-OEypUwK69bFPj+aa3/LYCnlIUPgoOLu//WNcriwpnWNmt47808Ht7RJSg+MNK8a7pSZHpXJ5/E6CRK/OTwFdaQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxfmt/linux-x64-gnu": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-x64-gnu/-/linux-x64-gnu-0.26.0.tgz", + "integrity": "sha512-xO6iEW2bC6ZHyOTPmPWrg/nM6xgzyRPaS84rATy6F8d79wz69LdRdJ3l/PXlkqhi7XoxhvX4ExysA0Nf10ZZEQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxfmt/linux-x64-musl": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-x64-musl/-/linux-x64-musl-0.26.0.tgz", + "integrity": "sha512-Z3KuZFC+MIuAyFCXBHY71kCsdRq1ulbsbzTe71v+hrEv7zVBn6yzql+/AZcgfIaKzWO9OXNuz5WWLWDmVALwow==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxfmt/win32-arm64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/win32-arm64/-/win32-arm64-0.26.0.tgz", + "integrity": "sha512-3zRbqwVWK1mDhRhTknlQFpRFL9GhEB5GfU6U7wawnuEwpvi39q91kJ+SRJvJnhyPCARkjZBd1V8XnweN5IFd1g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@oxfmt/win32-x64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/win32-x64/-/win32-x64-0.26.0.tgz", + "integrity": "sha512-m8TfIljU22i9UEIkD+slGPifTFeaCwIUfxszN3E6ABWP1KQbtwSw9Ak0TdoikibvukF/dtbeyG3WW63jv9DnEg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@pagefind/darwin-arm64": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@pagefind/darwin-arm64/-/darwin-arm64-1.3.0.tgz", @@ -4978,6 +5091,35 @@ "regex-recursion": "^6.0.2" } }, + "node_modules/oxfmt": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/oxfmt/-/oxfmt-0.26.0.tgz", + "integrity": "sha512-UDD1wFNwfeorMm2ZY0xy1KRAAvJ5NjKBfbDmiMwGP7baEHTq65cYpC0aPP+BGHc8weXUbSZaK8MdGyvuRUvS4Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinypool": "2.0.0" + }, + "bin": { + "oxfmt": "bin/oxfmt" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/sponsors/Boshen" + }, + "optionalDependencies": { + "@oxfmt/darwin-arm64": "0.26.0", + "@oxfmt/darwin-x64": "0.26.0", + "@oxfmt/linux-arm64-gnu": "0.26.0", + "@oxfmt/linux-arm64-musl": "0.26.0", + "@oxfmt/linux-x64-gnu": "0.26.0", + "@oxfmt/linux-x64-musl": "0.26.0", + "@oxfmt/win32-arm64": "0.26.0", + "@oxfmt/win32-x64": "0.26.0" + } + }, "node_modules/p-limit": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.2.0.tgz", @@ -6094,6 +6236,16 @@ "url": "https://github.com/sponsors/SuperchupuDev" } }, + "node_modules/tinypool": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-2.0.0.tgz", + "integrity": "sha512-/RX9RzeH2xU5ADE7n2Ykvmi9ED3FBGPAjw9u3zucrNNaEBIO0HPSYgL0NT7+3p147ojeSdaVu08F6hjpv31HJg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^20.0.0 || >=22.0.0" + } + }, "node_modules/trim-lines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", @@ -7352,6 +7504,62 @@ "vfile": "^6.0.0" } }, + "@oxfmt/darwin-arm64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/darwin-arm64/-/darwin-arm64-0.26.0.tgz", + "integrity": "sha512-AAGc+8CffkiWeVgtWf4dPfQwHEE5c/j/8NWH7VGVxxJRCZFdmWcqCXprvL2H6qZFewvDLrFbuSPRCqYCpYGaTQ==", + "dev": true, + "optional": true + }, + "@oxfmt/darwin-x64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/darwin-x64/-/darwin-x64-0.26.0.tgz", + "integrity": "sha512-xFx5ijCTjw577wJvFlZEMmKDnp3HSCcbYdCsLRmC5i3TZZiDe9DEYh3P46uqhzj8BkEw1Vm1ZCWdl48aEYAzvQ==", + "dev": true, + "optional": true + }, + "@oxfmt/linux-arm64-gnu": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-arm64-gnu/-/linux-arm64-gnu-0.26.0.tgz", + "integrity": "sha512-GubkQeQT5d3B/Jx/IiR7NMkSmXrCZcVI0BPh1i7mpFi8HgD1hQ/LbhiBKAMsMqs5bbugdQOgBEl8bOhe8JhW1g==", + "dev": true, + "optional": true + }, + "@oxfmt/linux-arm64-musl": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-arm64-musl/-/linux-arm64-musl-0.26.0.tgz", + "integrity": "sha512-OEypUwK69bFPj+aa3/LYCnlIUPgoOLu//WNcriwpnWNmt47808Ht7RJSg+MNK8a7pSZHpXJ5/E6CRK/OTwFdaQ==", + "dev": true, + "optional": true + }, + "@oxfmt/linux-x64-gnu": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-x64-gnu/-/linux-x64-gnu-0.26.0.tgz", + "integrity": "sha512-xO6iEW2bC6ZHyOTPmPWrg/nM6xgzyRPaS84rATy6F8d79wz69LdRdJ3l/PXlkqhi7XoxhvX4ExysA0Nf10ZZEQ==", + "dev": true, + "optional": true + }, + "@oxfmt/linux-x64-musl": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/linux-x64-musl/-/linux-x64-musl-0.26.0.tgz", + "integrity": "sha512-Z3KuZFC+MIuAyFCXBHY71kCsdRq1ulbsbzTe71v+hrEv7zVBn6yzql+/AZcgfIaKzWO9OXNuz5WWLWDmVALwow==", + "dev": true, + "optional": true + }, + "@oxfmt/win32-arm64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/win32-arm64/-/win32-arm64-0.26.0.tgz", + "integrity": "sha512-3zRbqwVWK1mDhRhTknlQFpRFL9GhEB5GfU6U7wawnuEwpvi39q91kJ+SRJvJnhyPCARkjZBd1V8XnweN5IFd1g==", + "dev": true, + "optional": true + }, + "@oxfmt/win32-x64": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/@oxfmt/win32-x64/-/win32-x64-0.26.0.tgz", + "integrity": "sha512-m8TfIljU22i9UEIkD+slGPifTFeaCwIUfxszN3E6ABWP1KQbtwSw9Ak0TdoikibvukF/dtbeyG3WW63jv9DnEg==", + "dev": true, + "optional": true + }, "@pagefind/darwin-arm64": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@pagefind/darwin-arm64/-/darwin-arm64-1.3.0.tgz", @@ -9925,6 +10133,23 @@ "regex-recursion": "^6.0.2" } }, + "oxfmt": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/oxfmt/-/oxfmt-0.26.0.tgz", + "integrity": "sha512-UDD1wFNwfeorMm2ZY0xy1KRAAvJ5NjKBfbDmiMwGP7baEHTq65cYpC0aPP+BGHc8weXUbSZaK8MdGyvuRUvS4Q==", + "dev": true, + "requires": { + "@oxfmt/darwin-arm64": "0.26.0", + "@oxfmt/darwin-x64": "0.26.0", + "@oxfmt/linux-arm64-gnu": "0.26.0", + "@oxfmt/linux-arm64-musl": "0.26.0", + "@oxfmt/linux-x64-gnu": "0.26.0", + "@oxfmt/linux-x64-musl": "0.26.0", + "@oxfmt/win32-arm64": "0.26.0", + "@oxfmt/win32-x64": "0.26.0", + "tinypool": "2.0.0" + } + }, "p-limit": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.2.0.tgz", @@ -10728,6 +10953,12 @@ "picomatch": "^4.0.3" } }, + "tinypool": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-2.0.0.tgz", + "integrity": "sha512-/RX9RzeH2xU5ADE7n2Ykvmi9ED3FBGPAjw9u3zucrNNaEBIO0HPSYgL0NT7+3p147ojeSdaVu08F6hjpv31HJg==", + "dev": true + }, "trim-lines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", diff --git a/package.json b/package.json index 0b6217b..13e0aad 100644 --- a/package.json +++ b/package.json @@ -2,53 +2,55 @@ "name": "@rescript/webapi", "version": "0.1.0", "description": "Experimental successor to [rescript-webapi](https://github.com/TheSpyder/rescript-webapi)", + "keywords": [ + "dom", + "fetch", + "mdn", + "rescript", + "webapi" + ], "homepage": "https://rescript-lang.github.io/experimental-rescript-webapi/", "bugs": "https://github.com/rescript-lang/experimental-rescript-webapi/issues", - "repository": { - "type": "git", - "url": "git+https://github.com/rescript-lang/experimental-rescript-webapi.git" - }, + "license": "MIT", "author": { "name": "Florian Verdonck" }, "maintainers": [ "Florian Verdonck (https://github.com/nojaf)" ], - "keywords": [ - "rescript", - "webapi", - "mdn", - "dom", - "fetch" - ], + "repository": { + "type": "git", + "url": "git+https://github.com/rescript-lang/experimental-rescript-webapi.git" + }, "files": [ "rescript.json", "src/**/*.res" ], "type": "module", + "publishConfig": { + "access": "public", + "provenance": true + }, "scripts": { "test": "node tests/index.js", "build": "rescript", - "format": "rescript format && prettier --write ./tests/index.js ./package.json ./docs/pages", + "format": "rescript format && oxfmt ./tests/index.js ./package.json ./docs/pages", + "format:check": "rescript format --check && oxfmt ./tests/index.js ./package.json ./docs/pages --check", "docs": "astro dev", "prebuild:docs": "node docs/llm.js", "build:docs": "astro build" }, - "license": "MIT", - "publishConfig": { - "access": "public", - "provenance": true - }, - "peerDependencies": { - "rescript": ">=12.0.0 <13" - }, "devDependencies": { "@astrojs/starlight": "0.37.4", "astro": "^5.10.1", "micromark": "^4.0.1", + "oxfmt": "^0.26.0", "prettier": "^3.3.3", "prettier-plugin-astro": "^0.14.1", - "sharp": "^0.34.0", + "rescript": ">=12.0.0 <13", + "sharp": "^0.34.0" + }, + "peerDependencies": { "rescript": ">=12.0.0 <13" } } From b60f5437ba5e7e3cc055796b7f49ccbcee895daa Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 26 Jan 2026 08:33:17 +0100 Subject: [PATCH 2/2] Still use prettier for astro files --- docs/llm.js | 144 +++++++++++++++++++++--------------------- docs/styles/fonts.css | 42 ++++++------ docs/styles/theme.css | 3 +- docs/utils.js | 65 +++++++++---------- package.json | 4 +- 5 files changed, 126 insertions(+), 132 deletions(-) diff --git a/docs/llm.js b/docs/llm.js index 7cb0bb7..582db23 100644 --- a/docs/llm.js +++ b/docs/llm.js @@ -6,102 +6,102 @@ import fs from "node:fs/promises"; const execAsync = promisify(exec); const bins = await import( - path.join(import.meta.dirname, "../node_modules/rescript/cli/common/bins.js") + path.join(import.meta.dirname, "../node_modules/rescript/cli/common/bins.js") ); const rescriptTools = bins["rescript_tools_exe"]; if (!rescriptTools) { - throw new Error("rescript-tools not found"); + throw new Error("rescript-tools not found"); } async function getDocJson(filePath) { - try { - const command = `${rescriptTools} doc "${filePath}"`; - const options = { maxBuffer: 10 * 1024 * 1024 }; - const { stdout, stderr } = await execAsync(command, options); - - if (stderr) { - throw new Error(`Error executing command for ${filePath}: ${stderr}`); - } - - return JSON.parse(stdout); - } catch (error) { - throw new Error(`Failed to get documentation JSON for ${filePath}:`, error); + try { + const command = `${rescriptTools} doc "${filePath}"`; + const options = { maxBuffer: 10 * 1024 * 1024 }; + const { stdout, stderr } = await execAsync(command, options); + + if (stderr) { + throw new Error(`Error executing command for ${filePath}: ${stderr}`); } + + return JSON.parse(stdout); + } catch (error) { + throw new Error(`Failed to get documentation JSON for ${filePath}:`, error); + } } async function processFile(filePath) { - const json = await getDocJson(filePath); - - const moduleName = "WebAPI." + json.name.replace("-WebAPI", ""); - - const types = []; - const functions = []; - - function mkType(item) { - let description = ""; - if (item.docstrings.length > 0) { - description = "\n Description: " + item.docstrings.join("\n"); - } - let fields = ""; - if (item.detail && item.detail.kind === "record") { - fields = - "\n Fields:\n" + - item.detail.items - .map((field) => { - let fieldDoc = ""; - if (field.docstrings.length > 0) { - fieldDoc = " - " + field.docstrings.join(" "); - } - return ` - ${field.name}: ${field.signature}${fieldDoc}`; - }) - .join("\n"); - } - return `- ${item.signature}${description}${fields}`; - } + const json = await getDocJson(filePath); - function mkFunction(item) { - let description = ""; - if (item.docstrings.length > 0) { - description = "\n Description: " + item.docstrings.join("\n"); - } - return `- ${item.signature}${description}`; - } + const moduleName = "WebAPI." + json.name.replace("-WebAPI", ""); - for (const item of json.items) { - switch (item.kind) { - case "type": - types.push(mkType(item)); - break; - case "value": - functions.push(mkFunction(item)); - break; - } - } + const types = []; + const functions = []; - let typeString = ""; - if (types.length > 0) { - typeString = "\n\nTypes:\n\n" + types.join("\n\n"); + function mkType(item) { + let description = ""; + if (item.docstrings.length > 0) { + description = "\n Description: " + item.docstrings.join("\n"); } + let fields = ""; + if (item.detail && item.detail.kind === "record") { + fields = + "\n Fields:\n" + + item.detail.items + .map((field) => { + let fieldDoc = ""; + if (field.docstrings.length > 0) { + fieldDoc = " - " + field.docstrings.join(" "); + } + return ` - ${field.name}: ${field.signature}${fieldDoc}`; + }) + .join("\n"); + } + return `- ${item.signature}${description}${fields}`; + } - let functionString = ""; - if (functions.length > 0) { - functionString = "\n\nFunctions:\n\n" + functions.join("\n\n"); + function mkFunction(item) { + let description = ""; + if (item.docstrings.length > 0) { + description = "\n Description: " + item.docstrings.join("\n"); + } + return `- ${item.signature}${description}`; + } + + for (const item of json.items) { + switch (item.kind) { + case "type": + types.push(mkType(item)); + break; + case "value": + functions.push(mkFunction(item)); + break; } + } + + let typeString = ""; + if (types.length > 0) { + typeString = "\n\nTypes:\n\n" + types.join("\n\n"); + } - return `File: ${json.source.filepath} + let functionString = ""; + if (functions.length > 0) { + functionString = "\n\nFunctions:\n\n" + functions.join("\n\n"); + } + + return `File: ${json.source.filepath} Module: ${moduleName}${typeString}${functionString} `; } -const pattern = "../src/**/*.res" +const pattern = "../src/**/*.res"; const files = []; -for await (const file of fs.glob(pattern, { recursive: true, cwd: import.meta.dirname })) { - files.push(path.join(import.meta.dirname, file)); +for await (const file of fs.glob(pattern, { recursive: true, cwd: import.meta.dirname })) { + files.push(path.join(import.meta.dirname, file)); } files.sort(); -const pages = await Promise.all(files.map(processFile)) +const pages = await Promise.all(files.map(processFile)); const packageJson = await fs.readFile(path.join(import.meta.dirname, "../package.json"), "utf-8"); let version = JSON.parse(packageJson).version; const sha = await execAsync("git rev-parse --short HEAD").then(({ stdout }) => stdout.trim()); @@ -111,7 +111,7 @@ const header = `Experimental Rescript WebAPI Documentation ${fullVersion} This is the API documentation for the experimental WebAPI module version ${fullVersion}. More information can be found on https://rescript-lang.github.io/experimental-rescript-webapi/ -` +`; const content = pages.join("\n---\n\n"); await fs.writeFile(path.join(import.meta.dirname, "public/llm.txt"), header + content); -console.log("Generated llm.txt"); \ No newline at end of file +console.log("Generated llm.txt"); diff --git a/docs/styles/fonts.css b/docs/styles/fonts.css index 36ebbcb..1b3d817 100644 --- a/docs/styles/fonts.css +++ b/docs/styles/fonts.css @@ -8,9 +8,9 @@ font-weight: 700; font-style: normal; font-display: swap; - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, - U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, - U+FEFF, U+FFFD; + unicode-range: + U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, + U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } /* latin */ @@ -23,9 +23,9 @@ font-weight: 400; font-style: italic; font-display: swap; - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, - U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, - U+FEFF, U+FFFD; + unicode-range: + U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, + U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } /* latin */ @@ -38,9 +38,9 @@ font-weight: 500; font-style: normal; font-display: swap; - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, - U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, - U+FEFF, U+FFFD; + unicode-range: + U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, + U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } /* latin */ @@ -53,9 +53,9 @@ font-weight: 600; font-style: normal; font-display: swap; - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, - U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, - U+FEFF, U+FFFD; + unicode-range: + U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, + U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } /* latin */ @@ -68,9 +68,9 @@ font-weight: 400; font-style: normal; font-display: swap; - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, - U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, - U+FEFF, U+FFFD; + unicode-range: + U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, + U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } /* ROBOTO MONO */ @@ -85,9 +85,9 @@ local("Roboto Mono"), local("RobotoMono-Regular"), url("../fonts/roboto-mono-400.woff2") format("woff2"); - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, - U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, - U+FEFF, U+FFFD; + unicode-range: + U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, + U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } /* latin */ @@ -100,7 +100,7 @@ local("Roboto Mono Bold"), local("RobotoMono-Bold"), url("../fonts/roboto-mono-700.woff2") format("woff2"); - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, - U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, - U+FEFF, U+FFFD; + unicode-range: + U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, + U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } diff --git a/docs/styles/theme.css b/docs/styles/theme.css index ef4a208..413e55d 100644 --- a/docs/styles/theme.css +++ b/docs/styles/theme.css @@ -30,7 +30,8 @@ https://github.com/rescript-lang/rescript-lang.org/blob/4e4f9520f6fc7a0376db82a0 } } -body, #starlight__sidebar { +body, +#starlight__sidebar { --scrollbar-track-background: #222222; --scrollbar-track-border: #4a4a4a; --scrollbar-thumb-background: #686868; diff --git a/docs/utils.js b/docs/utils.js index 9c5a9a2..ed3711a 100644 --- a/docs/utils.js +++ b/docs/utils.js @@ -36,10 +36,7 @@ function mapTypeModules(parentModuleLink, file) { .map((file) => { const filePath = path.join(folder, file); - const moduleName = file - .replace("$", "") - .replace(folder, "") - .replace(".res", ""); + const moduleName = file.replace("$", "").replace(folder, "").replace(".res", ""); const apiRouteParameter = toKebabCase(moduleName); const link = createTypeModuleLink(parentModuleLink, moduleName); const typeName = moduleName[0].toLocaleLowerCase() + moduleName.slice(1); @@ -72,15 +69,14 @@ function mapRescriptFile(srcDir, file) { } const srcDir = path.resolve(process.cwd(), "src"); -export const apiModules = readdirSync(srcDir).filter(f => f.endsWith(".res")).map(r => mapRescriptFile(srcDir, r)); +export const apiModules = readdirSync(srcDir) + .filter((f) => f.endsWith(".res")) + .map((r) => mapRescriptFile(srcDir, r)); async function getRescriptDoc(absoluteFilePath) { - const { stdout, stderr } = await execAsync( - `rescript-tools doc ${absoluteFilePath}`, - { - maxBuffer: 1024 * 1024 * 10, // Increase buffer to 10 MB - }, - ); + const { stdout, stderr } = await execAsync(`rescript-tools doc ${absoluteFilePath}`, { + maxBuffer: 1024 * 1024 * 10, // Increase buffer to 10 MB + }); if (stderr) { throw new Error(stderr); } @@ -94,8 +90,7 @@ export async function getDoc(absoluteFilePath) { .filter((item) => item.kind === "type") .sort((a, b) => a.name.localeCompare(b.name)) .map((type) => { - const documentation = - type.docstrings && micromark(type.docstrings.join("\n")); + const documentation = type.docstrings && micromark(type.docstrings.join("\n")); return { name: type.name, documentation, @@ -116,8 +111,7 @@ export async function getDoc(absoluteFilePath) { .filter((item) => item.kind === "value") .sort((a, b) => a.name.localeCompare(b.name)) .map((value) => { - const documentation = - value.docstrings && micromark(value.docstrings.join("\n")); + const documentation = value.docstrings && micromark(value.docstrings.join("\n")); return { name: value.name, documentation, @@ -150,24 +144,23 @@ function trimRescriptOutput(output) { } const testDir = path.resolve(process.cwd(), "tests"); -export const testFiles = - readdirSync(testDir, { recursive: true }) - .filter(f => f.endsWith(".res")) - .map(tf => { - const sourcePath = path.join(testDir, tf); - const source = readFileSync(sourcePath, "utf-8"); - const outputPath = sourcePath.replace(".res", ".js"); - const output = readFileSync(outputPath, "utf-8"); - - const parts = tf.split(path.sep); - const name = parts[parts.length - 1].replace("__tests.res", ""); - - return { - sourcePath: sourcePath.replace(testDir,""), - source, - output: trimRescriptOutput(output), - outputPath: outputPath.replace(testDir,""), - name, - }; - }) - .sort((a, b) => a.name.localeCompare(b.name)); \ No newline at end of file +export const testFiles = readdirSync(testDir, { recursive: true }) + .filter((f) => f.endsWith(".res")) + .map((tf) => { + const sourcePath = path.join(testDir, tf); + const source = readFileSync(sourcePath, "utf-8"); + const outputPath = sourcePath.replace(".res", ".js"); + const output = readFileSync(outputPath, "utf-8"); + + const parts = tf.split(path.sep); + const name = parts[parts.length - 1].replace("__tests.res", ""); + + return { + sourcePath: sourcePath.replace(testDir, ""), + source, + output: trimRescriptOutput(output), + outputPath: outputPath.replace(testDir, ""), + name, + }; + }) + .sort((a, b) => a.name.localeCompare(b.name)); diff --git a/package.json b/package.json index 13e0aad..870a099 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ "scripts": { "test": "node tests/index.js", "build": "rescript", - "format": "rescript format && oxfmt ./tests/index.js ./package.json ./docs/pages", - "format:check": "rescript format --check && oxfmt ./tests/index.js ./package.json ./docs/pages --check", + "format": "rescript format && oxfmt ./tests/index.js ./package.json ./docs && prettier --write ./docs/pages", + "format:check": "rescript format --check && oxfmt ./tests/index.js ./package.json ./docs --check && prettier --check ./docs/pages", "docs": "astro dev", "prebuild:docs": "node docs/llm.js", "build:docs": "astro build"