mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
fix: use realpath for site dir to resolve symlink (#5684)
This commit is contained in:
parent
fee10c9e13
commit
543011c9d2
1 changed files with 28 additions and 34 deletions
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const path = require('path');
|
const fs = require('fs');
|
||||||
const cli = require('commander');
|
const cli = require('commander');
|
||||||
const {
|
const {
|
||||||
build,
|
build,
|
||||||
|
@ -23,6 +23,8 @@ const {
|
||||||
|
|
||||||
require('./beforeCli');
|
require('./beforeCli');
|
||||||
|
|
||||||
|
const resolveDir = (dir = '.') => fs.realpathSync(dir);
|
||||||
|
|
||||||
cli.version(require('../package.json').version).usage('<command> [options]');
|
cli.version(require('../package.json').version).usage('<command> [options]');
|
||||||
|
|
||||||
cli
|
cli
|
||||||
|
@ -48,8 +50,8 @@ cli
|
||||||
'--no-minify',
|
'--no-minify',
|
||||||
'build website without minimizing JS bundles (default: false)',
|
'build website without minimizing JS bundles (default: false)',
|
||||||
)
|
)
|
||||||
.action((siteDir = '.', {bundleAnalyzer, config, outDir, locale, minify}) => {
|
.action((siteDir, {bundleAnalyzer, config, outDir, locale, minify}) => {
|
||||||
build(path.resolve(siteDir), {
|
build(resolveDir(siteDir), {
|
||||||
bundleAnalyzer,
|
bundleAnalyzer,
|
||||||
outDir,
|
outDir,
|
||||||
config,
|
config,
|
||||||
|
@ -66,14 +68,8 @@ cli
|
||||||
'copy TypeScript theme files when possible (default: false)',
|
'copy TypeScript theme files when possible (default: false)',
|
||||||
)
|
)
|
||||||
.option('--danger', 'enable swizzle for internal component of themes')
|
.option('--danger', 'enable swizzle for internal component of themes')
|
||||||
.action((themeName, componentName, siteDir = '.', {typescript, danger}) => {
|
.action((themeName, componentName, siteDir, {typescript, danger}) => {
|
||||||
swizzle(
|
swizzle(resolveDir(siteDir), themeName, componentName, typescript, danger);
|
||||||
path.resolve(siteDir),
|
|
||||||
themeName,
|
|
||||||
componentName,
|
|
||||||
typescript,
|
|
||||||
danger,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cli
|
cli
|
||||||
|
@ -95,8 +91,8 @@ cli
|
||||||
'--skip-build',
|
'--skip-build',
|
||||||
'skip building website before deploy it (default: false)',
|
'skip building website before deploy it (default: false)',
|
||||||
)
|
)
|
||||||
.action((siteDir = '.', {outDir, skipBuild, config}) => {
|
.action((siteDir, {outDir, skipBuild, config}) => {
|
||||||
deploy(path.resolve(siteDir), {
|
deploy(resolveDir(siteDir), {
|
||||||
outDir,
|
outDir,
|
||||||
config,
|
config,
|
||||||
skipBuild,
|
skipBuild,
|
||||||
|
@ -122,19 +118,17 @@ cli
|
||||||
'--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(
|
.action((siteDir, {port, host, locale, config, hotOnly, open, poll}) => {
|
||||||
(siteDir = '.', {port, host, locale, config, hotOnly, open, poll}) => {
|
start(resolveDir(siteDir), {
|
||||||
start(path.resolve(siteDir), {
|
port,
|
||||||
port,
|
host,
|
||||||
host,
|
locale,
|
||||||
locale,
|
config,
|
||||||
config,
|
hotOnly,
|
||||||
hotOnly,
|
open,
|
||||||
open,
|
poll,
|
||||||
poll,
|
});
|
||||||
});
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
cli
|
cli
|
||||||
.command('serve [siteDir]')
|
.command('serve [siteDir]')
|
||||||
|
@ -152,7 +146,7 @@ cli
|
||||||
.option('-h, --host <host>', 'use specified host (default: localhost)')
|
.option('-h, --host <host>', 'use specified host (default: localhost)')
|
||||||
.action(
|
.action(
|
||||||
(
|
(
|
||||||
siteDir = '.',
|
siteDir,
|
||||||
{
|
{
|
||||||
dir = 'build',
|
dir = 'build',
|
||||||
port = 3000,
|
port = 3000,
|
||||||
|
@ -161,7 +155,7 @@ cli
|
||||||
config,
|
config,
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
serve(path.resolve(siteDir), {
|
serve(resolveDir(siteDir), {
|
||||||
dir,
|
dir,
|
||||||
port,
|
port,
|
||||||
build: buildSite,
|
build: buildSite,
|
||||||
|
@ -174,8 +168,8 @@ cli
|
||||||
cli
|
cli
|
||||||
.command('clear [siteDir]')
|
.command('clear [siteDir]')
|
||||||
.description('Remove build artifacts.')
|
.description('Remove build artifacts.')
|
||||||
.action((siteDir = '.') => {
|
.action((siteDir) => {
|
||||||
clear(path.resolve(siteDir));
|
clear(resolveDir(siteDir));
|
||||||
});
|
});
|
||||||
|
|
||||||
cli
|
cli
|
||||||
|
@ -199,10 +193,10 @@ cli
|
||||||
)
|
)
|
||||||
.action(
|
.action(
|
||||||
(
|
(
|
||||||
siteDir = '.',
|
siteDir,
|
||||||
{locale = undefined, override = false, messagePrefix = '', config},
|
{locale = undefined, override = false, messagePrefix = '', config},
|
||||||
) => {
|
) => {
|
||||||
writeTranslations(path.resolve(siteDir), {
|
writeTranslations(resolveDir(siteDir), {
|
||||||
locale,
|
locale,
|
||||||
override,
|
override,
|
||||||
config,
|
config,
|
||||||
|
@ -214,7 +208,7 @@ cli
|
||||||
cli
|
cli
|
||||||
.command('write-heading-ids [contentDir]')
|
.command('write-heading-ids [contentDir]')
|
||||||
.description('Generate heading ids in Markdown content.')
|
.description('Generate heading ids in Markdown content.')
|
||||||
.action((siteDir = '.') => {
|
.action((siteDir) => {
|
||||||
writeHeadingIds(siteDir);
|
writeHeadingIds(siteDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -239,7 +233,7 @@ function isInternalCommand(command) {
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
||||||
await externalCommand(cli, path.resolve('.'));
|
await externalCommand(cli, resolveDir('.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.parse(process.argv);
|
cli.parse(process.argv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue