Skip to content

Commit

Permalink
refactor(core): reorganize files (#7042)
Browse files Browse the repository at this point in the history
* refactor(core): reorganize files

* fix types
  • Loading branch information
Josh-Cena authored Mar 28, 2022
1 parent 85a79fd commit 5fb09a2
Show file tree
Hide file tree
Showing 61 changed files with 1,090 additions and 1,029 deletions.
4 changes: 2 additions & 2 deletions packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ declare module '@generated/docusaurus.config' {
}

declare module '@generated/site-metadata' {
import type {DocusaurusSiteMetadata} from '@docusaurus/types';
import type {SiteMetadata} from '@docusaurus/types';

const siteMetadata: DocusaurusSiteMetadata;
const siteMetadata: SiteMetadata;
export = siteMetadata;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-plugin-content-blog/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type {BlogContent, BlogPaginated} from './types';
import type {TranslationFileContent, TranslationFiles} from '@docusaurus/types';
import type {TranslationFileContent, TranslationFile} from '@docusaurus/types';
import type {PluginOptions} from '@docusaurus/plugin-content-blog';

function translateListPage(
Expand All @@ -27,7 +27,7 @@ function translateListPage(
});
}

export function getTranslationFiles(options: PluginOptions): TranslationFiles {
export function getTranslationFiles(options: PluginOptions): TranslationFile[] {
return [
{
path: 'options',
Expand All @@ -51,7 +51,7 @@ export function getTranslationFiles(options: PluginOptions): TranslationFiles {

export function translateContent(
content: BlogContent,
translationFiles: TranslationFiles,
translationFiles: TranslationFile[],
): BlogContent {
const {content: optionsTranslations} = translationFiles[0]!;
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('simple site', () => {
loadSiteOptions: {options: Partial<PluginOptions>} = {options: {}},
) {
const siteDir = path.join(fixtureDir, 'simple-site');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const options = {
id: DEFAULT_PLUGIN_ID,
...DEFAULT_OPTIONS,
Expand Down Expand Up @@ -523,7 +523,8 @@ describe('versioned site', () => {
},
) {
const siteDir = path.join(fixtureDir, 'versioned-site');
const context = await loadContext(siteDir, {
const context = await loadContext({
siteDir,
locale: loadSiteOptions.locale,
});
const options = {
Expand Down
28 changes: 14 additions & 14 deletions packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Entries created:
describe('sidebar', () => {
it('site with wrong sidebar content', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const sidebarPath = path.join(siteDir, 'wrong-sidebars.json');
const plugin = await pluginContentDocs(
context,
Expand All @@ -131,7 +131,7 @@ describe('sidebar', () => {

it('site with wrong sidebar file path', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'site-with-doc-label');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});

await expect(async () => {
const plugin = await pluginContentDocs(
Expand All @@ -155,7 +155,7 @@ describe('sidebar', () => {

it('site with undefined sidebar', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'site-with-doc-label');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const plugin = await pluginContentDocs(
context,
validateOptions({
Expand All @@ -173,7 +173,7 @@ describe('sidebar', () => {

it('site with disabled sidebar', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'site-with-doc-label');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const plugin = await pluginContentDocs(
context,
validateOptions({
Expand All @@ -194,7 +194,7 @@ describe('empty/no docs website', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'empty-site');

it('no files in docs folder', async () => {
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
await fs.ensureDir(path.join(siteDir, 'docs'));
const plugin = await pluginContentDocs(
context,
Expand All @@ -208,7 +208,7 @@ describe('empty/no docs website', () => {
});

it('docs folder does not exist', async () => {
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
await expect(
pluginContentDocs(
context,
Expand All @@ -228,7 +228,7 @@ describe('empty/no docs website', () => {
describe('simple website', () => {
async function loadSite() {
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const sidebarPath = path.join(siteDir, 'sidebars.json');
const plugin = await pluginContentDocs(
context,
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('simple website', () => {
describe('versioned website', () => {
async function loadSite() {
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const sidebarPath = path.join(siteDir, 'sidebars.json');
const routeBasePath = 'docs';
const plugin = await pluginContentDocs(
Expand Down Expand Up @@ -470,7 +470,7 @@ describe('versioned website', () => {
describe('versioned website (community)', () => {
async function loadSite() {
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const sidebarPath = path.join(siteDir, 'community_sidebars.json');
const routeBasePath = 'community';
const pluginId = 'community';
Expand Down Expand Up @@ -578,7 +578,7 @@ describe('versioned website (community)', () => {
describe('site with doc label', () => {
async function loadSite() {
const siteDir = path.join(__dirname, '__fixtures__', 'site-with-doc-label');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const sidebarPath = path.join(siteDir, 'sidebars.json');
const plugin = await pluginContentDocs(
context,
Expand Down Expand Up @@ -620,7 +620,7 @@ describe('site with full autogenerated sidebar', () => {
'__fixtures__',
'site-with-autogenerated-sidebar',
);
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const plugin = await pluginContentDocs(
context,
validateOptions({
Expand Down Expand Up @@ -675,7 +675,7 @@ describe('site with partial autogenerated sidebars', () => {
'__fixtures__',
'site-with-autogenerated-sidebar',
);
const context = await loadContext(siteDir, {});
const context = await loadContext({siteDir});
const plugin = await pluginContentDocs(
context,
validateOptions({
Expand Down Expand Up @@ -731,7 +731,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
'__fixtures__',
'site-with-autogenerated-sidebar',
);
const context = await loadContext(siteDir, {});
const context = await loadContext({siteDir});
const plugin = await pluginContentDocs(
context,
validateOptions({
Expand Down Expand Up @@ -768,7 +768,7 @@ describe('site with custom sidebar items generator', () => {
'__fixtures__',
'site-with-autogenerated-sidebar',
);
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const plugin = await pluginContentDocs(
context,
validateOptions({
Expand Down
7 changes: 3 additions & 4 deletions packages/docusaurus-plugin-content-docs/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
import type {
TranslationFileContent,
TranslationFile,
TranslationFiles,
TranslationMessage,
} from '@docusaurus/types';
import {mergeTranslations} from '@docusaurus/utils';
Expand Down Expand Up @@ -242,7 +241,7 @@ function translateSidebars(
);
}

function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
function getVersionTranslationFiles(version: LoadedVersion): TranslationFile[] {
const versionTranslations: TranslationFileContent = {
'version.label': {
message: version.label,
Expand Down Expand Up @@ -283,7 +282,7 @@ function translateVersion(

function getVersionsTranslationFiles(
versions: LoadedVersion[],
): TranslationFiles {
): TranslationFile[] {
return versions.flatMap(getVersionTranslationFiles);
}
function translateVersions(
Expand All @@ -295,7 +294,7 @@ function translateVersions(

export function getLoadedContentTranslationFiles(
loadedContent: LoadedContent,
): TranslationFiles {
): TranslationFile[] {
return getVersionsTranslationFiles(loadedContent.loadedVersions);
}
export function translateLoadedContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {normalizePluginOptions} from '@docusaurus/utils-validation';
describe('docusaurus-plugin-content-pages', () => {
it('loads simple pages', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const plugin = await pluginContentPages(
context,
validateOptions({
Expand All @@ -32,7 +32,7 @@ describe('docusaurus-plugin-content-pages', () => {

it('loads simple pages with french translations', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext(siteDir);
const context = await loadContext({siteDir});
const plugin = await pluginContentPages(
{
...context,
Expand Down
Loading

0 comments on commit 5fb09a2

Please sign in to comment.