From c35b45f0e894008b12f7d690835dafb141340023 Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Wed, 14 Aug 2024 15:54:44 +0100 Subject: [PATCH 1/4] chore: add ts support --- docusaurus.config.js => docusaurus.config.ts | 8 ++- package.json | 8 ++- sidebar_community.js => sidebar_community.ts | 0 sidebar_docs.js => sidebar_docs.ts | 4 +- src/pages/{benchmarks.js => benchmarks.tsx} | 15 +++-- src/pages/{index.js => index.tsx} | 2 +- tsconfig.json | 9 +++ yarn.lock | 69 ++++++++++++++++++++ 8 files changed, 101 insertions(+), 14 deletions(-) rename docusaurus.config.js => docusaurus.config.ts (96%) rename sidebar_community.js => sidebar_community.ts (100%) rename sidebar_docs.js => sidebar_docs.ts (98%) rename src/pages/{benchmarks.js => benchmarks.tsx} (57%) rename src/pages/{index.js => index.tsx} (99%) create mode 100644 tsconfig.json diff --git a/docusaurus.config.js b/docusaurus.config.ts similarity index 96% rename from docusaurus.config.js rename to docusaurus.config.ts index f33d792..1fc23e1 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.ts @@ -1,7 +1,9 @@ const math = require('remark-math') const katex = require('rehype-katex') +import { Config } from "@docusaurus/types"; +import type * as Preset from "@docusaurus/preset-classic"; -const config = { +const config: Config = { title: 'Rapier', tagline: 'Fast 2D and 3D physics engine for the Rust programming language.', url: 'https://rapier.rs', @@ -142,7 +144,7 @@ const config = { ], // copyright: `Copyright © ${new Date().getFullYear()} Dimforge EURL. Website built with Docusaurus.`, }, - }, + } satisfies Preset.ThemeConfig, plugins: [ [ '@docusaurus/plugin-content-docs', @@ -174,7 +176,7 @@ const config = { theme: { customCss: require.resolve('./src/css/custom.css'), }, - }, + } satisfies Preset.Options, ], ], stylesheets: [ diff --git a/package.json b/package.json index 414626a..e9df4d1 100644 --- a/package.json +++ b/package.json @@ -37,5 +37,11 @@ "last 1 safari version" ] }, - "packageManager": "yarn@4.3.1" + "packageManager": "yarn@4.3.1", + "devDependencies": { + "@docusaurus/module-type-aliases": "^3.5.2", + "@docusaurus/tsconfig": "^3.5.2", + "@docusaurus/types": "^3.5.2", + "typescript": "^5.5.4" + } } diff --git a/sidebar_community.js b/sidebar_community.ts similarity index 100% rename from sidebar_community.js rename to sidebar_community.ts diff --git a/sidebar_docs.js b/sidebar_docs.ts similarity index 98% rename from sidebar_docs.js rename to sidebar_docs.ts index d64c18d..0716052 100644 --- a/sidebar_docs.js +++ b/sidebar_docs.ts @@ -1,6 +1,6 @@ -let template = { +const template = { '': [ 'user_guides/templates_injected/getting_started', 'user_guides/templates_injected/getting_started_bevy', @@ -23,7 +23,7 @@ let template = { ] }; -let specialized_guides = { +const specialized_guides = { 'Rust': [ 'user_guides/rust/getting_started', 'user_guides/rust/introduction_to_nalgebra', diff --git a/src/pages/benchmarks.js b/src/pages/benchmarks.tsx similarity index 57% rename from src/pages/benchmarks.js rename to src/pages/benchmarks.tsx index 788b750..46b9b52 100644 --- a/src/pages/benchmarks.js +++ b/src/pages/benchmarks.tsx @@ -4,18 +4,19 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; function iframeLoaded() { if (typeof document !== 'undefined') { - var iFrameID = document.getElementById('bench-iframe'); - if (iFrameID) { - let newHeight = (iFrameID.contentWindow.document.body.scrollHeight + 100) + "px"; - if (iFrameID.height != newHeight) - iFrameID.height = newHeight; - } + const iFrameID = document.getElementById('bench-iframe'); + if (!(iFrameID instanceof HTMLIFrameElement)) + throw new Error(`Expected e to be an HTMLIFrameElement, was ${iFrameID && iFrameID.constructor && iFrameID.constructor.name || iFrameID}`); + + const newHeight = (iFrameID.contentWindow.document.body.scrollHeight + 100) + "px"; + if (iFrameID.height != newHeight) + iFrameID.height = newHeight; } } function Benchmarks() { const context = useDocusaurusContext(); - const {siteConfig = {}} = context; + const {siteConfig} = context; const benchUrl = "/benchmarks3d/index.html"; setInterval(function(){ iframeLoaded(); }, 3000); diff --git a/src/pages/index.js b/src/pages/index.tsx similarity index 99% rename from src/pages/index.js rename to src/pages/index.tsx index dce2d97..935bb3f 100644 --- a/src/pages/index.js +++ b/src/pages/index.tsx @@ -108,7 +108,7 @@ function Feature({ imageUrl, title, description }) { function Home() { const context = useDocusaurusContext(); - const { siteConfig = {} } = context; + const { siteConfig } = context; return ( ": + version: 5.5.4 + resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin::version=5.5.4&hash=379a07" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 10c0/73409d7b9196a5a1217b3aaad929bf76294d3ce7d6e9766dd880ece296ee91cf7d7db6b16c6c6c630ee5096eccde726c0ef17c7dfa52b01a243e57ae1f09ef07 + languageName: node + linkType: hard + "undici-types@npm:~5.26.4": version: 5.26.5 resolution: "undici-types@npm:5.26.5" From b9920d7007442e5b06fbf7170044f81bc6a5cd3d Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Wed, 14 Aug 2024 15:56:17 +0100 Subject: [PATCH 2/4] chore: update VS Code extensions and settings --- .vscode/extensions.json | 8 ++++++++ .vscode/settings.json | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..bc1aa04 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode", + "davidanson.vscode-markdownlint", + "unifiedjs.vscode-mdx", + "dbaeumer.vscode-eslint" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c41c617 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "markdownlint.config": { + "no-inline-html": false, + "link-image-reference-definitions": false, + "fenced-code-language": false, + } +} From e16f9595cab302fd6f9024cd571a3a5c8986a756 Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Wed, 14 Aug 2024 16:15:12 +0100 Subject: [PATCH 3/4] chore: update .prettierrc with new formatting options --- .prettierrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..c24c22a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,12 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "useTabs": true, + "singleQuote": false, + "semi": true, + "bracketSameLine": false, + "bracketSpacing": true, + "jsxSingleQuote": false, + "quoteProps": "as-needed", + "endOfLine": "lf" +} From 6becdfcafed73d172ff7dcfa4f19e80fc277aba8 Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Thu, 15 Aug 2024 15:23:42 +0100 Subject: [PATCH 4/4] fix: update error message in benchmarks.tsx --- src/pages/benchmarks.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/benchmarks.tsx b/src/pages/benchmarks.tsx index 46b9b52..77dd0df 100644 --- a/src/pages/benchmarks.tsx +++ b/src/pages/benchmarks.tsx @@ -6,7 +6,7 @@ function iframeLoaded() { if (typeof document !== 'undefined') { const iFrameID = document.getElementById('bench-iframe'); if (!(iFrameID instanceof HTMLIFrameElement)) - throw new Error(`Expected e to be an HTMLIFrameElement, was ${iFrameID && iFrameID.constructor && iFrameID.constructor.name || iFrameID}`); + throw new Error(`Expected iFrameID to be an HTMLIFrameElement, was ${iFrameID && iFrameID.constructor && iFrameID.constructor.name || iFrameID}`); const newHeight = (iFrameID.contentWindow.document.body.scrollHeight + 100) + "px"; if (iFrameID.height != newHeight)