mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
add git eager VCS preset
This commit is contained in:
parent
cf016c69f5
commit
1bc1bcf024
|
|
@ -7,10 +7,12 @@
|
|||
|
||||
import {VcsHardcoded} from './vcsHardcoded';
|
||||
import {VcsGitAdHoc} from './vcsGitAdHoc';
|
||||
import {VscGitEager} from './vcsGitEager';
|
||||
import type {VcsConfig} from '@docusaurus/types';
|
||||
|
||||
const VcsPresets = {
|
||||
'git-ad-hoc': VcsGitAdHoc,
|
||||
'git-eager': VscGitEager,
|
||||
hardcoded: VcsHardcoded,
|
||||
} as const satisfies Record<string, VcsConfig>;
|
||||
|
||||
|
|
@ -34,7 +36,9 @@ function getDefaultVcsConfig(): VcsConfig {
|
|||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
return getVcsPreset('git-ad-hoc');
|
||||
// TODO add feature flag switch for git-eager / git-ad-hoc strategies
|
||||
// return getVcsPreset('git-ad-hoc');
|
||||
return getVcsPreset('git-eager');
|
||||
}
|
||||
|
||||
// Return hardcoded values in dev to improve DX
|
||||
|
|
|
|||
|
|
@ -8,13 +8,12 @@
|
|||
import {resolve} from 'node:path';
|
||||
import {realpath} from 'node:fs/promises';
|
||||
import execa from 'execa';
|
||||
import {DEFAULT_VCS_CONFIG} from '@docusaurus/utils';
|
||||
import {PerfLogger} from '@docusaurus/logger';
|
||||
import type {VcsConfig} from '@docusaurus/types';
|
||||
|
||||
async function getGitRepoRoot(cwd: string): Promise<string> {
|
||||
async function getGitRepoRoot(filePath: string): Promise<string> {
|
||||
const result = await execa('git', ['rev-parse', '--show-toplevel'], {
|
||||
cwd,
|
||||
cwd: filePath,
|
||||
});
|
||||
|
||||
if (result.exitCode !== 0) {
|
||||
|
|
@ -40,8 +39,8 @@ type GitRepositoryInfo = {files: GitFilesInfo};
|
|||
// Logic inspired from Astro Starlight:
|
||||
// See https://bsky.app/profile/bluwy.me/post/3lyihod6qos2a
|
||||
// See https://github.com/withastro/starlight/blob/c417f1efd463be63b7230617d72b120caed098cd/packages/starlight/utils/git.ts#L58
|
||||
async function loadGitFiles(cwd: string): Promise<GitFilesInfo> {
|
||||
const repoRoot = await getGitRepoRoot(cwd);
|
||||
async function loadGitFiles(filePath: string): Promise<GitFilesInfo> {
|
||||
const repoRoot = await getGitRepoRoot(filePath);
|
||||
|
||||
// git -c log.showSignature=false log --format=t:%ct,a:%an --name-status
|
||||
const result = await execa(
|
||||
|
|
@ -141,23 +140,14 @@ The command exited with code ${result.exitCode}: ${result.stderr}`,
|
|||
return new Map(Array.from(runningMap.entries()).map(transformMapEntry));
|
||||
}
|
||||
|
||||
async function loadGitRepository(cwd: string): Promise<GitRepositoryInfo> {
|
||||
return PerfLogger.async('getGitRepoLastCommitInfoMap', async () => {
|
||||
const files = await loadGitFiles(cwd);
|
||||
async function loadGitRepository(filePath: string): Promise<GitRepositoryInfo> {
|
||||
return PerfLogger.async('loadGitRepository', async () => {
|
||||
const files = await loadGitFiles(filePath);
|
||||
return {files};
|
||||
});
|
||||
}
|
||||
|
||||
function createGitVcsConfig(): VcsConfig {
|
||||
if (process.env.DOCUSAURUS_WEBSITE_USE_OLD_VCS_STRATEGY === 'true') {
|
||||
console.log("Using the old Docusaurus website's VCS strategy");
|
||||
return DEFAULT_VCS_CONFIG;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// return DEFAULT_VCS_CONFIG;
|
||||
}
|
||||
|
||||
// TODO need to support multiple repositories (git submodules, etc.)
|
||||
let repositoryPromise: Promise<GitRepositoryInfo> | null = null;
|
||||
|
||||
|
|
@ -194,4 +184,4 @@ function createGitVcsConfig(): VcsConfig {
|
|||
};
|
||||
}
|
||||
|
||||
export const customSiteVcsImplementation: VcsConfig = createGitVcsConfig();
|
||||
export const VscGitEager: VcsConfig = createGitVcsConfig();
|
||||
|
|
@ -25,8 +25,6 @@ import ConfigLocalized from './docusaurus.config.localized.json';
|
|||
import PrismLight from './src/utils/prismLight';
|
||||
import PrismDark from './src/utils/prismDark';
|
||||
|
||||
import {customSiteVcsImplementation} from './vcs';
|
||||
|
||||
import type {Config, DocusaurusConfig} from '@docusaurus/types';
|
||||
|
||||
import type * as Preset from '@docusaurus/preset-classic';
|
||||
|
|
@ -192,7 +190,7 @@ export default async function createConfigAsync() {
|
|||
experimental_storage: {
|
||||
namespace: true,
|
||||
},
|
||||
experimental_vcs: customSiteVcsImplementation,
|
||||
// experimental_vcs: customSiteVcsImplementation,
|
||||
experimental_router: router,
|
||||
},
|
||||
// Dogfood both settings:
|
||||
|
|
|
|||
Loading…
Reference in New Issue