mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 12:17:20 +02:00
feat(v2): add --config option to CLI (#4308)
* feat: add --config & --generated-files-dir option to CLI * revert --generated-files-dir option + some refactors Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
9413ba920e
commit
f46adffa17
19 changed files with 225 additions and 169 deletions
27
packages/docusaurus-types/src/index.d.ts
vendored
27
packages/docusaurus-types/src/index.d.ts
vendored
|
@ -131,19 +131,25 @@ export type HostPortCLIOptions = {
|
||||||
port?: string;
|
port?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StartCLIOptions = HostPortCLIOptions & {
|
export type ConfigOptions = {
|
||||||
hotOnly: boolean;
|
config: string;
|
||||||
open: boolean;
|
|
||||||
poll: boolean | number;
|
|
||||||
locale?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ServeCLIOptions = HostPortCLIOptions & {
|
export type StartCLIOptions = HostPortCLIOptions &
|
||||||
build: boolean;
|
ConfigOptions & {
|
||||||
dir: string;
|
hotOnly: boolean;
|
||||||
};
|
open: boolean;
|
||||||
|
poll: boolean | number;
|
||||||
|
locale?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type BuildOptions = {
|
export type ServeCLIOptions = HostPortCLIOptions &
|
||||||
|
ConfigOptions & {
|
||||||
|
dir: string;
|
||||||
|
build: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type BuildOptions = ConfigOptions & {
|
||||||
bundleAnalyzer: boolean;
|
bundleAnalyzer: boolean;
|
||||||
outDir: string;
|
outDir: string;
|
||||||
minify: boolean;
|
minify: boolean;
|
||||||
|
@ -158,6 +164,7 @@ export interface LoadContext {
|
||||||
siteDir: string;
|
siteDir: string;
|
||||||
generatedFilesDir: string;
|
generatedFilesDir: string;
|
||||||
siteConfig: DocusaurusConfig;
|
siteConfig: DocusaurusConfig;
|
||||||
|
siteConfigPath: string;
|
||||||
outDir: string;
|
outDir: string;
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
i18n: I18n;
|
i18n: I18n;
|
||||||
|
|
|
@ -109,6 +109,10 @@ cli
|
||||||
'--out-dir <dir>',
|
'--out-dir <dir>',
|
||||||
'The full path for the new output directory, relative to the current workspace (default: build).',
|
'The full path for the new output directory, relative to the current workspace (default: build).',
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
'--config <config>',
|
||||||
|
'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`',
|
||||||
|
)
|
||||||
.option(
|
.option(
|
||||||
'-l, --locale <locale>',
|
'-l, --locale <locale>',
|
||||||
'Build the site in a specified locale. Build all known locales otherwise.',
|
'Build the site in a specified locale. Build all known locales otherwise.',
|
||||||
|
@ -117,10 +121,11 @@ cli
|
||||||
'--no-minify',
|
'--no-minify',
|
||||||
'Build website without minimizing JS bundles (default: false)',
|
'Build website without minimizing JS bundles (default: false)',
|
||||||
)
|
)
|
||||||
.action((siteDir = '.', {bundleAnalyzer, outDir, locale, minify}) => {
|
.action((siteDir = '.', {bundleAnalyzer, config, outDir, locale, minify}) => {
|
||||||
wrapCommand(build)(path.resolve(siteDir), {
|
wrapCommand(build)(path.resolve(siteDir), {
|
||||||
bundleAnalyzer,
|
bundleAnalyzer,
|
||||||
outDir,
|
outDir,
|
||||||
|
config,
|
||||||
locale,
|
locale,
|
||||||
minify,
|
minify,
|
||||||
});
|
});
|
||||||
|
@ -155,12 +160,20 @@ cli
|
||||||
'--out-dir <dir>',
|
'--out-dir <dir>',
|
||||||
'The full path for the new output directory, relative to the current workspace (default: build).',
|
'The full path for the new output directory, relative to the current workspace (default: build).',
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
'--config <config>',
|
||||||
|
'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`',
|
||||||
|
)
|
||||||
.option(
|
.option(
|
||||||
'--skip-build',
|
'--skip-build',
|
||||||
'Skip building website before deploy it (default: false)',
|
'Skip building website before deploy it (default: false)',
|
||||||
)
|
)
|
||||||
.action((siteDir = '.', {outDir, skipBuild}) => {
|
.action((siteDir = '.', {outDir, skipBuild, config}) => {
|
||||||
wrapCommand(deploy)(path.resolve(siteDir), {outDir, skipBuild});
|
wrapCommand(deploy)(path.resolve(siteDir), {
|
||||||
|
outDir,
|
||||||
|
config,
|
||||||
|
skipBuild,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
cli
|
cli
|
||||||
|
@ -173,21 +186,28 @@ cli
|
||||||
'--hot-only',
|
'--hot-only',
|
||||||
'Do not fallback to page refresh if hot reload fails (default: false)',
|
'Do not fallback to page refresh if hot reload fails (default: false)',
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
'--config <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('--no-open', 'Do not open page in the browser (default: false)')
|
||||||
.option(
|
.option(
|
||||||
'--poll [interval]',
|
'--poll [interval]',
|
||||||
'Use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds.',
|
'Use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds.',
|
||||||
)
|
)
|
||||||
.action((siteDir = '.', {port, host, locale, hotOnly, open, poll}) => {
|
.action(
|
||||||
wrapCommand(start)(path.resolve(siteDir), {
|
(siteDir = '.', {port, host, locale, config, hotOnly, open, poll}) => {
|
||||||
port,
|
wrapCommand(start)(path.resolve(siteDir), {
|
||||||
host,
|
port,
|
||||||
locale,
|
host,
|
||||||
hotOnly,
|
locale,
|
||||||
open,
|
config,
|
||||||
poll,
|
hotOnly,
|
||||||
});
|
open,
|
||||||
});
|
poll,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
cli
|
cli
|
||||||
.command('serve [siteDir]')
|
.command('serve [siteDir]')
|
||||||
|
@ -196,6 +216,10 @@ cli
|
||||||
'--dir <dir>',
|
'--dir <dir>',
|
||||||
'The full path for the new output directory, relative to the current workspace (default: build).',
|
'The full path for the new output directory, relative to the current workspace (default: build).',
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
'--config <config>',
|
||||||
|
'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`',
|
||||||
|
)
|
||||||
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
||||||
.option('--build', 'Build website before serving (default: false)')
|
.option('--build', 'Build website before serving (default: false)')
|
||||||
.option('-h, --host <host>', 'use specified host (default: localhost')
|
.option('-h, --host <host>', 'use specified host (default: localhost')
|
||||||
|
@ -207,12 +231,14 @@ cli
|
||||||
port = 3000,
|
port = 3000,
|
||||||
host = 'localhost',
|
host = 'localhost',
|
||||||
build: buildSite = false,
|
build: buildSite = false,
|
||||||
|
config,
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
wrapCommand(serve)(path.resolve(siteDir), {
|
wrapCommand(serve)(path.resolve(siteDir), {
|
||||||
dir,
|
dir,
|
||||||
port,
|
port,
|
||||||
build: buildSite,
|
build: buildSite,
|
||||||
|
config,
|
||||||
host,
|
host,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -236,6 +262,10 @@ cli
|
||||||
'--override',
|
'--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.',
|
'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 <config>',
|
||||||
|
'Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js`',
|
||||||
|
)
|
||||||
.option(
|
.option(
|
||||||
'--messagePrefix <messagePrefix>',
|
'--messagePrefix <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.',
|
'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 +273,12 @@ cli
|
||||||
.action(
|
.action(
|
||||||
(
|
(
|
||||||
siteDir = '.',
|
siteDir = '.',
|
||||||
{locale = undefined, override = false, messagePrefix = ''},
|
{locale = undefined, override = false, messagePrefix = '', config},
|
||||||
) => {
|
) => {
|
||||||
wrapCommand(writeTranslations)(path.resolve(siteDir), {
|
wrapCommand(writeTranslations)(path.resolve(siteDir), {
|
||||||
locale,
|
locale,
|
||||||
override,
|
override,
|
||||||
|
config,
|
||||||
messagePrefix,
|
messagePrefix,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {Configuration, Plugin} from 'webpack';
|
||||||
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer';
|
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer';
|
||||||
import merge from 'webpack-merge';
|
import merge from 'webpack-merge';
|
||||||
import {STATIC_DIR_NAME} from '../constants';
|
import {STATIC_DIR_NAME} from '../constants';
|
||||||
import {load} from '../server';
|
import {load, loadContext} from '../server';
|
||||||
import {handleBrokenLinks} from '../server/brokenLinks';
|
import {handleBrokenLinks} from '../server/brokenLinks';
|
||||||
|
|
||||||
import {BuildCLIOptions, Props} from '@docusaurus/types';
|
import {BuildCLIOptions, Props} from '@docusaurus/types';
|
||||||
|
@ -28,7 +28,6 @@ import {
|
||||||
import CleanWebpackPlugin from '../webpack/plugins/CleanWebpackPlugin';
|
import CleanWebpackPlugin from '../webpack/plugins/CleanWebpackPlugin';
|
||||||
import {loadI18n} from '../server/i18n';
|
import {loadI18n} from '../server/i18n';
|
||||||
import {mapAsyncSequencial} from '@docusaurus/utils';
|
import {mapAsyncSequencial} from '@docusaurus/utils';
|
||||||
import loadConfig from '../server/config';
|
|
||||||
|
|
||||||
export default async function build(
|
export default async function build(
|
||||||
siteDir: string,
|
siteDir: string,
|
||||||
|
@ -59,8 +58,13 @@ export default async function build(
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const context = await loadContext(siteDir, {
|
||||||
const i18n = await loadI18n(loadConfig(siteDir), {
|
customOutDir: cliOptions.outDir,
|
||||||
|
customConfigFilePath: cliOptions.config,
|
||||||
|
locale: cliOptions.locale,
|
||||||
|
localizePath: cliOptions.locale ? false : undefined,
|
||||||
|
});
|
||||||
|
const i18n = await loadI18n(context.siteConfig, {
|
||||||
locale: cliOptions.locale,
|
locale: cliOptions.locale,
|
||||||
});
|
});
|
||||||
if (cliOptions.locale) {
|
if (cliOptions.locale) {
|
||||||
|
@ -112,6 +116,7 @@ async function buildLocale({
|
||||||
|
|
||||||
const props: Props = await load(siteDir, {
|
const props: Props = await load(siteDir, {
|
||||||
customOutDir: cliOptions.outDir,
|
customOutDir: cliOptions.outDir,
|
||||||
|
customConfigFilePath: cliOptions.config,
|
||||||
locale,
|
locale,
|
||||||
localizePath: cliOptions.locale ? false : undefined,
|
localizePath: cliOptions.locale ? false : undefined,
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import chalk = require('chalk');
|
import chalk = require('chalk');
|
||||||
import {BUILD_DIR_NAME, GENERATED_FILES_DIR_NAME} from '../constants';
|
import {DEFAULT_BUILD_DIR_NAME, GENERATED_FILES_DIR_NAME} from '../constants';
|
||||||
|
|
||||||
function removePath(fsPath: string) {
|
function removePath(fsPath: string) {
|
||||||
return fs
|
return fs
|
||||||
|
@ -24,7 +24,7 @@ function removePath(fsPath: string) {
|
||||||
export default async function clear(siteDir: string): Promise<unknown> {
|
export default async function clear(siteDir: string): Promise<unknown> {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
removePath(path.join(siteDir, GENERATED_FILES_DIR_NAME)),
|
removePath(path.join(siteDir, GENERATED_FILES_DIR_NAME)),
|
||||||
removePath(path.join(siteDir, BUILD_DIR_NAME)),
|
removePath(path.join(siteDir, DEFAULT_BUILD_DIR_NAME)),
|
||||||
removePath(path.join(siteDir, 'node_modules/.cache/cache-loader')),
|
removePath(path.join(siteDir, 'node_modules/.cache/cache-loader')),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
|
||||||
import shell from 'shelljs';
|
import shell from 'shelljs';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import {CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME} from '../constants';
|
|
||||||
import {loadContext} from '../server';
|
import {loadContext} from '../server';
|
||||||
import loadConfig from '../server/config';
|
|
||||||
import build from './build';
|
import build from './build';
|
||||||
import {BuildCLIOptions} from '@docusaurus/types';
|
import {BuildCLIOptions} from '@docusaurus/types';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
// GIT_PASS env variable should not appear in logs
|
// GIT_PASS env variable should not appear in logs
|
||||||
function obfuscateGitPass(str) {
|
function obfuscateGitPass(str) {
|
||||||
|
@ -42,10 +41,10 @@ export default async function deploy(
|
||||||
siteDir: string,
|
siteDir: string,
|
||||||
cliOptions: Partial<BuildCLIOptions> = {},
|
cliOptions: Partial<BuildCLIOptions> = {},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const {outDir} = await loadContext(siteDir, {
|
const {outDir, siteConfig, siteConfigPath} = await loadContext(siteDir, {
|
||||||
|
customConfigFilePath: cliOptions.config,
|
||||||
customOutDir: cliOptions.outDir,
|
customOutDir: cliOptions.outDir,
|
||||||
});
|
});
|
||||||
const tempDir = path.join(siteDir, GENERATED_FILES_DIR_NAME);
|
|
||||||
|
|
||||||
console.log('Deploy command invoked ...');
|
console.log('Deploy command invoked ...');
|
||||||
if (!shell.which('git')) {
|
if (!shell.which('git')) {
|
||||||
|
@ -62,14 +61,13 @@ export default async function deploy(
|
||||||
process.env.CURRENT_BRANCH ||
|
process.env.CURRENT_BRANCH ||
|
||||||
shell.exec('git rev-parse --abbrev-ref HEAD').stdout.trim();
|
shell.exec('git rev-parse --abbrev-ref HEAD').stdout.trim();
|
||||||
|
|
||||||
const siteConfig = loadConfig(siteDir);
|
|
||||||
const organizationName =
|
const organizationName =
|
||||||
process.env.ORGANIZATION_NAME ||
|
process.env.ORGANIZATION_NAME ||
|
||||||
process.env.CIRCLE_PROJECT_USERNAME ||
|
process.env.CIRCLE_PROJECT_USERNAME ||
|
||||||
siteConfig.organizationName;
|
siteConfig.organizationName;
|
||||||
if (!organizationName) {
|
if (!organizationName) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Missing project organization name. Did you forget to define 'organizationName' in ${CONFIG_FILE_NAME}? You may also export it via the ORGANIZATION_NAME environment variable.`,
|
`Missing project organization name. Did you forget to define 'organizationName' in ${siteConfigPath}? You may also export it via the ORGANIZATION_NAME environment variable.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
console.log(`${chalk.cyan('organizationName:')} ${organizationName}`);
|
console.log(`${chalk.cyan('organizationName:')} ${organizationName}`);
|
||||||
|
@ -80,7 +78,7 @@ export default async function deploy(
|
||||||
siteConfig.projectName;
|
siteConfig.projectName;
|
||||||
if (!projectName) {
|
if (!projectName) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Missing project name. Did you forget to define 'projectName' in ${CONFIG_FILE_NAME}? You may also export it via the PROJECT_NAME environment variable.`,
|
`Missing project name. Did you forget to define 'projectName' in ${siteConfigPath}? You may also export it via the PROJECT_NAME environment variable.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
console.log(`${chalk.cyan('projectName:')} ${projectName}`);
|
console.log(`${chalk.cyan('projectName:')} ${projectName}`);
|
||||||
|
@ -141,22 +139,16 @@ export default async function deploy(
|
||||||
// out to deployment branch.
|
// out to deployment branch.
|
||||||
const currentCommit = shellExecLog('git rev-parse HEAD').stdout.trim();
|
const currentCommit = shellExecLog('git rev-parse HEAD').stdout.trim();
|
||||||
|
|
||||||
const runDeploy = (outputDirectory) => {
|
const runDeploy = async (outputDirectory) => {
|
||||||
if (shell.cd(tempDir).code !== 0) {
|
const fromPath = outputDirectory;
|
||||||
throw new Error(
|
const toPath = await fs.mkdtemp(
|
||||||
`Temp dir ${GENERATED_FILES_DIR_NAME} does not exists. Run build website first.`,
|
path.join(os.tmpdir(), `${projectName}-${deploymentBranch}`),
|
||||||
);
|
);
|
||||||
|
if (shellExecLog(`git clone ${remoteBranch} ${toPath}`).code !== 0) {
|
||||||
|
throw new Error(`Error: git clone failed in ${toPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
shell.cd(toPath);
|
||||||
shellExecLog(
|
|
||||||
`git clone ${remoteBranch} ${projectName}-${deploymentBranch}`,
|
|
||||||
).code !== 0
|
|
||||||
) {
|
|
||||||
throw new Error('Error: git clone failed');
|
|
||||||
}
|
|
||||||
|
|
||||||
shell.cd(`${projectName}-${deploymentBranch}`);
|
|
||||||
|
|
||||||
// If the default branch is the one we're deploying to, then we'll fail
|
// 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
|
// to create it. This is the case of a cross-repo publish, where we clone
|
||||||
|
@ -183,63 +175,50 @@ export default async function deploy(
|
||||||
}
|
}
|
||||||
|
|
||||||
shellExecLog('git rm -rf .');
|
shellExecLog('git rm -rf .');
|
||||||
|
try {
|
||||||
|
await fs.copy(fromPath, toPath);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Error: Copying build assets from "${fromPath}" to "${toPath}" failed with error '${error}'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
shell.cd(toPath);
|
||||||
|
shellExecLog('git add --all');
|
||||||
|
|
||||||
shell.cd('../..');
|
const commitMessage =
|
||||||
|
process.env.CUSTOM_COMMIT_MESSAGE ||
|
||||||
const fromPath = outputDirectory;
|
`Deploy website - based on ${currentCommit}`;
|
||||||
const toPath = path.join(
|
const commitResults = shellExecLog(`git commit -m "${commitMessage}"`);
|
||||||
GENERATED_FILES_DIR_NAME,
|
if (
|
||||||
`${projectName}-${deploymentBranch}`,
|
shellExecLog(`git push --force origin ${deploymentBranch}`).code !== 0
|
||||||
);
|
) {
|
||||||
|
throw new Error('Error: Git push failed');
|
||||||
fs.copy(fromPath, toPath, (error) => {
|
} else if (commitResults.code === 0) {
|
||||||
if (error) {
|
// The commit might return a non-zero value when site is up to date.
|
||||||
throw new Error(
|
let websiteURL = '';
|
||||||
`Error: Copying build assets failed with error '${error}'`,
|
if (githubHost === 'github.com') {
|
||||||
);
|
websiteURL = projectName.includes('.github.io')
|
||||||
|
? `https://${organizationName}.github.io/`
|
||||||
|
: `https://${organizationName}.github.io/${projectName}/`;
|
||||||
|
} else {
|
||||||
|
// GitHub enterprise hosting.
|
||||||
|
websiteURL = `https://${githubHost}/pages/${organizationName}/${projectName}/`;
|
||||||
}
|
}
|
||||||
|
shell.echo(`Website is live at ${websiteURL}`);
|
||||||
shell.cd(toPath);
|
shell.exit(0);
|
||||||
shellExecLog('git add --all');
|
}
|
||||||
|
|
||||||
const commitMessage =
|
|
||||||
process.env.CUSTOM_COMMIT_MESSAGE ||
|
|
||||||
`Deploy website - based on ${currentCommit}`;
|
|
||||||
const commitResults = shellExecLog(`git commit -m "${commitMessage}"`);
|
|
||||||
if (
|
|
||||||
shellExecLog(`git push --force origin ${deploymentBranch}`).code !== 0
|
|
||||||
) {
|
|
||||||
throw new Error('Error: Git push failed');
|
|
||||||
} else if (commitResults.code === 0) {
|
|
||||||
// The commit might return a non-zero value when site is up to date.
|
|
||||||
let websiteURL = '';
|
|
||||||
if (githubHost === 'github.com') {
|
|
||||||
websiteURL = projectName.includes('.github.io')
|
|
||||||
? `https://${organizationName}.github.io/`
|
|
||||||
: `https://${organizationName}.github.io/${projectName}/`;
|
|
||||||
} else {
|
|
||||||
// GitHub enterprise hosting.
|
|
||||||
websiteURL = `https://${githubHost}/pages/${organizationName}/${projectName}/`;
|
|
||||||
}
|
|
||||||
shell.echo(`Website is live at ${websiteURL}`);
|
|
||||||
shell.exit(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!cliOptions.skipBuild) {
|
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 static html files, then push to deploymentBranch branch of specified repo.
|
||||||
build(siteDir, cliOptions, false)
|
try {
|
||||||
.then(runDeploy)
|
await runDeploy(await build(siteDir, cliOptions, false));
|
||||||
.catch((buildError) => {
|
} catch (buildError) {
|
||||||
console.error(buildError);
|
console.error(buildError);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
// Push current build to deploymentBranch branch of specified repo.
|
// Push current build to deploymentBranch branch of specified repo.
|
||||||
runDeploy(outDir);
|
await runDeploy(outDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,14 @@ export default async function serve(
|
||||||
siteDir: string,
|
siteDir: string,
|
||||||
cliOptions: ServeCLIOptions,
|
cliOptions: ServeCLIOptions,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let dir = path.join(siteDir, cliOptions.dir);
|
let dir = path.isAbsolute(cliOptions.dir)
|
||||||
|
? cliOptions.dir
|
||||||
|
: path.join(siteDir, cliOptions.dir);
|
||||||
if (cliOptions.build) {
|
if (cliOptions.build) {
|
||||||
dir = await build(
|
dir = await build(
|
||||||
siteDir,
|
siteDir,
|
||||||
{
|
{
|
||||||
|
config: cliOptions.config,
|
||||||
outDir: dir,
|
outDir: dir,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -22,7 +22,7 @@ import merge from 'webpack-merge';
|
||||||
import HotModuleReplacementPlugin from 'webpack/lib/HotModuleReplacementPlugin';
|
import HotModuleReplacementPlugin from 'webpack/lib/HotModuleReplacementPlugin';
|
||||||
import {load} from '../server';
|
import {load} from '../server';
|
||||||
import {StartCLIOptions} from '@docusaurus/types';
|
import {StartCLIOptions} from '@docusaurus/types';
|
||||||
import {CONFIG_FILE_NAME, STATIC_DIR_NAME} from '../constants';
|
import {STATIC_DIR_NAME} from '../constants';
|
||||||
import createClientConfig from '../webpack/client';
|
import createClientConfig from '../webpack/client';
|
||||||
import {
|
import {
|
||||||
applyConfigureWebpack,
|
applyConfigureWebpack,
|
||||||
|
@ -42,6 +42,7 @@ export default async function start(
|
||||||
|
|
||||||
function loadSite() {
|
function loadSite() {
|
||||||
return load(siteDir, {
|
return load(siteDir, {
|
||||||
|
customConfigFilePath: cliOptions.config,
|
||||||
locale: cliOptions.locale,
|
locale: cliOptions.locale,
|
||||||
localizePath: undefined, // should this be configurable?
|
localizePath: undefined, // should this be configurable?
|
||||||
});
|
});
|
||||||
|
@ -97,7 +98,7 @@ export default async function start(
|
||||||
|
|
||||||
const pathsToWatch: string[] = [
|
const pathsToWatch: string[] = [
|
||||||
...pluginPaths,
|
...pluginPaths,
|
||||||
CONFIG_FILE_NAME,
|
props.siteConfigPath,
|
||||||
getTranslationsLocaleDirPath({
|
getTranslationsLocaleDirPath({
|
||||||
siteDir,
|
siteDir,
|
||||||
locale: props.i18n.currentLocale,
|
locale: props.i18n.currentLocale,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* This source code is licensed under the MIT license found in the
|
* This source code is licensed under the MIT license found in the
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
import {ConfigOptions} from '@docusaurus/types';
|
||||||
import {loadContext, loadPluginConfigs} from '../server';
|
import {loadContext, loadPluginConfigs} from '../server';
|
||||||
import initPlugins, {InitPlugin} from '../server/plugins/init';
|
import initPlugins, {InitPlugin} from '../server/plugins/init';
|
||||||
|
|
||||||
|
@ -47,9 +48,12 @@ async function writePluginTranslationFiles({
|
||||||
|
|
||||||
export default async function writeTranslations(
|
export default async function writeTranslations(
|
||||||
siteDir: string,
|
siteDir: string,
|
||||||
options: WriteTranslationsOptions & {locale?: string},
|
options: WriteTranslationsOptions & ConfigOptions & {locale?: string},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const context = await loadContext(siteDir, {locale: options.locale});
|
const context = await loadContext(siteDir, {
|
||||||
|
customConfigFilePath: options.config,
|
||||||
|
locale: options.locale,
|
||||||
|
});
|
||||||
const pluginConfigs = loadPluginConfigs(context);
|
const pluginConfigs = loadPluginConfigs(context);
|
||||||
const plugins = initPlugins({
|
const plugins = initPlugins({
|
||||||
pluginConfigs,
|
pluginConfigs,
|
||||||
|
|
|
@ -5,10 +5,18 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const BABEL_CONFIG_FILE_NAME = 'babel.config.js';
|
// Can be overridden with cli option --out-dir
|
||||||
export const BUILD_DIR_NAME = 'build';
|
export const DEFAULT_BUILD_DIR_NAME = 'build';
|
||||||
export const CONFIG_FILE_NAME = 'docusaurus.config.js';
|
|
||||||
export const GENERATED_FILES_DIR_NAME = '.docusaurus';
|
// Can be overridden with cli option --config
|
||||||
|
export const DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
|
||||||
|
|
||||||
|
export const BABEL_CONFIG_FILE_NAME =
|
||||||
|
process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME || 'babel.config.js';
|
||||||
|
|
||||||
|
export const GENERATED_FILES_DIR_NAME =
|
||||||
|
process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME || '.docusaurus';
|
||||||
|
|
||||||
export const SRC_DIR_NAME = 'src';
|
export const SRC_DIR_NAME = 'src';
|
||||||
export const STATIC_DIR_NAME = 'static';
|
export const STATIC_DIR_NAME = 'static';
|
||||||
export const OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
|
export const OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
|
||||||
|
|
|
@ -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`] = `
|
exports[`loadConfig website with useless field (wrong field) in siteConfig 1`] = `
|
||||||
"\\"favicon\\" is required
|
"\\"favicon\\" is required
|
||||||
These field(s) [\\"useLessField\\",] are not recognized in docusaurus.config.js.
|
These field(s) [\\"useLessField\\",] are not recognized in docusaurus.config.js.
|
||||||
|
|
|
@ -10,31 +10,52 @@ import loadConfig from '../config';
|
||||||
|
|
||||||
describe('loadConfig', () => {
|
describe('loadConfig', () => {
|
||||||
test('website with valid siteConfig', async () => {
|
test('website with valid siteConfig', async () => {
|
||||||
const fixtures = path.join(__dirname, '__fixtures__');
|
const siteDir = path.join(
|
||||||
const siteDir = path.join(fixtures, 'simple-site');
|
__dirname,
|
||||||
|
'__fixtures__',
|
||||||
|
'simple-site',
|
||||||
|
'docusaurus.config.js',
|
||||||
|
);
|
||||||
const config = loadConfig(siteDir);
|
const config = loadConfig(siteDir);
|
||||||
expect(config).toMatchSnapshot();
|
expect(config).toMatchSnapshot();
|
||||||
expect(config).not.toEqual({});
|
expect(config).not.toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('website with incomplete siteConfig', () => {
|
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(() => {
|
expect(() => {
|
||||||
loadConfig(siteDir);
|
loadConfig(siteDir);
|
||||||
}).toThrowErrorMatchingSnapshot();
|
}).toThrowErrorMatchingSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('website with useless field (wrong field) in siteConfig', () => {
|
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(() => {
|
expect(() => {
|
||||||
loadConfig(siteDir);
|
loadConfig(siteDir);
|
||||||
}).toThrowErrorMatchingSnapshot();
|
}).toThrowErrorMatchingSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('website with no siteConfig', () => {
|
test('website with no siteConfig', () => {
|
||||||
const siteDir = path.join(__dirname, '__fixtures__', 'nonExisting');
|
const siteDir = path.join(
|
||||||
|
__dirname,
|
||||||
|
'__fixtures__',
|
||||||
|
'nonExisting',
|
||||||
|
'docusaurus.config.js',
|
||||||
|
);
|
||||||
expect(() => {
|
expect(() => {
|
||||||
loadConfig(siteDir);
|
loadConfig(siteDir);
|
||||||
}).toThrowErrorMatchingSnapshot();
|
}).toThrowError(
|
||||||
|
/Config file "(.*?)__fixtures__[/\\]nonExisting[/\\]docusaurus.config.js" not found$/,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,25 +7,12 @@
|
||||||
|
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import importFresh from 'import-fresh';
|
import importFresh from 'import-fresh';
|
||||||
import path from 'path';
|
|
||||||
import {DocusaurusConfig} from '@docusaurus/types';
|
import {DocusaurusConfig} from '@docusaurus/types';
|
||||||
import {CONFIG_FILE_NAME} from '../constants';
|
|
||||||
import {validateConfig} from './configValidation';
|
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)) {
|
if (!fs.existsSync(configPath)) {
|
||||||
throw new Error(
|
throw new Error(`Config file "${configPath}" not found`);
|
||||||
`${CONFIG_FILE_NAME} not found at ${toMessageRelativeFilePath(
|
|
||||||
configPath,
|
|
||||||
)}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadedConfig = importFresh(configPath) as Partial<DocusaurusConfig>;
|
const loadedConfig = importFresh(configPath) as Partial<DocusaurusConfig>;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DocusaurusConfig, I18nConfig} from '@docusaurus/types';
|
import {DocusaurusConfig, I18nConfig} from '@docusaurus/types';
|
||||||
import {CONFIG_FILE_NAME} from '../constants';
|
import {DEFAULT_CONFIG_FILE_NAME} from '../constants';
|
||||||
import Joi from 'joi';
|
import Joi from 'joi';
|
||||||
import {
|
import {
|
||||||
logValidationBugReportHint,
|
logValidationBugReportHint,
|
||||||
|
@ -164,7 +164,7 @@ export function validateConfig(
|
||||||
'',
|
'',
|
||||||
);
|
);
|
||||||
formattedError = unknownFields
|
formattedError = unknownFields
|
||||||
? `${formattedError}These field(s) [${unknownFields}] are not recognized in ${CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the 'customFields' attribute.\nSee https://v2.docusaurus.io/docs/docusaurus.config.js/#customfields`
|
? `${formattedError}These field(s) [${unknownFields}] are not recognized in ${DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the 'customFields' attribute.\nSee https://v2.docusaurus.io/docs/docusaurus.config.js/#customfields`
|
||||||
: formattedError;
|
: formattedError;
|
||||||
throw new Error(formattedError);
|
throw new Error(formattedError);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,8 +10,8 @@ import path, {join} from 'path';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import ssrDefaultTemplate from '../client/templates/ssr.html.template';
|
import ssrDefaultTemplate from '../client/templates/ssr.html.template';
|
||||||
import {
|
import {
|
||||||
BUILD_DIR_NAME,
|
DEFAULT_BUILD_DIR_NAME,
|
||||||
CONFIG_FILE_NAME,
|
DEFAULT_CONFIG_FILE_NAME,
|
||||||
GENERATED_FILES_DIR_NAME,
|
GENERATED_FILES_DIR_NAME,
|
||||||
THEME_PATH,
|
THEME_PATH,
|
||||||
} from '../constants';
|
} from '../constants';
|
||||||
|
@ -40,6 +40,7 @@ import {mapValues} from 'lodash';
|
||||||
|
|
||||||
type LoadContextOptions = {
|
type LoadContextOptions = {
|
||||||
customOutDir?: string;
|
customOutDir?: string;
|
||||||
|
customConfigFilePath?: string;
|
||||||
locale?: string;
|
locale?: string;
|
||||||
localizePath?: boolean; // undefined = only non-default locales paths are localized
|
localizePath?: boolean; // undefined = only non-default locales paths are localized
|
||||||
};
|
};
|
||||||
|
@ -48,17 +49,23 @@ export async function loadContext(
|
||||||
siteDir: string,
|
siteDir: string,
|
||||||
options: LoadContextOptions = {},
|
options: LoadContextOptions = {},
|
||||||
): Promise<LoadContext> {
|
): Promise<LoadContext> {
|
||||||
const {customOutDir, locale} = options;
|
const {customOutDir, locale, customConfigFilePath} = options;
|
||||||
const generatedFilesDir: string = path.resolve(
|
const generatedFilesDir = path.isAbsolute(GENERATED_FILES_DIR_NAME)
|
||||||
siteDir,
|
? GENERATED_FILES_DIR_NAME
|
||||||
GENERATED_FILES_DIR_NAME,
|
: path.resolve(siteDir, GENERATED_FILES_DIR_NAME);
|
||||||
);
|
|
||||||
const initialSiteConfig: DocusaurusConfig = loadConfig(siteDir);
|
const siteConfigPathUnresolved =
|
||||||
|
customConfigFilePath ?? DEFAULT_CONFIG_FILE_NAME;
|
||||||
|
const siteConfigPath = path.isAbsolute(siteConfigPathUnresolved)
|
||||||
|
? siteConfigPathUnresolved
|
||||||
|
: path.resolve(siteDir, siteConfigPathUnresolved);
|
||||||
|
|
||||||
|
const initialSiteConfig: DocusaurusConfig = loadConfig(siteConfigPath);
|
||||||
const {ssrTemplate} = initialSiteConfig;
|
const {ssrTemplate} = initialSiteConfig;
|
||||||
|
|
||||||
const baseOutDir = customOutDir
|
const baseOutDir = customOutDir
|
||||||
? path.resolve(customOutDir)
|
? path.resolve(customOutDir)
|
||||||
: path.resolve(siteDir, BUILD_DIR_NAME);
|
: path.resolve(siteDir, DEFAULT_BUILD_DIR_NAME);
|
||||||
|
|
||||||
const i18n = await loadI18n(initialSiteConfig, {locale});
|
const i18n = await loadI18n(initialSiteConfig, {locale});
|
||||||
|
|
||||||
|
@ -93,6 +100,7 @@ export async function loadContext(
|
||||||
siteDir,
|
siteDir,
|
||||||
generatedFilesDir,
|
generatedFilesDir,
|
||||||
siteConfig,
|
siteConfig,
|
||||||
|
siteConfigPath,
|
||||||
outDir,
|
outDir,
|
||||||
baseUrl,
|
baseUrl,
|
||||||
i18n,
|
i18n,
|
||||||
|
@ -122,6 +130,7 @@ export async function load(
|
||||||
const {
|
const {
|
||||||
generatedFilesDir,
|
generatedFilesDir,
|
||||||
siteConfig,
|
siteConfig,
|
||||||
|
siteConfigPath,
|
||||||
outDir,
|
outDir,
|
||||||
baseUrl,
|
baseUrl,
|
||||||
i18n,
|
i18n,
|
||||||
|
@ -149,7 +158,7 @@ export async function load(
|
||||||
// We want the generated config to have been normalized by the plugins!
|
// We want the generated config to have been normalized by the plugins!
|
||||||
const genSiteConfig = generate(
|
const genSiteConfig = generate(
|
||||||
generatedFilesDir,
|
generatedFilesDir,
|
||||||
CONFIG_FILE_NAME,
|
DEFAULT_CONFIG_FILE_NAME,
|
||||||
`export default ${JSON.stringify(siteConfig, null, 2)};`,
|
`export default ${JSON.stringify(siteConfig, null, 2)};`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -315,6 +324,7 @@ ${Object.keys(registry)
|
||||||
|
|
||||||
const props: Props = {
|
const props: Props = {
|
||||||
siteConfig,
|
siteConfig,
|
||||||
|
siteConfigPath,
|
||||||
siteDir,
|
siteDir,
|
||||||
outDir,
|
outDir,
|
||||||
baseUrl,
|
baseUrl,
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Module from 'module';
|
import Module from 'module';
|
||||||
import {join} from 'path';
|
|
||||||
import importFresh from 'import-fresh';
|
import importFresh from 'import-fresh';
|
||||||
import {
|
import {
|
||||||
DocusaurusPluginVersionInformation,
|
DocusaurusPluginVersionInformation,
|
||||||
|
@ -15,7 +14,7 @@ import {
|
||||||
PluginConfig,
|
PluginConfig,
|
||||||
PluginOptions,
|
PluginOptions,
|
||||||
} from '@docusaurus/types';
|
} from '@docusaurus/types';
|
||||||
import {CONFIG_FILE_NAME, DEFAULT_PLUGIN_ID} from '../../constants';
|
import {DEFAULT_PLUGIN_ID} from '../../constants';
|
||||||
import {getPluginVersion} from '../versions';
|
import {getPluginVersion} from '../versions';
|
||||||
import {ensureUniquePluginInstanceIds} from './pluginIds';
|
import {ensureUniquePluginInstanceIds} from './pluginIds';
|
||||||
import {
|
import {
|
||||||
|
@ -40,7 +39,7 @@ export default function initPlugins({
|
||||||
// We need to fallback to createRequireFromPath since createRequire is only available in node v12.
|
// We need to fallback to createRequireFromPath since createRequire is only available in node v12.
|
||||||
// See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
|
// See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
|
||||||
const createRequire = Module.createRequire || Module.createRequireFromPath;
|
const createRequire = Module.createRequire || Module.createRequireFromPath;
|
||||||
const pluginRequire = createRequire(join(context.siteDir, CONFIG_FILE_NAME));
|
const pluginRequire = createRequire(context.siteConfigPath);
|
||||||
|
|
||||||
const plugins: InitPlugin[] = pluginConfigs
|
const plugins: InitPlugin[] = pluginConfigs
|
||||||
.map((pluginItem) => {
|
.map((pluginItem) => {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {LoadContext} from '@docusaurus/types';
|
||||||
describe('loadPresets', () => {
|
describe('loadPresets', () => {
|
||||||
test('no presets', () => {
|
test('no presets', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {},
|
siteConfig: {},
|
||||||
} as LoadContext;
|
} as LoadContext;
|
||||||
const presets = loadPresets(context);
|
const presets = loadPresets(context);
|
||||||
|
@ -27,7 +27,7 @@ describe('loadPresets', () => {
|
||||||
|
|
||||||
test('string form', () => {
|
test('string form', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
presets: [path.join(__dirname, '__fixtures__/preset-bar.js')],
|
presets: [path.join(__dirname, '__fixtures__/preset-bar.js')],
|
||||||
},
|
},
|
||||||
|
@ -52,7 +52,7 @@ describe('loadPresets', () => {
|
||||||
|
|
||||||
test('string form composite', () => {
|
test('string form composite', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
presets: [
|
presets: [
|
||||||
path.join(__dirname, '__fixtures__/preset-bar.js'),
|
path.join(__dirname, '__fixtures__/preset-bar.js'),
|
||||||
|
@ -88,7 +88,7 @@ describe('loadPresets', () => {
|
||||||
|
|
||||||
test('array form', () => {
|
test('array form', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
presets: [[path.join(__dirname, '__fixtures__/preset-bar.js')]],
|
presets: [[path.join(__dirname, '__fixtures__/preset-bar.js')]],
|
||||||
},
|
},
|
||||||
|
@ -113,7 +113,7 @@ describe('loadPresets', () => {
|
||||||
|
|
||||||
test('array form with options', () => {
|
test('array form with options', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
|
@ -145,7 +145,7 @@ describe('loadPresets', () => {
|
||||||
|
|
||||||
test('array form composite', () => {
|
test('array form composite', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
|
@ -191,7 +191,7 @@ describe('loadPresets', () => {
|
||||||
|
|
||||||
test('mixed form', () => {
|
test('mixed form', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
|
@ -232,7 +232,7 @@ describe('loadPresets', () => {
|
||||||
|
|
||||||
test('mixed form with themes', () => {
|
test('mixed form with themes', () => {
|
||||||
const context = {
|
const context = {
|
||||||
siteDir: __dirname,
|
siteConfigPath: __dirname,
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Module from 'module';
|
import Module from 'module';
|
||||||
import {join} from 'path';
|
|
||||||
import importFresh from 'import-fresh';
|
import importFresh from 'import-fresh';
|
||||||
import {CONFIG_FILE_NAME} from '../../constants';
|
|
||||||
import {
|
import {
|
||||||
LoadContext,
|
LoadContext,
|
||||||
PluginConfig,
|
PluginConfig,
|
||||||
|
@ -27,7 +25,7 @@ export default function loadPresets(
|
||||||
// We need to fallback to createRequireFromPath since createRequire is only available in node v12.
|
// We need to fallback to createRequireFromPath since createRequire is only available in node v12.
|
||||||
// See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
|
// See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename
|
||||||
const createRequire = Module.createRequire || Module.createRequireFromPath;
|
const createRequire = Module.createRequire || Module.createRequireFromPath;
|
||||||
const pluginRequire = createRequire(join(context.siteDir, CONFIG_FILE_NAME));
|
const pluginRequire = createRequire(context.siteConfigPath);
|
||||||
|
|
||||||
const presets: PresetConfig[] = (context.siteConfig || {}).presets || [];
|
const presets: PresetConfig[] = (context.siteConfig || {}).presets || [];
|
||||||
const unflatPlugins: PluginConfig[][] = [];
|
const unflatPlugins: PluginConfig[][] = [];
|
||||||
|
|
|
@ -30,7 +30,7 @@ import TOCInline from "@theme/TOCInline"
|
||||||
|
|
||||||
Below is a list of Docusaurus CLI commands and their usages:
|
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).
|
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`. |
|
| `--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). |
|
| `--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. |
|
| `--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). |
|
| `--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
|
:::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/`
|
4. Open `https://localhost:3000/`
|
||||||
|
|
||||||
### `docusaurus build`
|
### `docusaurus build [siteDir]`
|
||||||
|
|
||||||
Compiles your site for production.
|
Compiles your site for production.
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ Compiles your site for production.
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `--bundle-analyzer` | `false` | Analyze your bundle with the [webpack bundle analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer). |
|
| `--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. |
|
| `--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` |
|
||||||
| `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. |
|
| `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. |
|
||||||
|
|
||||||
:::info
|
:::info
|
||||||
|
@ -84,7 +86,7 @@ For advanced minification of CSS bundle, we use the [advanced cssnano preset](ht
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
### `docusaurus swizzle`
|
### `docusaurus swizzle [siteDir]`
|
||||||
|
|
||||||
:::caution
|
:::caution
|
||||||
|
|
||||||
|
@ -133,7 +135,7 @@ TODO a separate section for swizzle tutorial.
|
||||||
To learn more about swizzling, check [here](#).
|
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.
|
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 +145,9 @@ 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. |
|
| `--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. |
|
| `--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` |
|
||||||
|
|
||||||
### `docusaurus serve`
|
### `docusaurus serve [siteDir]`
|
||||||
|
|
||||||
Serve your built website locally.
|
Serve your built website locally.
|
||||||
|
|
||||||
|
@ -153,15 +156,16 @@ Serve your built website locally.
|
||||||
| `--port` | `3000` | Use specified port |
|
| `--port` | `3000` | Use specified port |
|
||||||
| `--dir` | `build` | The full path for the output directory, relative to the current workspace |
|
| `--dir` | `build` | The full path for the output directory, relative to the current workspace |
|
||||||
| `--build` | `false` | Build website before serving |
|
| `--build` | `false` | Build website before serving |
|
||||||
|
| `--config` | `undefined` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
|
||||||
| `--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`. |
|
| `--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.
|
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.
|
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.
|
Write the JSON translation files that you will have to translate.
|
||||||
|
|
||||||
|
@ -171,4 +175,5 @@ By default, the files are written in `website/i18n/<defaultLocale>/...`.
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `--locale` | `<defaultLocale>` | Define which locale folder you want to write translations the JSON files in |
|
| `--locale` | `<defaultLocale>` | Define which locale folder you want to write translations the JSON files in |
|
||||||
| `--override` | `false` | Override existing translation messages |
|
| `--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 |
|
| `--messagePrefix` | `''` | Allows to add a prefix to each translation message, to help you highlight untranslated strings |
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
"build:baseUrl": "cross-env BASE_URL='/build/' yarn build",
|
"build:baseUrl": "cross-env BASE_URL='/build/' yarn build",
|
||||||
"start:bootstrap": "cross-env DOCUSAURUS_PRESET=bootstrap yarn start",
|
"start:bootstrap": "cross-env DOCUSAURUS_PRESET=bootstrap yarn start",
|
||||||
"build:bootstrap": "cross-env DOCUSAURUS_PRESET=bootstrap yarn build",
|
"build:bootstrap": "cross-env DOCUSAURUS_PRESET=bootstrap yarn build",
|
||||||
"start:blogOnly": "cross-env DOCUSAURUS_CONFIG='docusaurus.config-blog-only.js' yarn start",
|
"start:blogOnly": "cross-env yarn start --config=docusaurus.config-blog-only.js",
|
||||||
"build:blogOnly": "cross-env DOCUSAURUS_CONFIG='docusaurus.config-blog-only.js' yarn build",
|
"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: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": "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",
|
"netlify:build:deployPreview:classic": "cross-env BASE_URL='/classic/' yarn build --out-dir netlifyDeployPreview/classic",
|
||||||
|
|
Loading…
Add table
Reference in a new issue