diff --git a/.eslintignore b/.eslintignore index 0f08c470b8b4..8a6e126fff9f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -18,6 +18,7 @@ packages/docusaurus-plugin-client-redirects/lib/ packages/docusaurus-plugin-content-blog/lib/ packages/docusaurus-plugin-content-docs/lib/ packages/docusaurus-plugin-content-pages/lib/ +packages/docusaurus-plugin-debug/lib/ packages/docusaurus-plugin-sitemap/lib/ packages/docusaurus-plugin-ideal-image/lib/ packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js diff --git a/.gitignore b/.gitignore index 062df8797ceb..c1a3bf0b1d92 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,6 @@ packages/docusaurus-plugin-client-redirects/lib/ packages/docusaurus-plugin-content-blog/lib/ packages/docusaurus-plugin-content-docs/lib/ packages/docusaurus-plugin-content-pages/lib/ +packages/docusaurus-plugin-debug/lib/ packages/docusaurus-plugin-sitemap/lib/ packages/docusaurus-plugin-ideal-image/lib/ diff --git a/.prettierignore b/.prettierignore index fd0e7bbf9129..1f599c7c1a41 100644 --- a/.prettierignore +++ b/.prettierignore @@ -11,6 +11,7 @@ packages/docusaurus-init/templates/**/*.md packages/docusaurus-plugin-content-blog/lib/ packages/docusaurus-plugin-content-docs/lib/ packages/docusaurus-plugin-content-pages/lib/ +packages/docusaurus-plugin-debug/lib/ packages/docusaurus-plugin-sitemap/lib/ packages/docusaurus-plugin-ideal-image/lib/ __fixtures__ diff --git a/packages/docusaurus-plugin-debug/package.json b/packages/docusaurus-plugin-debug/package.json new file mode 100644 index 000000000000..c93233c10479 --- /dev/null +++ b/packages/docusaurus-plugin-debug/package.json @@ -0,0 +1,25 @@ +{ + "name": "@docusaurus/plugin-debug", + "version": "2.0.0-alpha.56", + "description": "Debug plugin for Docusaurus", + "main": "lib/index.js", + "scripts": { + "tsc": "tsc" + }, + "publishConfig": { + "access": "public" + }, + "license": "MIT", + "dependencies": { + "@docusaurus/types": "^2.0.0-alpha.56", + "@docusaurus/utils": "^2.0.0-alpha.56" + }, + "peerDependencies": { + "@docusaurus/core": "^2.0.0", + "react": "^16.8.4", + "react-dom": "^16.8.4" + }, + "engines": { + "node": ">=10.15.1" + } +} diff --git a/packages/docusaurus-plugin-debug/src/index.ts b/packages/docusaurus-plugin-debug/src/index.ts new file mode 100644 index 000000000000..8eadee856646 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/index.ts @@ -0,0 +1,31 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {LoadContext, Plugin} from '@docusaurus/types'; +import {normalizeUrl} from '@docusaurus/utils'; + +import path from 'path'; + +export default function pluginContentPages({ + siteConfig: {baseUrl}, +}: LoadContext): Plugin { + return { + name: 'docusaurus-plugin-debug', + + getThemePath() { + return path.resolve(__dirname, '../src/theme'); + }, + + contentLoaded({actions: {addRoute}}) { + addRoute({ + path: normalizeUrl([baseUrl, '__docusaurus/debug']), + component: '@theme/Debug', + exact: true, + }); + }, + }; +} diff --git a/packages/docusaurus-plugin-debug/src/theme/Debug/index.js b/packages/docusaurus-plugin-debug/src/theme/Debug/index.js new file mode 100644 index 000000000000..beef72aa4d30 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/Debug/index.js @@ -0,0 +1,47 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React from 'react'; +import Layout from '@theme/Layout'; + +import registry from '@generated/registry'; +import routes from '@generated/routes'; + +import styles from './styles.module.css'; + +function Debug() { + return ( + +
+
+

Registry

+
    + {Object.values(registry).map(([, aliasedPath, resolved]) => ( +
  • +
    Aliased Path: {aliasedPath}
    +
    Resolved Path: {resolved}
    +
  • + ))} +
+
+
+

Routes

+
    + {routes.map(({path, exact}) => ( +
  • +
    Route: {path}
    +
    Is exact: {Boolean(exact)}
    +
  • + ))} +
+
+
+
+ ); +} + +export default Debug; diff --git a/packages/docusaurus-plugin-debug/src/theme/Debug/styles.module.css b/packages/docusaurus-plugin-debug/src/theme/Debug/styles.module.css new file mode 100644 index 000000000000..cb621a15abf8 --- /dev/null +++ b/packages/docusaurus-plugin-debug/src/theme/Debug/styles.module.css @@ -0,0 +1,11 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +.Container { + display: flex; + margin: 1em; +} diff --git a/packages/docusaurus-plugin-debug/tsconfig.json b/packages/docusaurus-plugin-debug/tsconfig.json new file mode 100644 index 000000000000..f5902ba1089b --- /dev/null +++ b/packages/docusaurus-plugin-debug/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "incremental": true, + "tsBuildInfoFile": "./lib/.tsbuildinfo", + "rootDir": "src", + "outDir": "lib" + } +} diff --git a/packages/docusaurus-preset-classic/src/index.js b/packages/docusaurus-preset-classic/src/index.js index 2a4d489bcc76..894fe315c251 100644 --- a/packages/docusaurus-preset-classic/src/index.js +++ b/packages/docusaurus-preset-classic/src/index.js @@ -24,6 +24,7 @@ module.exports = function preset(context, opts = {}) { isProd && googleAnalytics && require.resolve('@docusaurus/plugin-google-analytics'), + !isProd && require.resolve('@docusaurus/plugin-debug'), isProd && gtag && require.resolve('@docusaurus/plugin-google-gtag'), isProd && [require.resolve('@docusaurus/plugin-sitemap'), opts.sitemap], ],