diff --git a/packages/lexical-list/README.md b/packages/lexical-list/README.md index 2324c66de925..3728e76a1603 100644 --- a/packages/lexical-list/README.md +++ b/packages/lexical-list/README.md @@ -1,4 +1,4 @@ -`@lexical/list` +# `@lexical/list` [![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_list) diff --git a/packages/lexical-website/.gitignore b/packages/lexical-website/.gitignore index 5f2229121262..34291925ae0c 100644 --- a/packages/lexical-website/.gitignore +++ b/packages/lexical-website/.gitignore @@ -8,6 +8,7 @@ .docusaurus .cache-loader /docs/api +/docs/packages # Misc .DS_Store diff --git a/packages/lexical-website/docs/packages/_category_.json b/packages/lexical-website/docs/packages/_category_.json deleted file mode 100644 index 94ed42720de7..000000000000 --- a/packages/lexical-website/docs/packages/_category_.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "label": "Packages", - "position": 4 -} diff --git a/packages/lexical-website/docs/packages/lexical-clipboard.md b/packages/lexical-website/docs/packages/lexical-clipboard.md deleted file mode 100644 index b8ccd62108b2..000000000000 --- a/packages/lexical-website/docs/packages/lexical-clipboard.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/clipboard' ---- - -{@import ../../../lexical-clipboard/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-code.md b/packages/lexical-website/docs/packages/lexical-code.md deleted file mode 100644 index 059d41ca302f..000000000000 --- a/packages/lexical-website/docs/packages/lexical-code.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/code' ---- - -{@import ../../../lexical-code/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-devtools-core.md b/packages/lexical-website/docs/packages/lexical-devtools-core.md deleted file mode 100644 index e649f09270dd..000000000000 --- a/packages/lexical-website/docs/packages/lexical-devtools-core.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/devtools-core' ---- - -{@import ../../../lexical-devtools-core/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-dragon.md b/packages/lexical-website/docs/packages/lexical-dragon.md deleted file mode 100644 index 0f94bb0b9b6c..000000000000 --- a/packages/lexical-website/docs/packages/lexical-dragon.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/dragon' ---- - -{@import ../../../lexical-dragon/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-file.md b/packages/lexical-website/docs/packages/lexical-file.md deleted file mode 100644 index 83c5962a5c37..000000000000 --- a/packages/lexical-website/docs/packages/lexical-file.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/file' ---- - -{@import ../../../lexical-file/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-hashtag.md b/packages/lexical-website/docs/packages/lexical-hashtag.md deleted file mode 100644 index af135d6d6d5d..000000000000 --- a/packages/lexical-website/docs/packages/lexical-hashtag.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/hashtag' ---- - -{@import ../../../lexical-hashtag/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-headless.md b/packages/lexical-website/docs/packages/lexical-headless.md deleted file mode 100644 index 20c35591dfa8..000000000000 --- a/packages/lexical-website/docs/packages/lexical-headless.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/headless' ---- - -{@import ../../../lexical-headless/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-history.md b/packages/lexical-website/docs/packages/lexical-history.md deleted file mode 100644 index ac72a1524000..000000000000 --- a/packages/lexical-website/docs/packages/lexical-history.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/history' ---- - -{@import ../../../lexical-history/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-html.md b/packages/lexical-website/docs/packages/lexical-html.md deleted file mode 100644 index 0ebd9016399e..000000000000 --- a/packages/lexical-website/docs/packages/lexical-html.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/html' ---- - -{@import ../../../lexical-html/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-link.md b/packages/lexical-website/docs/packages/lexical-link.md deleted file mode 100644 index eb748f61c17e..000000000000 --- a/packages/lexical-website/docs/packages/lexical-link.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/link' ---- - -{@import ../../../lexical-link/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-list.md b/packages/lexical-website/docs/packages/lexical-list.md deleted file mode 100644 index f1bda7d938b8..000000000000 --- a/packages/lexical-website/docs/packages/lexical-list.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/list' ---- - -{@import ../../../lexical-list/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-mark.md b/packages/lexical-website/docs/packages/lexical-mark.md deleted file mode 100644 index 33607576a8b4..000000000000 --- a/packages/lexical-website/docs/packages/lexical-mark.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/mark' ---- - -{@import ../../../lexical-mark/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-markdown.md b/packages/lexical-website/docs/packages/lexical-markdown.md deleted file mode 100644 index 8354cc5c9f16..000000000000 --- a/packages/lexical-website/docs/packages/lexical-markdown.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/markdown' ---- - -{@import ../../../lexical-markdown/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-offset.md b/packages/lexical-website/docs/packages/lexical-offset.md deleted file mode 100644 index 44f1e2760015..000000000000 --- a/packages/lexical-website/docs/packages/lexical-offset.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/offset' ---- - -{@import ../../../lexical-offset/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-overflow.md b/packages/lexical-website/docs/packages/lexical-overflow.md deleted file mode 100644 index d79d1b213271..000000000000 --- a/packages/lexical-website/docs/packages/lexical-overflow.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/overflow' ---- - -{@import ../../../lexical-overflow/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-plain-text.md b/packages/lexical-website/docs/packages/lexical-plain-text.md deleted file mode 100644 index 28043e3af05d..000000000000 --- a/packages/lexical-website/docs/packages/lexical-plain-text.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/plain-text' ---- - -{@import ../../../lexical-plain-text/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-react.md b/packages/lexical-website/docs/packages/lexical-react.md deleted file mode 100644 index fd26ef088b6b..000000000000 --- a/packages/lexical-website/docs/packages/lexical-react.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/react' ---- - -{@import ../../../lexical-react/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-rich-text.md b/packages/lexical-website/docs/packages/lexical-rich-text.md deleted file mode 100644 index b38ef264a91c..000000000000 --- a/packages/lexical-website/docs/packages/lexical-rich-text.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/rich-text' ---- - -{@import ../../../lexical-rich-text/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-selection.md b/packages/lexical-website/docs/packages/lexical-selection.md deleted file mode 100644 index e0b47043c5a6..000000000000 --- a/packages/lexical-website/docs/packages/lexical-selection.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/selection' ---- - -{@import ../../../lexical-selection/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-table.md b/packages/lexical-website/docs/packages/lexical-table.md deleted file mode 100644 index 54c258f1e009..000000000000 --- a/packages/lexical-website/docs/packages/lexical-table.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/table' ---- - -{@import ../../../lexical-table/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-text.md b/packages/lexical-website/docs/packages/lexical-text.md deleted file mode 100644 index df9dce9d1943..000000000000 --- a/packages/lexical-website/docs/packages/lexical-text.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/text' ---- - -{@import ../../../lexical-text/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-utils.md b/packages/lexical-website/docs/packages/lexical-utils.md deleted file mode 100644 index 3363ea8d9ebb..000000000000 --- a/packages/lexical-website/docs/packages/lexical-utils.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/utils' ---- - -{@import ../../../lexical-utils/README.md} diff --git a/packages/lexical-website/docs/packages/lexical-yjs.md b/packages/lexical-website/docs/packages/lexical-yjs.md deleted file mode 100644 index 9fc76e814a74..000000000000 --- a/packages/lexical-website/docs/packages/lexical-yjs.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: '' -sidebar_label: '@lexical/yjs' ---- - -{@import ../../../lexical-yjs/README.md} diff --git a/packages/lexical-website/docs/packages/lexical.md b/packages/lexical-website/docs/packages/lexical.md deleted file mode 100644 index e03e7a472b92..000000000000 --- a/packages/lexical-website/docs/packages/lexical.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -sidebar_position: 1 ---- - -# lexical (core) - -This package contains the core library, including the Editor, EditorState, Selection, and core nodes. It also contains logic for the fundamental logic of the library, such as updates and DOM reconciliation. diff --git a/packages/lexical-website/docusaurus.config.js b/packages/lexical-website/docusaurus.config.js index cac524e91447..4b52470cf986 100644 --- a/packages/lexical-website/docusaurus.config.js +++ b/packages/lexical-website/docusaurus.config.js @@ -207,6 +207,21 @@ const config = { onBrokenMarkdownLinks: 'throw', organizationName: 'facebook', plugins: [ + [ + './plugins/package-docs', + /** @type {import('./plugins/package-docs').PackageDocsPluginOptions} */ + { + baseDir: path.resolve(__dirname, '..'), + editUrl: `${GITHUB_REPO_URL}/tree/main/packages/`, + packageFrontMatter: { + lexical: [ + 'sidebar_position: 1', + 'sidebar_label: lexical (core)', + ].join('\n'), + }, + targetDir: path.resolve(__dirname, 'docs/packages'), + }, + ], './plugins/webpack-buffer', ['docusaurus-plugin-typedoc', docusaurusPluginTypedocConfig], async function tailwindcss() { diff --git a/packages/lexical-website/plugins/package-docs/index.js b/packages/lexical-website/plugins/package-docs/index.js new file mode 100644 index 000000000000..7ca7c6cb1441 --- /dev/null +++ b/packages/lexical-website/plugins/package-docs/index.js @@ -0,0 +1,79 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const glob = require('glob'); +// Not using packagesManager since it will cache package.json files +const {PackageMetadata} = require('../../../../scripts/shared/PackageMetadata'); + +/** + * @typedef {Object} PackageDocsPluginOptions + * @property {string} baseDir + * @property {editUrl} editUrl + * @property {string} targetDir + * @property {Record} packageFrontMatter + */ + +/** + * Watch all public monorepo packages/{project}/README.md files and + * copy them to docs/packages/{project}.md + * + * @param {import('@docusaurus/types').LoadContext} context + * @param {PackageDocsPluginOptions} options + * @returns {import('@docusaurus/types').Plugin} + */ +module.exports = async function (context, options) { + return { + getPathsToWatch: () => [`${options.baseDir}/*/{README.md,package.json}`], + loadContent: () => { + fs.mkdirSync(options.targetDir, {recursive: true}); + const oldTargets = new Set( + glob.sync(path.resolve(options.targetDir, '*.md')), + ); + for (const srcPath of glob.sync(`${options.baseDir}/*/README.md`)) { + const jsonPath = path.resolve(path.dirname(srcPath), 'package.json'); + if (!fs.existsSync(jsonPath)) { + continue; + } + const metadata = new PackageMetadata(jsonPath); + if (metadata.isPrivate()) { + continue; + } + const folderName = metadata.getDirectoryName(); + const targetPath = path.resolve(options.targetDir, `${folderName}.md`); + /** @type {string|undefined} */ + const frontMatter = [ + `# Do not edit! Generated from ${path.relative( + path.dirname(targetPath), + srcPath, + )}`, + options.packageFrontMatter[folderName], + `custom_edit_url: ${options.editUrl.replace( + /\/$/, + '', + )}/${folderName}/README.md`, + ] + .filter(Boolean) + .map((s) => s.trim()) + .join('\n'); + fs.writeFileSync( + targetPath, + `---\n${frontMatter}\n---\n\n${fs.readFileSync(srcPath, 'utf-8')}`, + ); + oldTargets.delete(targetPath); + } + for (const oldPath of oldTargets) { + fs.unlinkSync(oldPath); + } + }, + name: 'package-docs', + }; +}; diff --git a/scripts/__tests__/unit/build.test.js b/scripts/__tests__/unit/build.test.js index db2a9c1f413f..ca4631cb88f6 100644 --- a/scripts/__tests__/unit/build.test.js +++ b/scripts/__tests__/unit/build.test.js @@ -93,15 +93,11 @@ describe('public package.json audits (`npm run update-packages` to fix most issu }); describe('documentation audits (`npm run update-packages` to fix most issues)', () => { - const webPkg = packagesManager.getPackageByDirectoryName('lexical-website'); packagesManager.getPublicPackages().forEach((pkg) => { const npmName = pkg.getNpmName(); describe(npmName, () => { const root = pkg.resolve('..', '..'); - [ - pkg.resolve('README.md'), - webPkg.resolve('docs', 'packages', `${pkg.getDirectoryName()}.md`), - ].forEach((docPath) => { + [pkg.resolve('README.md')].forEach((docPath) => { describe(path.relative(root, docPath), () => { it('exists', () => expect(fs.existsSync(docPath)).toBe(true)); if (path.basename(docPath) === 'README.md') { diff --git a/scripts/create-docs.js b/scripts/create-docs.js index fbea3037d362..02ac0c8b1990 100644 --- a/scripts/create-docs.js +++ b/scripts/create-docs.js @@ -12,21 +12,6 @@ const fs = require('fs-extra'); const path = require('node:path'); const {packagesManager} = require('./shared/packagesManager'); -const webPkg = packagesManager.getPackageByDirectoryName('lexical-website'); - -function sidebarTemplate(npmName, readmePath) { - return ( - ` ---- -title: '' -sidebar_label: '${npmName}' ---- - -{@import ${readmePath}} -`.trim() + '\n' - ); -} - function readmeTemplate(npmName, directoryName, description) { const apiModuleName = directoryName.replace(/-/g, '_'); return ( @@ -40,17 +25,12 @@ ${description} ); } -function updateDocs() { +function createDocs() { packagesManager.getPublicPackages().forEach((pkg) => { const npmName = pkg.getNpmName(); const directoryName = pkg.getDirectoryName(); const root = pkg.resolve('..', '..'); const readmePath = pkg.resolve('README.md'); - const sidebarPath = webPkg.resolve( - 'docs', - 'packages', - `${directoryName}.md`, - ); if (!fs.existsSync(readmePath)) { console.log(`Creating ${path.relative(root, readmePath)}`); fs.writeFileSync( @@ -63,17 +43,7 @@ function updateDocs() { ), ); } - if (!fs.existsSync(sidebarPath)) { - console.log(`Creating ${path.relative(root, sidebarPath)}`); - fs.writeFileSync( - sidebarPath, - sidebarTemplate( - npmName, - path.relative(path.dirname(sidebarPath), readmePath), - ), - ); - } }); } -updateDocs(); +createDocs();