Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils-build): new utility to build plugins #5612

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
7 changes: 4 additions & 3 deletions packages/docusaurus-plugin-client-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "lib/index.js",
"types": "src/plugin-client-redirects.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"repository": {
"type": "git",
Expand All @@ -29,7 +29,8 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.15"
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "lib/index.js",
"types": "src/plugin-content-blog.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,6 +36,7 @@
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15",
"escape-string-regexp": "^4.0.0"
},
"peerDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"types": "src/plugin-content-docs.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "2.0.0-beta.15",
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15",
"@types/js-yaml": "^4.0.5",
"@types/picomatch": "^2.3.0",
"commander": "^5.1.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus-plugin-content-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "lib/index.js",
"types": "src/plugin-content-pages.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"publishConfig": {
"access": "public"
Expand All @@ -28,7 +28,8 @@
"webpack": "^5.69.1"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.15"
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus-plugin-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "lib/index.js",
"types": "src/plugin-debug.d.ts",
"scripts": {
"build": "tsc && node copyUntypedFiles.mjs",
"watch": "node copyUntypedFiles.mjs && tsc --watch"
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"publishConfig": {
"access": "public"
Expand All @@ -25,7 +25,8 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.15"
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"access": "public"
},
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"repository": {
"type": "git",
Expand All @@ -23,7 +23,8 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.15"
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus-plugin-google-gtag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "lib/index.js",
"types": "src/plugin-google-gtag.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"publishConfig": {
"access": "public"
Expand All @@ -23,7 +23,8 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.15"
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
8 changes: 3 additions & 5 deletions packages/docusaurus-plugin-ideal-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
"main": "lib/index.js",
"types": "src/plugin-ideal-image.d.ts",
"scripts": {
"build": "yarn build:server && yarn build:browser && yarn build:copy && yarn build:format",
"build:server": "tsc --project tsconfig.server.json",
"build:browser": "tsc --project tsconfig.browser.json",
"build:copy": "node copyUntypedFiles.mjs",
"build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\""
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"publishConfig": {
"access": "public"
Expand All @@ -35,6 +32,7 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "2.0.0-beta.15",
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15",
"fs-extra": "^10.0.0"
},
"peerDependencies": {
Expand Down
30 changes: 0 additions & 30 deletions packages/docusaurus-theme-classic/babel.config.js

This file was deleted.

7 changes: 2 additions & 5 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
},
"license": "MIT",
"scripts": {
"build": "tsc --noEmit && yarn babel:lib && yarn babel:lib-next && yarn format:lib-next",
"watch": "concurrently --names \"lib,lib-next,tsc\" --kill-others \"yarn babel:lib --watch\" \"yarn babel:lib-next --watch\" \"yarn tsc --watch\"",
"babel:lib": "cross-env BABEL_ENV=lib babel src -d lib --extensions \".tsx,.ts\" --ignore \"**/*.d.ts\" --copy-files",
"babel:lib-next": "cross-env BABEL_ENV=lib-next babel src -d lib-next --extensions \".tsx,.ts\" --ignore \"**/*.d.ts\" --copy-files",
"format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
"build": "docusaurus-plugin build",
"watch": "docusaurus-plugin watch"
},
"dependencies": {
"@docusaurus/core": "2.0.0-beta.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-classic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function docusaurusThemeClassic(
name: 'docusaurus-theme-classic',

getThemePath() {
return path.join(__dirname, '../lib-next/theme');
return path.join(__dirname, '../lib/theme');
},

getTypeScriptThemePath() {
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-theme-classic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"compilerOptions": {
"lib": ["DOM", "ES2019"],
"module": "esnext",
"noEmit": true,
"jsx": "react",
"baseUrl": "src"
"baseUrl": "src",
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/"]
}
1 change: 1 addition & 0 deletions packages/docusaurus-theme-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@docusaurus/core": "2.0.0-beta.15",
"@docusaurus/module-type-aliases": "2.0.0-beta.15",
"@docusaurus/types": "2.0.0-beta.15",
"@docusaurus/utils-build": "2.0.0-beta.15",
"@testing-library/react-hooks": "^7.0.2",
"fs-extra": "^10.0.0",
"lodash": "^4.17.21"
Expand Down
9 changes: 9 additions & 0 deletions packages/docusaurus-utils-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# docusaurus-plugin-utils

A utility to build and pack docusaurus plugins, particularly useful for TypeScript plugin authors

## CLI

### `docusaurus-plugin build`

Builds your plugin and transpiles theme components to human-readable JS for swizzling.
39 changes: 39 additions & 0 deletions packages/docusaurus-utils-build/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node
/**
* 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 logger from '@docusaurus/logger';
import cli from 'commander';
import build from '../lib/build.js';
import watch from '../lib/watch.js';

cli
.command('build')
.option('--source-dir <dir>')
.option('--target-dir <dir>')
.option('--theme-dir <dir>')
.option('--theme-target-dir <dir>')
.option('--ignore <pattern>')
.action(build);

cli
.command('watch')
.option('--source-dir <dir>')
.option('--target-dir <dir>')
.option('--ignore <pattern>')
.action(watch);

cli.arguments('<command>').action((cmd) => {
cli.outputHelp();
logger.error` Unknown command name=${cmd}.`;
});

cli.parse(process.argv);

if (!process.argv.slice(2).length) {
cli.outputHelp();
}
37 changes: 37 additions & 0 deletions packages/docusaurus-utils-build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@docusaurus/utils-build",
"version": "2.0.0-beta.15",
"description": "Build and pack docusaurus plugins in one command",
"license": "MIT",
"type": "module",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/docusaurus.git",
"directory": "packages/docusaurus-utils-build"
},
"bin": {
"docusaurus-plugin": "bin/index.js"
},
"scripts": {
"build": "tsc"
},
"dependencies": {
"@babel/core": "^7.17.5",
"@babel/plugin-transform-modules-commonjs": "^7.16.8",
"@babel/preset-typescript": "^7.16.7",
"@docusaurus/logger": "2.0.0-beta.15",
"@docusaurus/utils": "2.0.0-beta.15",
"chokidar": "^3.5.2",
"commander": "^5.1.0",
"lodash": "^4.17.21",
"prettier": "^2.5.1",
"shelljs": "^0.8.5",
"typescript": "^4.5.5"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.15"
}
}
Loading