From 15b50dc4482ea1af1fb9b6ca12f7859813053b25 Mon Sep 17 00:00:00 2001 From: Long Ho Date: Fri, 26 Feb 2021 23:11:04 -0500 Subject: [PATCH] feat: add --config & --generated-files-dir option to CLI --- packages/docusaurus-types/src/index.d.ts | 35 +++++-- packages/docusaurus/bin/docusaurus.js | 94 ++++++++++++++----- packages/docusaurus/src/commands/build.ts | 15 ++- packages/docusaurus/src/commands/deploy.ts | 45 +++------ packages/docusaurus/src/commands/serve.ts | 6 +- packages/docusaurus/src/commands/start.ts | 1 + .../src/commands/writeTranslations.ts | 8 +- .../__snapshots__/config.test.ts.snap | 2 - .../src/server/__tests__/config.test.ts | 33 +++++-- packages/docusaurus/src/server/config.ts | 17 +--- packages/docusaurus/src/server/index.ts | 23 +++-- website/docs/cli.md | 22 +++-- website/package.json | 4 +- 13 files changed, 198 insertions(+), 107 deletions(-) diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index 021201e495eec..259f1c7952dbb 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -131,21 +131,36 @@ export type HostPortCLIOptions = { port?: string; }; -export type StartCLIOptions = HostPortCLIOptions & { - hotOnly: boolean; - open: boolean; - poll: boolean | number; - locale?: string; +export type ConfigOptions = { + config: string; }; -export type ServeCLIOptions = HostPortCLIOptions & { - build: boolean; - dir: string; -}; +export type StartCLIOptions = HostPortCLIOptions & + ConfigOptions & { + hotOnly: boolean; + open: boolean; + poll: boolean | number; + locale?: string; + }; -export type BuildOptions = { +export type ServeCLIOptions = HostPortCLIOptions & + ConfigOptions & { + dir: string; + } & ( + | { + build: true; + // We only need generatedFilesDir when `build` is true + generatedFilesDir: string; + } + | { + build: false; + } + ); + +export type BuildOptions = ConfigOptions & { bundleAnalyzer: boolean; outDir: string; + generatedFilesDir: string; minify: boolean; skipBuild: boolean; }; diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index ff0969cb35a9c..5cb6238037176 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -109,6 +109,14 @@ cli '--out-dir ', 'The full path for the new output directory, relative to the current workspace (default: build).', ) + .option( + '--config ', + 'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`', + ) + .option( + '--generated-files-dir ', + 'Path to temporary `.docusaurus` folder, default to `[siteDir]/.docusaurus`.', + ) .option( '-l, --locale ', 'Build the site in a specified locale. Build all known locales otherwise.', @@ -117,14 +125,21 @@ cli '--no-minify', 'Build website without minimizing JS bundles (default: false)', ) - .action((siteDir = '.', {bundleAnalyzer, outDir, locale, minify}) => { - wrapCommand(build)(path.resolve(siteDir), { - bundleAnalyzer, - outDir, - locale, - minify, - }); - }); + .action( + ( + siteDir = '.', + {bundleAnalyzer, config, generatedFilesDir, outDir, locale, minify}, + ) => { + wrapCommand(build)(path.resolve(siteDir), { + bundleAnalyzer, + outDir, + config, + generatedFilesDir, + locale, + minify, + }); + }, + ); cli .command('swizzle [themeName] [componentName] [siteDir]') @@ -155,12 +170,25 @@ cli '--out-dir ', 'The full path for the new output directory, relative to the current workspace (default: build).', ) + .option( + '--config ', + 'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`', + ) + .option( + '--generated-files-dir ', + 'Path to temporary `.docusaurus` folder, default to `[siteDir]/.docusaurus`. This is only relevant when `--build` passed in.', + ) .option( '--skip-build', 'Skip building website before deploy it (default: false)', ) - .action((siteDir = '.', {outDir, skipBuild}) => { - wrapCommand(deploy)(path.resolve(siteDir), {outDir, skipBuild}); + .action((siteDir = '.', {outDir, skipBuild, config, generatedFilesDir}) => { + wrapCommand(deploy)(path.resolve(siteDir), { + outDir, + config, + generatedFilesDir, + skipBuild, + }); }); cli @@ -173,21 +201,28 @@ cli '--hot-only', 'Do not fallback to page refresh if hot reload fails (default: false)', ) + .option( + '--config ', + 'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`', + ) .option('--no-open', 'Do not open page in the browser (default: false)') .option( '--poll [interval]', 'Use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds.', ) - .action((siteDir = '.', {port, host, locale, hotOnly, open, poll}) => { - wrapCommand(start)(path.resolve(siteDir), { - port, - host, - locale, - hotOnly, - open, - poll, - }); - }); + .action( + (siteDir = '.', {port, host, locale, config, hotOnly, open, poll}) => { + wrapCommand(start)(path.resolve(siteDir), { + port, + host, + locale, + config, + hotOnly, + open, + poll, + }); + }, + ); cli .command('serve [siteDir]') @@ -196,6 +231,14 @@ cli '--dir ', 'The full path for the new output directory, relative to the current workspace (default: build).', ) + .option( + '--config ', + 'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`', + ) + .option( + '--generated-files-dir ', + 'Path to temporary `.docusaurus` folder, default to `[siteDir]/.docusaurus`. This is only relevant when `--build` passed in.', + ) .option('-p, --port ', 'use specified port (default: 3000)') .option('--build', 'Build website before serving (default: false)') .option('-h, --host ', 'use specified host (default: localhost') @@ -207,12 +250,16 @@ cli port = 3000, host = 'localhost', build: buildSite = false, + config, + generatedFilesDir, }, ) => { wrapCommand(serve)(path.resolve(siteDir), { dir, port, build: buildSite, + config, + generatedFilesDir, host, }); }, @@ -236,6 +283,10 @@ cli '--override', 'By default, we only append missing translation messages to existing translation files. This option allows to override existing translation messages. Make sure to commit or backup your existing translations, as they may be overridden.', ) + .option( + '--config ', + 'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`', + ) .option( '--messagePrefix ', 'Allows to init new written messages with a given prefix. This might help you to highlight untranslated message to make them stand out in the UI.', @@ -243,11 +294,12 @@ cli .action( ( siteDir = '.', - {locale = undefined, override = false, messagePrefix = ''}, + {locale = undefined, override = false, messagePrefix = '', config}, ) => { wrapCommand(writeTranslations)(path.resolve(siteDir), { locale, override, + config, messagePrefix, }); }, diff --git a/packages/docusaurus/src/commands/build.ts b/packages/docusaurus/src/commands/build.ts index 0ec5f13cfa2df..380b4a0cf88cb 100644 --- a/packages/docusaurus/src/commands/build.ts +++ b/packages/docusaurus/src/commands/build.ts @@ -14,7 +14,7 @@ import {Configuration, Plugin} from 'webpack'; import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer'; import merge from 'webpack-merge'; import {STATIC_DIR_NAME} from '../constants'; -import {load} from '../server'; +import {load, loadContext} from '../server'; import {handleBrokenLinks} from '../server/brokenLinks'; import {BuildCLIOptions, Props} from '@docusaurus/types'; @@ -28,7 +28,6 @@ import { import CleanWebpackPlugin from '../webpack/plugins/CleanWebpackPlugin'; import {loadI18n} from '../server/i18n'; import {mapAsyncSequencial} from '@docusaurus/utils'; -import loadConfig from '../server/config'; export default async function build( siteDir: string, @@ -59,8 +58,14 @@ export default async function build( throw e; } } - - const i18n = await loadI18n(loadConfig(siteDir), { + const context = await loadContext(siteDir, { + customOutDir: cliOptions.outDir, + customGeneratedFilesDir: cliOptions.generatedFilesDir, + customConfigFilePath: cliOptions.config, + locale: cliOptions.locale, + localizePath: cliOptions.locale ? false : undefined, + }); + const i18n = await loadI18n(context.siteConfig, { locale: cliOptions.locale, }); if (cliOptions.locale) { @@ -112,6 +117,8 @@ async function buildLocale({ const props: Props = await load(siteDir, { customOutDir: cliOptions.outDir, + customConfigFilePath: cliOptions.config, + customGeneratedFilesDir: cliOptions.generatedFilesDir, locale, localizePath: cliOptions.locale ? false : undefined, }); diff --git a/packages/docusaurus/src/commands/deploy.ts b/packages/docusaurus/src/commands/deploy.ts index cd2451a195b31..f1b294026fe48 100644 --- a/packages/docusaurus/src/commands/deploy.ts +++ b/packages/docusaurus/src/commands/deploy.ts @@ -6,14 +6,15 @@ */ import fs from 'fs-extra'; -import path from 'path'; import shell from 'shelljs'; import chalk from 'chalk'; -import {CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME} from '../constants'; +import {CONFIG_FILE_NAME} from '../constants'; import {loadContext} from '../server'; -import loadConfig from '../server/config'; import build from './build'; import {BuildCLIOptions} from '@docusaurus/types'; +import {mkdtempSync} from 'fs'; +import path from 'path'; +import os from 'os'; // GIT_PASS env variable should not appear in logs function obfuscateGitPass(str) { @@ -42,10 +43,10 @@ export default async function deploy( siteDir: string, cliOptions: Partial = {}, ): Promise { - const {outDir} = await loadContext(siteDir, { + const {outDir, siteConfig} = await loadContext(siteDir, { + customConfigFilePath: cliOptions.config, customOutDir: cliOptions.outDir, }); - const tempDir = path.join(siteDir, GENERATED_FILES_DIR_NAME); console.log('Deploy command invoked ...'); if (!shell.which('git')) { @@ -62,7 +63,6 @@ export default async function deploy( process.env.CURRENT_BRANCH || shell.exec('git rev-parse --abbrev-ref HEAD').stdout.trim(); - const siteConfig = loadConfig(siteDir); const organizationName = process.env.ORGANIZATION_NAME || process.env.CIRCLE_PROJECT_USERNAME || @@ -142,21 +142,15 @@ export default async function deploy( const currentCommit = shellExecLog('git rev-parse HEAD').stdout.trim(); const runDeploy = (outputDirectory) => { - if (shell.cd(tempDir).code !== 0) { - throw new Error( - `Temp dir ${GENERATED_FILES_DIR_NAME} does not exists. Run build website first.`, - ); - } - - if ( - shellExecLog( - `git clone ${remoteBranch} ${projectName}-${deploymentBranch}`, - ).code !== 0 - ) { - throw new Error('Error: git clone failed'); + const fromPath = outputDirectory; + const toPath = mkdtempSync( + path.join(os.tmpdir(), `${projectName}-${deploymentBranch}`), + ); + if (shellExecLog(`git clone ${remoteBranch} ${toPath}`).code !== 0) { + throw new Error(`Error: git clone failed in ${toPath}`); } - shell.cd(`${projectName}-${deploymentBranch}`); + shell.cd(toPath); // If the default branch is the one we're deploying to, then we'll fail // to create it. This is the case of a cross-repo publish, where we clone @@ -184,18 +178,10 @@ export default async function deploy( shellExecLog('git rm -rf .'); - shell.cd('../..'); - - const fromPath = outputDirectory; - const toPath = path.join( - GENERATED_FILES_DIR_NAME, - `${projectName}-${deploymentBranch}`, - ); - fs.copy(fromPath, toPath, (error) => { if (error) { throw new Error( - `Error: Copying build assets failed with error '${error}'`, + `Error: Copying build assets from "${fromPath}" to "${toPath}" failed with error '${error}'`, ); } @@ -228,9 +214,6 @@ export default async function deploy( }; if (!cliOptions.skipBuild) { - // Clear Docusaurus 2 cache dir for deploy consistency. - fs.removeSync(tempDir); - // Build static html files, then push to deploymentBranch branch of specified repo. build(siteDir, cliOptions, false) .then(runDeploy) diff --git a/packages/docusaurus/src/commands/serve.ts b/packages/docusaurus/src/commands/serve.ts index 8b0952d2628c5..925b5e7ea5613 100644 --- a/packages/docusaurus/src/commands/serve.ts +++ b/packages/docusaurus/src/commands/serve.ts @@ -19,11 +19,15 @@ export default async function serve( siteDir: string, cliOptions: ServeCLIOptions, ): Promise { - let dir = path.join(siteDir, cliOptions.dir); + let dir = path.isAbsolute(cliOptions.dir) + ? cliOptions.dir + : path.join(siteDir, cliOptions.dir); if (cliOptions.build) { dir = await build( siteDir, { + generatedFilesDir: cliOptions.generatedFilesDir, + config: cliOptions.config, outDir: dir, }, false, diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index 40a023e0cc57d..1751d635407d5 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -42,6 +42,7 @@ export default async function start( function loadSite() { return load(siteDir, { + customConfigFilePath: cliOptions.config, locale: cliOptions.locale, localizePath: undefined, // should this be configurable? }); diff --git a/packages/docusaurus/src/commands/writeTranslations.ts b/packages/docusaurus/src/commands/writeTranslations.ts index 749eaeb0bd090..ee26e7fff6e82 100644 --- a/packages/docusaurus/src/commands/writeTranslations.ts +++ b/packages/docusaurus/src/commands/writeTranslations.ts @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +import {ConfigOptions} from '@docusaurus/types'; import {loadContext, loadPluginConfigs} from '../server'; import initPlugins, {InitPlugin} from '../server/plugins/init'; @@ -47,9 +48,12 @@ async function writePluginTranslationFiles({ export default async function writeTranslations( siteDir: string, - options: WriteTranslationsOptions & {locale?: string}, + options: WriteTranslationsOptions & ConfigOptions & {locale?: string}, ): Promise { - const context = await loadContext(siteDir, {locale: options.locale}); + const context = await loadContext(siteDir, { + customConfigFilePath: options.config, + locale: options.locale, + }); const pluginConfigs = loadPluginConfigs(context); const plugins = initPlugins({ pluginConfigs, diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap index d0d71639874ec..9600828797d6d 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap @@ -6,8 +6,6 @@ exports[`loadConfig website with incomplete siteConfig 1`] = ` " `; -exports[`loadConfig website with no siteConfig 1`] = `"docusaurus.config.js not found at packages/docusaurus/src/server/__tests__/__fixtures__/nonExisting/docusaurus.config.js"`; - exports[`loadConfig website with useless field (wrong field) in siteConfig 1`] = ` "\\"favicon\\" is required These field(s) [\\"useLessField\\",] are not recognized in docusaurus.config.js. diff --git a/packages/docusaurus/src/server/__tests__/config.test.ts b/packages/docusaurus/src/server/__tests__/config.test.ts index ede66200d0c88..5f17fb409cdd5 100644 --- a/packages/docusaurus/src/server/__tests__/config.test.ts +++ b/packages/docusaurus/src/server/__tests__/config.test.ts @@ -10,31 +10,52 @@ import loadConfig from '../config'; describe('loadConfig', () => { test('website with valid siteConfig', async () => { - const fixtures = path.join(__dirname, '__fixtures__'); - const siteDir = path.join(fixtures, 'simple-site'); + const siteDir = path.join( + __dirname, + '__fixtures__', + 'simple-site', + 'docusaurus.config.js', + ); const config = loadConfig(siteDir); expect(config).toMatchSnapshot(); expect(config).not.toEqual({}); }); test('website with incomplete siteConfig', () => { - const siteDir = path.join(__dirname, '__fixtures__', 'bad-site'); + const siteDir = path.join( + __dirname, + '__fixtures__', + 'bad-site', + 'docusaurus.config.js', + ); expect(() => { loadConfig(siteDir); }).toThrowErrorMatchingSnapshot(); }); test('website with useless field (wrong field) in siteConfig', () => { - const siteDir = path.join(__dirname, '__fixtures__', 'wrong-site'); + const siteDir = path.join( + __dirname, + '__fixtures__', + 'wrong-site', + 'docusaurus.config.js', + ); expect(() => { loadConfig(siteDir); }).toThrowErrorMatchingSnapshot(); }); test('website with no siteConfig', () => { - const siteDir = path.join(__dirname, '__fixtures__', 'nonExisting'); + const siteDir = path.join( + __dirname, + '__fixtures__', + 'nonExisting', + 'docusaurus.config.js', + ); expect(() => { loadConfig(siteDir); - }).toThrowErrorMatchingSnapshot(); + }).toThrowError( + /Config file "(.*?)\/packages\/docusaurus\/src\/server\/__tests__\/__fixtures__\/nonExisting\/docusaurus.config.js" not found$/, + ); }); }); diff --git a/packages/docusaurus/src/server/config.ts b/packages/docusaurus/src/server/config.ts index 78ee8ebf302f4..2f08307c889a2 100644 --- a/packages/docusaurus/src/server/config.ts +++ b/packages/docusaurus/src/server/config.ts @@ -7,25 +7,12 @@ import fs from 'fs-extra'; import importFresh from 'import-fresh'; -import path from 'path'; import {DocusaurusConfig} from '@docusaurus/types'; -import {CONFIG_FILE_NAME} from '../constants'; import {validateConfig} from './configValidation'; -import {toMessageRelativeFilePath} from '@docusaurus/utils'; - -export default function loadConfig(siteDir: string): DocusaurusConfig { - // TODO temporary undocumented env variable: we should be able to use a cli option instead! - const loadedConfigFileName = - process.env.DOCUSAURUS_CONFIG || CONFIG_FILE_NAME; - - const configPath = path.resolve(siteDir, loadedConfigFileName); +export default function loadConfig(configPath: string): DocusaurusConfig { if (!fs.existsSync(configPath)) { - throw new Error( - `${CONFIG_FILE_NAME} not found at ${toMessageRelativeFilePath( - configPath, - )}`, - ); + throw new Error(`Config file "${configPath}" not found`); } const loadedConfig = importFresh(configPath) as Partial; diff --git a/packages/docusaurus/src/server/index.ts b/packages/docusaurus/src/server/index.ts index 9a5d90b56b862..29f4f9879540f 100644 --- a/packages/docusaurus/src/server/index.ts +++ b/packages/docusaurus/src/server/index.ts @@ -40,6 +40,8 @@ import {mapValues} from 'lodash'; type LoadContextOptions = { customOutDir?: string; + customGeneratedFilesDir?: string; + customConfigFilePath?: string; locale?: string; localizePath?: boolean; // undefined = only non-default locales paths are localized }; @@ -48,12 +50,21 @@ export async function loadContext( siteDir: string, options: LoadContextOptions = {}, ): Promise { - const {customOutDir, locale} = options; - const generatedFilesDir: string = path.resolve( - siteDir, - GENERATED_FILES_DIR_NAME, - ); - const initialSiteConfig: DocusaurusConfig = loadConfig(siteDir); + const { + customOutDir, + locale, + customGeneratedFilesDir, + customConfigFilePath, + } = options; + const generatedFilesDir = customGeneratedFilesDir + ? path.resolve(customGeneratedFilesDir) + : path.resolve(siteDir, GENERATED_FILES_DIR_NAME); + + const configPath = customConfigFilePath + ? path.resolve(customConfigFilePath) + : path.resolve(siteDir, CONFIG_FILE_NAME); + + const initialSiteConfig: DocusaurusConfig = loadConfig(configPath); const {ssrTemplate} = initialSiteConfig; const baseOutDir = customOutDir diff --git a/website/docs/cli.md b/website/docs/cli.md index 8d136b212d3f3..1df658be48c2a 100644 --- a/website/docs/cli.md +++ b/website/docs/cli.md @@ -30,7 +30,7 @@ import TOCInline from "@theme/TOCInline" Below is a list of Docusaurus CLI commands and their usages: -### `docusaurus start` +### `docusaurus start [siteDir]` Builds and serves a preview of your site locally with [Webpack Dev Server](https://webpack.js.org/configuration/dev-server). @@ -42,6 +42,7 @@ Builds and serves a preview of your site locally with [Webpack Dev Server](https | `--host` | `localhost` | Specify a host to use. For example, if you want your server to be accessible externally, you can use `--host 0.0.0.0`. | | `--hot-only` | `false` | Enables Hot Module Replacement without page refresh as fallback in case of build failures. More information [here](https://webpack.js.org/configuration/dev-server/#devserverhotonly). | | `--no-open` | `false` | Do not open automatically the page in the browser. | +| `--config` | `undefined` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` | | `--poll [optionalIntervalMs]` | `false` | Use polling of files rather than watching for live reload as a fallback in environments where watching doesn't work. More information [here](https://webpack.js.org/configuration/watch/#watchoptionspoll). | :::important @@ -66,7 +67,7 @@ HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem yarn start 4. Open `https://localhost:3000/` -### `docusaurus build` +### `docusaurus build [siteDir]` Compiles your site for production. @@ -76,6 +77,8 @@ Compiles your site for production. | --- | --- | --- | | `--bundle-analyzer` | `false` | Analyze your bundle with the [webpack bundle analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer). | | `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. | +| `--config` | `undefined` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` | +| `--generated-files-dir` | `undefined` | Path to temporary `.docusaurus` folder, default to `[siteDir]/.docusaurus` | | `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. | :::info @@ -84,7 +87,7 @@ For advanced minification of CSS bundle, we use the [advanced cssnano preset](ht ::: -### `docusaurus swizzle` +### `docusaurus swizzle [siteDir]` :::caution @@ -133,7 +136,7 @@ TODO a separate section for swizzle tutorial. To learn more about swizzling, check [here](#). --> -### `docusaurus deploy` +### `docusaurus deploy [siteDir]` Deploys your site with [GitHub Pages](https://pages.github.com/). Check out the docs on [deployment](deployment.mdx#deploying-to-github-pages) for more details. @@ -143,8 +146,10 @@ Deploys your site with [GitHub Pages](https://pages.github.com/). Check out the | --- | --- | --- | | `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. | | `--skip-build` | `false` | Deploy website without building it. This may be useful when using custom deploy script. | +| `--config` | `undefined` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` | +| `--generated-files-dir` | `undefined` | Path to temporary `.docusaurus` folder, default to `[siteDir]/.docusaurus` | -### `docusaurus serve` +### `docusaurus serve [siteDir]` Serve your built website locally. @@ -153,15 +158,17 @@ Serve your built website locally. | `--port` | `3000` | Use specified port | | `--dir` | `build` | The full path for the output directory, relative to the current workspace | | `--build` | `false` | Build website before serving | +| `--config` | `undefined` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` | +| `--generated-files-dir` | `undefined` | Path to temporary `.docusaurus` folder, default to `[siteDir]/.docusaurus`. This is only relevant when `--build` is `true` | | `--host` | `localhost` | Specify a host to use. For example, if you want your server to be accessible externally, you can use `--host 0.0.0.0`. | -### `docusaurus clear` +### `docusaurus clear [siteDir]` Clear a Docusaurus site's generated assets, caches, build artifacts. We recommend running this command before reporting bugs, after upgrading versions, or anytime you have issues with your Docusaurus site. -### `docusaurus write-translations` +### `docusaurus write-translations [siteDir]` Write the JSON translation files that you will have to translate. @@ -171,4 +178,5 @@ By default, the files are written in `website/i18n//...`. | --- | --- | --- | | `--locale` | `` | Define which locale folder you want to write translations the JSON files in | | `--override` | `false` | Override existing translation messages | +| `--config` | `undefined` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` | | `--messagePrefix` | `''` | Allows to add a prefix to each translation message, to help you highlight untranslated strings | diff --git a/website/package.json b/website/package.json index 049aaf5fd7225..b7a883af39840 100644 --- a/website/package.json +++ b/website/package.json @@ -15,8 +15,8 @@ "build:baseUrl": "cross-env BASE_URL='/build/' yarn build", "start:bootstrap": "cross-env DOCUSAURUS_PRESET=bootstrap yarn start", "build:bootstrap": "cross-env DOCUSAURUS_PRESET=bootstrap yarn build", - "start:blogOnly": "cross-env DOCUSAURUS_CONFIG='docusaurus.config-blog-only.js' yarn start", - "build:blogOnly": "cross-env DOCUSAURUS_CONFIG='docusaurus.config-blog-only.js' yarn build", + "start:blogOnly": "cross-env yarn start --config=docusaurus.config-blog-only.js", + "build:blogOnly": "cross-env yarn build --config=docusaurus.config-blog-only.js", "netlify:build:production": "yarn docusaurus write-translations && yarn netlify:crowdin:uploadSources && yarn netlify:crowdin:downloadTranslations && yarn build", "netlify:build:deployPreview": "yarn docusaurus write-translations --locale fr --messagePrefix '(fr) ' && yarn netlify:build:deployPreview:v1:all && yarn netlify:build:deployPreview:classic && yarn netlify:build:deployPreview:bootstrap && yarn netlify:build:deployPreview:blogOnly", "netlify:build:deployPreview:classic": "cross-env BASE_URL='/classic/' yarn build --out-dir netlifyDeployPreview/classic",