mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-28 15:37:49 +02:00
feat(v2): blog + docs multi-instance plugins (#3204)
* stable createData namespacing + second-blog dogfooding * Docs: support multi-instance + make community docs a separate instance * tests: add 2nd docs instance to versioned site * fix docs version cli tests * fix docs versioning cli * typo * team: add link to my site * better extendCli integration * fix metadata tests * tests for versioned site with second docs instance * move some validation code to utils-validation * fix missing dependency * fix bad compiled output due to importing constants in ./client folder * make docs tests easier to maintain * refactors * prevent lodash imports in client bundle * redirect old community docs to new urls
This commit is contained in:
parent
e944f35640
commit
59f705ee66
67 changed files with 2025 additions and 2059 deletions
|
@ -14,29 +14,36 @@ import fs from 'fs-extra';
|
|||
import path from 'path';
|
||||
import {Sidebar, PathOptions, SidebarItem} from './types';
|
||||
import loadSidebars from './sidebars';
|
||||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
||||
|
||||
// Tests depend on non-default export for mocking.
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export function docsVersion(
|
||||
version: string | null | undefined,
|
||||
siteDir: string,
|
||||
pluginId: string,
|
||||
options: PathOptions,
|
||||
): void {
|
||||
// It wouldn't be very user-friendly to show a [default] log prefix,
|
||||
// so we use [docs] instead of [default]
|
||||
const pluginIdLogPrefix =
|
||||
pluginId === DEFAULT_PLUGIN_ID ? '[docs] ' : `[${pluginId}] `;
|
||||
|
||||
if (!version) {
|
||||
throw new Error(
|
||||
'No version tag specified!. Pass the version you wish to create as an argument. Ex: 1.0.0',
|
||||
`${pluginIdLogPrefix}No version tag specified!. Pass the version you wish to create as an argument. Ex: 1.0.0`,
|
||||
);
|
||||
}
|
||||
|
||||
if (version.includes('/') || version.includes('\\')) {
|
||||
throw new Error(
|
||||
`Invalid version tag specified! Do not include slash (/) or (\\). Try something like: 1.0.0`,
|
||||
`${pluginIdLogPrefix}Invalid version tag specified! Do not include slash (/) or (\\). Try something like: 1.0.0`,
|
||||
);
|
||||
}
|
||||
|
||||
if (version.length > 32) {
|
||||
throw new Error(
|
||||
'Invalid version tag specified! Length must <= 32 characters. Try something like: 1.0.0',
|
||||
`${pluginIdLogPrefix}Invalid version tag specified! Length must <= 32 characters. Try something like: 1.0.0`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -44,19 +51,19 @@ export function docsVersion(
|
|||
// sure it's a valid pathname.
|
||||
if (/[<>:"\/\\|?*\x00-\x1F]/g.test(version)) {
|
||||
throw new Error(
|
||||
'Invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0',
|
||||
`${pluginIdLogPrefix}Invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0`,
|
||||
);
|
||||
}
|
||||
|
||||
if (/^\.\.?$/.test(version)) {
|
||||
throw new Error(
|
||||
'Invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0',
|
||||
`${pluginIdLogPrefix}Invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0`,
|
||||
);
|
||||
}
|
||||
|
||||
// Load existing versions.
|
||||
let versions = [];
|
||||
const versionsJSONFile = getVersionsJSONFile(siteDir);
|
||||
const versionsJSONFile = getVersionsJSONFile(siteDir, pluginId);
|
||||
if (fs.existsSync(versionsJSONFile)) {
|
||||
versions = JSON.parse(fs.readFileSync(versionsJSONFile, 'utf8'));
|
||||
}
|
||||
|
@ -64,7 +71,7 @@ export function docsVersion(
|
|||
// Check if version already exists.
|
||||
if (versions.includes(version)) {
|
||||
throw new Error(
|
||||
'This version already exists!. Use a version tag that does not already exist.',
|
||||
`${pluginIdLogPrefix}This version already exists!. Use a version tag that does not already exist.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -73,11 +80,11 @@ export function docsVersion(
|
|||
// Copy docs files.
|
||||
const docsDir = path.join(siteDir, docsPath);
|
||||
if (fs.existsSync(docsDir) && fs.readdirSync(docsDir).length > 0) {
|
||||
const versionedDir = getVersionedDocsDir(siteDir);
|
||||
const versionedDir = getVersionedDocsDir(siteDir, pluginId);
|
||||
const newVersionDir = path.join(versionedDir, `version-${version}`);
|
||||
fs.copySync(docsDir, newVersionDir);
|
||||
} else {
|
||||
throw new Error('There is no docs to version !');
|
||||
throw new Error(`${pluginIdLogPrefix}There is no docs to version !`);
|
||||
}
|
||||
|
||||
// Load current sidebar and create a new versioned sidebars file.
|
||||
|
@ -109,7 +116,7 @@ export function docsVersion(
|
|||
{},
|
||||
);
|
||||
|
||||
const versionedSidebarsDir = getVersionedSidebarsDir(siteDir);
|
||||
const versionedSidebarsDir = getVersionedSidebarsDir(siteDir, pluginId);
|
||||
const newSidebarFile = path.join(
|
||||
versionedSidebarsDir,
|
||||
`version-${version}-sidebars.json`,
|
||||
|
@ -127,5 +134,5 @@ export function docsVersion(
|
|||
fs.ensureDirSync(path.dirname(versionsJSONFile));
|
||||
fs.writeFileSync(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
|
||||
|
||||
console.log(`Version ${version} created!`);
|
||||
console.log(`${pluginIdLogPrefix}Version ${version} created!`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue