/
sdds
/
plasma
Обзор
Документация
Войти
/
sdds
/
plasma
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
dev
scaffold/template-docs/docusaurus.config.js
199 строк
7 KB
Ilya Bychek
fix(docs): Change proptable and check types after json generate
17 июн 2024, 11:23
17 июн 2024, 11:23
d9b90c7
Код
Авторство
О чём код?
import { themes } from 'prism-react-renderer'; import path from 'path'; import { withCustomConfig } from 'react-docgen-typescript'; import fg from 'fast-glob'; // eslint-disable-next-line @typescript-eslint/no-var-requires const pckgJson = require('./package.json'); // eslint-disable-next-line @typescript-eslint/no-var-requires const versionsArchived = require('./versionsArchived.json'); const { VERSION_NAME, PREFIX } = process.env; const defaultUrl = PREFIX ? `/${PREFIX}/{{url}}/` : '/{{url}}/'; const baseUrl = VERSION_NAME ? `/versions/${VERSION_NAME}/` : defaultUrl; /** @type {import('@docusaurus/types').DocusaurusConfig} */ const config = { title: '{{name}}', tagline: 'Дизайн-система для разработки современных приложений.', url: 'https://plasma.sberdevices.ru/', baseUrl, onBrokenLinks: 'warn', onBrokenMarkdownLinks: 'warn', favicon: 'images/favicon.png', organizationName: 'Salute-Developers', trailingSlash: true, themes: ['@docusaurus/theme-live-codeblock'], themeConfig: { navbar: { title: '{{ upperCase name }}', items: [ { type: 'docsVersionDropdown', position: 'right', dropdownActiveClassDisabled: false, dropdownItemsAfter: [ ...Object.entries(versionsArchived).map(([versionName, versionUrl]) => ({ label: versionName, href: versionUrl, })), ], }, { href: 'https://github.com/salute-developers/plasma', label: 'GitHub', position: 'right', }, ], }, footer: { style: 'light', links: [ { title: 'Сообщество', items: [ { label: 'GitHub', href: 'https://github.com/salute-developers/plasma', }, ], }, ], }, prism: { theme: themes.github, darkTheme: themes.dracula, }, colorMode: { // "light" | "dark" defaultMode: 'light', // Hides the switch in the navbar // Useful if you want to support a single color mode disableSwitch: false, // Whether to use the prefers-color-scheme media-query, // using user system preferences, instead of the hardcoded defaultMode. respectPrefersColorScheme: true, }, }, presets: [ [ '@docusaurus/preset-classic', { docs: { routeBasePath: '/', sidebarPath: require.resolve('./sidebars.js'), editUrl: 'https://github.com/salute-developers/plasma/blob/master/website/{{name}}-docs/', versions: { current: { label: pckgJson.dependencies['@salutejs/{{name}}'], path: '', }, }, }, theme: { customCss: require.resolve('./src/css/custom.css'), }, }, ], ], plugins: [ function docgenPlugin() { // Плагин генерации документации return { name: 'docusaurus-plugin-react-docgen-typescript', async loadContent() { // Загрузка компонентов для документации return withCustomConfig('./tsconfig.json', { shouldExtractLiteralValuesFromEnum: true, shouldRemoveUndefinedFromOptional: true, propFilter: () => { // Функция обрезки типов return true; }, }).parse( await fg([ '../../packages/{{name}}/src/**/*.{ts,tsx}', '!../../packages/{{name}}/src/**/*.test.*', ]), ); }, configureWebpack(config) { return { resolve: { alias: { '@docgen': path.join( config.resolve.alias['@generated'], 'docusaurus-plugin-react-docgen-typescript', 'default', ), }, }, }; }, async contentLoaded({ content, actions }) { // Генерация массива типов const names = []; content .filter((module) => { const result = !names.includes(module.displayName) && /^[A-Z]/.test(module.displayName) && (module.props || module.description) && module.displayName !== 'Default'; if (result) { names.push(module.displayName); return true; } return false; }) .forEach(async (component) => actions.createData( `${component.displayName}.json`, JSON.stringify({ props: Object.entries(component.props).reduce( (acc, [key, { declarations, ...rest }]) => ({ ...acc, [key]: rest, }), {}, ), description: component.description, }), ), ); }, }; }, function aliasPlugin() { return { name: 'docusaurus-plugin-aliases', configureWebpack() { return { resolve: { symlinks: false, alias: { react: path.resolve(__dirname, 'node_modules', 'react'), 'react-dom': path.resolve(__dirname, 'node_modules', 'react-dom'), 'styled-components': path.resolve(__dirname, 'node_modules', 'styled-components'), }, }, }; }, }; }, ], markdown: { format: 'detect', mdx1Compat: { comments: true, admonitions: true, headingIds: true, }, }, }; export default config;