From 22abe8d286964a9e65c7efcc353a375c074689a3 Mon Sep 17 00:00:00 2001 From: Alvin Bryan Date: Fri, 18 Oct 2024 16:17:00 +0100 Subject: [PATCH] V3 is aliiiiiiiive --- website/babel.config.js | 3 - website/clean-generated-docs.js | 6 +- ...usaurus.config.js => docusaurus.config.ts} | 54 +- website/package.json | 50 +- website/remote-content/edge-proxy.js | 6 +- website/remote-content/sdks.js | 12 +- website/remote-content/sdks.test.js | 2 +- website/remote-content/shared.js | 23 +- website/{sidebars.js => sidebars.ts} | 11 +- website/yarn.lock | 6250 ++++------------- 10 files changed, 1278 insertions(+), 5139 deletions(-) delete mode 100644 website/babel.config.js rename website/{docusaurus.config.js => docusaurus.config.ts} (97%) rename website/{sidebars.js => sidebars.ts} (99%) diff --git a/website/babel.config.js b/website/babel.config.js deleted file mode 100644 index 0adade1fb9..0000000000 --- a/website/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - presets: [require.resolve('@docusaurus/core/lib/babel/preset')], -}; diff --git a/website/clean-generated-docs.js b/website/clean-generated-docs.js index 116a15ae60..7158a09617 100644 --- a/website/clean-generated-docs.js +++ b/website/clean-generated-docs.js @@ -15,7 +15,9 @@ // the bits that are specific to the generation source we use, and make the docs // easier to use. In particular, removing the leading `/ushosted` is likely to // save us loooots of questions. -const replace = require('replace-in-file'); +const replaceInFileSync = require('replace-in-file'); + +console.log(replaceInFileSync); const options = { files: 'docs/reference/api/**/*.api.mdx', @@ -27,4 +29,4 @@ const options = { to: ['', '""', '"path":['], }; -replace(options); +replaceInFileSync(options); diff --git a/website/docusaurus.config.js b/website/docusaurus.config.ts similarity index 97% rename from website/docusaurus.config.js rename to website/docusaurus.config.ts index 8748a3c049..a552f015cc 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.ts @@ -1,5 +1,8 @@ -const { sdks } = require('./remote-content/sdks'); -const { docs: edgeAndProxy } = require('./remote-content/edge-proxy'); +import type { Config } from '@docusaurus/types'; + +import { sdks } from './remote-content/sdks'; +import { docs as edgeAndProxy } from './remote-content/edge-proxy'; +import pluginNpm2Yarn from '@docusaurus/remark-plugin-npm2yarn'; // for a given redirect object, modify it's `from` property such that for every // path that doesn't start with `/docs/`, a corresponding path that _does_ start @@ -38,8 +41,8 @@ const addDocsRoutePrefix = ({ from, ...rest }) => { from: addDocs(from), }; }; -/** @type {import('@docusaurus/types').DocusaurusConfig} */ -module.exports = { + +const config: Config = { title: 'Unleash', tagline: 'The enterprise ready feature flag service', url: 'https://docs.getunleash.io', @@ -169,20 +172,20 @@ module.exports = { }, ], }, - prism: { - theme: require('prism-react-renderer/themes/oceanicNext'), - additionalLanguages: [ - 'csharp', - 'dart', - 'http', - 'java', - 'kotlin', - 'php', - 'ruby', - 'rust', - 'swift', - ], - }, + // prism: { + // theme: require("prism-react-renderer/themes/oceanicNext"), + // additionalLanguages: [ + // "csharp", + // "dart", + // "http", + // "java", + // "kotlin", + // "php", + // "ruby", + // "rust", + // "swift", + // ], + // }, languageTabs: [ { highlight: 'bash', @@ -290,22 +293,15 @@ module.exports = { '@docusaurus/preset-classic', { docs: { - sidebarPath: require.resolve('./sidebars.js'), // Please change this to your repo. editUrl: 'https://github.com/Unleash/unleash/edit/main/website/', routeBasePath: '/', - remarkPlugins: [ - [ - require('@docusaurus/remark-plugin-npm2yarn'), - { sync: true }, - ], - ], - docLayoutComponent: '@theme/DocPage', + remarkPlugins: [[pluginNpm2Yarn, { sync: true }]], docItemComponent: '@theme/ApiItem', }, theme: { - customCss: require.resolve('./src/css/custom.css'), + customCss: './src/css/custom.css', }, googleAnalytics: { trackingID: 'UA-134882379-1', @@ -928,5 +924,7 @@ module.exports = { defer: true, }, ], - clientModules: [require.resolve('./global.js')], + clientModules: ['./global.js'], }; + +export default config; diff --git a/website/package.json b/website/package.json index 29cda1b2dd..e2c5e0753f 100644 --- a/website/package.json +++ b/website/package.json @@ -20,41 +20,25 @@ "test": "NODE_ENV=test node --trace-warnings ../node_modules/.bin/jest remote-content" }, "dependencies": { - "@docusaurus/core": "2.3.1", - "@docusaurus/plugin-client-redirects": "2.3.1", - "@docusaurus/plugin-google-analytics": "2.3.1", - "@docusaurus/preset-classic": "2.3.1", + "@docusaurus/core": "^3.5.2", + "@docusaurus/plugin-client-redirects": "^3.5.2", + "@docusaurus/plugin-google-analytics": "^3.5.2", + "@docusaurus/preset-classic": "^3.5.2", "@docusaurus/remark-plugin-npm2yarn": "2.3.1", - "@docusaurus/theme-mermaid": "2.3.1", - "@mdx-js/react": "1.6.22", + "@docusaurus/theme-mermaid": "^3.5.2", + "@mdx-js/react": "^3.0.1", "@svgr/webpack": "8.1.0", "browserslist": "^4.16.5", - "docusaurus-plugin-openapi-docs": "4.1.0", - "docusaurus-plugin-remote-content": "^3.1.0", - "docusaurus-theme-openapi-docs": "2.0.0-beta.2", + "docusaurus-plugin-openapi-docs": "^4.1.0", + "docusaurus-plugin-remote-content": "^4.0.0", + "docusaurus-theme-openapi-docs": "^4.1.0", "git-url-parse": "^14.0.0", "plugin-image-zoom": "flexanalytics/plugin-image-zoom", + "prism-react-renderer": "^2.4.0", "prism-svelte": "^0.5.0", - "react": "18.3.1", - "react-dom": "18.3.1", - "url-loader": "4.1.1" - }, - "resolutions": { - "axios": "^0.28.0", - "async": "^3.2.4", - "trim": "^1.0.0", - "got": "^13.0.0", - "glob-parent": "^6.0.0", - "browserslist": "^4.16.5", - "set-value": "^4.0.1", - "ansi-regex": "^5.0.1", - "nth-check": "^2.0.1", - "minimatch": "^5.0.0", - "decode-uri-component": "^0.4.0", - "qs": "^6.9.7", - "ws": "^8.18.0", - "semver": "^7.5.3", - "joi": "17.13.3" + "react": "^18.3.1", + "react-dom": "^18.3.1", + "replace-in-file": "^8.2.0" }, "browserslist": { "production": [ @@ -70,12 +54,10 @@ }, "devDependencies": { "@babel/core": "7.25.8", - "@docusaurus/module-type-aliases": "2.3.1", + "@docusaurus/module-type-aliases": "^3.5.2", + "@docusaurus/types": "^3.5.2", "@tsconfig/docusaurus": "2.0.3", - "babel-loader": "9.1.3", - "enhanced-resolve": "5.17.1", - "react-router": "6.26.2", - "replace-in-file": "7.2.0", + "@types/react": "^18.3.11", "typescript": "5.4.5" }, "packageManager": "yarn@4.4.1" diff --git a/website/remote-content/edge-proxy.js b/website/remote-content/edge-proxy.js index df21dbce8c..4e1d642376 100644 --- a/website/remote-content/edge-proxy.js +++ b/website/remote-content/edge-proxy.js @@ -1,10 +1,10 @@ -const { +import { enrich, mapObject, modifyContent, getRepoData, getUrls, -} = require('./shared'); +} from './shared'; const DOCS = mapObject(enrich)({ 'unleash-proxy': { @@ -46,7 +46,7 @@ const modifyContent2 = modifyContent({ getAdditionalAdmonitions: getAdmonitions, }); -module.exports.docs = { +export const docs = { urls: getUrls(DOCS), modifyContent: modifyContent2, }; diff --git a/website/remote-content/sdks.js b/website/remote-content/sdks.js index 18684f2361..0db083a666 100644 --- a/website/remote-content/sdks.js +++ b/website/remote-content/sdks.js @@ -1,9 +1,9 @@ -const { +import { enrichAdditional, modifyContent, getRepoData, getUrls, -} = require('./shared'); +} from './shared'; // Type definitions // @@ -44,9 +44,9 @@ const serverSideSdks = { 'unleash-client-ruby': { sidebarName: 'Ruby', }, - 'unleash-client-rust': { - sidebarName: 'Rust', - }, + // 'unleash-client-rust': { + // sidebarName: 'Rust', + // }, 'unleash-client-dotnet': { sidebarName: '.NET', slugName: 'dotnet', @@ -117,7 +117,7 @@ const modifyContent2 = modifyContent({ getAdditionalAdmonitions: getAdmonitions, }); -module.exports.sdks = { +export const sdks = { urls: getUrls(SDKS), modifyContent: modifyContent2, }; diff --git a/website/remote-content/sdks.test.js b/website/remote-content/sdks.test.js index 8140cfc823..6b23ae85d9 100644 --- a/website/remote-content/sdks.test.js +++ b/website/remote-content/sdks.test.js @@ -1,4 +1,4 @@ -const { docs } = require('./edge-proxy'); +import { docs } from './edge-proxy'; test('Should get all sub pages', () => { expect(docs.urls).toStrictEqual([ diff --git a/website/remote-content/shared.js b/website/remote-content/shared.js index 184ceb9ff0..eec004cfc6 100644 --- a/website/remote-content/shared.js +++ b/website/remote-content/shared.js @@ -1,9 +1,9 @@ -const path = require('path'); +import path from 'node:path'; -module.exports.mapObject = (fn) => (o) => +export const mapObject = (fn) => (o) => Object.fromEntries(Object.entries(o).map(fn)); -module.exports.enrichAdditional = +export const enrichAdditional = (additionalProperties) => ([repoName, repoData]) => { const repoUrl = `https://github.com/Unleash/${repoName}`; @@ -17,9 +17,10 @@ module.exports.enrichAdditional = { ...repoData, repoUrl, slugName, branch, ...additionalProperties }, ]; }; -module.exports.enrich = module.exports.enrichAdditional({}); -module.exports.getRepoData = (documents) => (filename) => { +export const enrich = enrichAdditional({}); + +export const getRepoData = (documents) => (filename) => { const repoName = filename.split('/')[0]; const repoData = documents[repoName]; @@ -80,7 +81,7 @@ const replaceLinks = ({ content, repo }) => { .replaceAll(imageSrcLink, replaceImageSrcLink); }; -module.exports.modifyContent = +export const modifyContent = ({ getRepoDataFn, filePath = () => {}, @@ -128,11 +129,15 @@ module.exports.modifyContent = content: `--- title: ${subpage?.sidebarName ?? data.sidebarName} slug: ${processedSlug} -custom_edit_url: ${data.repoUrl}/edit/${data.branch}/${subpage ? subpageKey : 'README.md'} +custom_edit_url: ${data.repoUrl}/edit/${data.branch}/${ + subpage ? subpageKey : 'README.md' + } --- :::info Generated content -This document was generated from ${subpage ? subpageKey : 'README.md'} in the [${data.sidebarName} GitHub repository](${data.repoUrl}). +This document was generated from ${ + subpage ? subpageKey : 'README.md' + } in the [${data.sidebarName} GitHub repository](${data.repoUrl}). ::: ${additionalAdmonitions} @@ -152,7 +157,7 @@ This content was generated on