Skip to content

Commit

Permalink
fix: Packages output filename fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Dec 18, 2023
1 parent 5a82139 commit 5f453c8
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-swans-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': patch
---

- Packages output file fixes
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function header(
): string {
const isPackages =
context.options.getValue('entryPointStrategy') ===
EntryPointStrategy.Packages && !Boolean(page.project.groups);
EntryPointStrategy.Packages;
if (isPackages) {
const packageItem = findPackage(page.model);
if (packageItem) {
Expand Down
77 changes: 43 additions & 34 deletions packages/typedoc-plugin-markdown/src/theme/urls-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,45 +82,54 @@ export class UrlsContext {
}

if (isPackages) {
this.project.children?.forEach((projectChild) => {
const preservePackageReadme =
Boolean(projectChild.readme) && !this.options.getValue('mergeReadme');

const packagesIndex = getIndexFileName(projectChild);
const packageMeta = (this.renderer as any).packages[projectChild.name];

const outputFileStrategy =
packageMeta.outputFileStrategy ||
this.options.getValue('outputFileStrategy');

const url = `${projectChild.name}/${
preservePackageReadme ? packagesIndex : entryFileName
}`;

if (preservePackageReadme) {
this.urls.push(
new UrlMapping(
`${path.dirname(url)}/${entryFileName}`,
projectChild as any,
this.theme.readmeTemplate,
),
);
}

this.urls.push(
new UrlMapping(url, projectChild as any, this.theme.projectTemplate),
);

projectChild.url = url;

this.buildUrlsFromProject(projectChild, url, outputFileStrategy);
});
if (Object.keys((this.renderer as any).packages)?.length === 1) {
this.buildUrlsFromProject(this.project);
} else {
this.project.children?.forEach((projectChild) => {
this.buildUrlsFromPackage(projectChild);
});
}
} else {
this.buildUrlsFromProject(this.project);
}
return this.urls;
}

private buildUrlsFromPackage(projectChild: DeclarationReflection) {
const entryFileName = this.options.getValue('entryFileName');
const preservePackageReadme =
Boolean(projectChild.readme) && !this.options.getValue('mergeReadme');

const packagesIndex = getIndexFileName(projectChild);
const packageMeta = (this.renderer as any).packages[projectChild.name];

const outputFileStrategy =
packageMeta?.outputFileStrategy ||
this.options.getValue('outputFileStrategy');

const url = `${projectChild.name}/${
preservePackageReadme ? packagesIndex : entryFileName
}`;

if (preservePackageReadme) {
this.urls.push(
new UrlMapping(
`${path.dirname(url)}/${entryFileName}`,
projectChild as any,
this.theme.readmeTemplate,
),
);
}

this.urls.push(
new UrlMapping(url, projectChild as any, this.theme.projectTemplate),
);

projectChild.url = url;

this.buildUrlsFromProject(projectChild, url, outputFileStrategy);
}

/**
*
* @param project
Expand Down Expand Up @@ -190,7 +199,7 @@ export class UrlsContext {
OutputFileStrategy.Modules &&
reflection.name === 'index'
) {
return `module.index.md`;
return urlPath.replace('index.md', 'module.index.md');
}
return urlPath;
}
Expand Down
15 changes: 15 additions & 0 deletions packages/typedoc-plugin-markdown/test/__utils__/fixture-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum FixtureOutputFileStrategy {
export enum FixtureEntryPoints {
Reflections = '/src/reflections/index.ts',
Packages = '/src/packages/*',
Package = '/src/packages/package-1',
Groups = '/src/groups/**/*.ts',
Comments = '/src/comments/index.ts',
EntryFiles = '/src/entryfiles/*',
Expand All @@ -18,6 +19,7 @@ export enum FixtureEntryPoints {
export enum FixtureOutputDir {
Reflections = 'reflections',
Packages = 'packages',
Package = 'package',
Groups = 'groups',
Comments = 'comments',
EntryFiles = 'entryfiles',
Expand Down Expand Up @@ -105,12 +107,25 @@ export const FIXTURES: Fixture[] = [
entryPointStrategy: 'packages',
hideGenerator: true,
name: 'packages-example',
hideInPageTOC: true,
},
options: [
{},
{ mergeReadme: true, includeVersion: true, indexPageTitle: 'API' },
],
},
{
outDir: FixtureOutputDir.Package,
entryPoints: FixtureEntryPoints.Package,
commonOptions: {
entryPointStrategy: 'packages',
hideGenerator: true,
name: 'packages-example',
includeVersion: true,
hideInPageTOC: true,
},
options: [{}],
},
{
outDir: FixtureOutputDir.EntryFiles,
entryPoints: FixtureEntryPoints.EntryFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,25 @@ exports[`Navigation should get Navigation Json for packages: (Output File Strate
},
{
"title": "package-3",
"children": [],
"children": [
{
"title": "Modules",
"children": [
{
"title": "index",
"url": "package-3/index/index.md"
},
{
"title": "module-1",
"url": "package-3/module-1/index.md"
},
{
"title": "module-2",
"url": "package-3/module-2/index.md"
}
]
}
],
"url": "package-3/index.md"
},
{
Expand Down Expand Up @@ -109,7 +127,25 @@ exports[`Navigation should get Navigation Json for packages: (Output File Strate
},
{
"title": "package-3",
"children": [],
"children": [
{
"title": "Modules",
"children": [
{
"title": "index",
"url": "package-3/module.index.md"
},
{
"title": "module-1",
"url": "package-3/module-1.md"
},
{
"title": "module-2",
"url": "package-3/module-2.md"
}
]
}
],
"url": "package-3/index.md"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ exports[`Urls should gets Urls for packages entry points: outputFileStrategy: me
"package-2/module-1/interfaces/PackageInterface1.md",
"package-2/module-2/index.md",
"package-2/module-2/interfaces/PackageInterface2.md",
"package-3/index/index.md",
"package-3/index.md",
"package-3/module-1/index.md",
"package-3/module-2/index.md",
"package-4/index.md",
"package-4/interfaces/PackageInterface.md",
"packages.md",
Expand All @@ -197,7 +200,10 @@ exports[`Urls should gets Urls for packages entry points: outputFileStrategy: me
"package-2/module-1/interfaces/PackageInterface1.md",
"package-2/module-2/index.md",
"package-2/module-2/interfaces/PackageInterface2.md",
"package-3/index/index.md",
"package-3/index.md",
"package-3/module-1/index.md",
"package-3/module-2/index.md",
"package-4/index.md",
"package-4/interfaces/PackageInterface.md",
]
Expand All @@ -212,6 +218,9 @@ exports[`Urls should gets Urls for packages entry points: outputFileStrategy: mo
"package-2/module-1.md",
"package-2/module-2.md",
"package-3/index.md",
"package-3/module-1.md",
"package-3/module-2.md",
"package-3/module.index.md",
"package-4/index.md",
"package-4/interfaces/PackageInterface.md",
"packages.md",
Expand All @@ -226,6 +235,9 @@ exports[`Urls should gets Urls for packages entry points: outputFileStrategy: mo
"package-2/module-1.md",
"package-2/module-2.md",
"package-3/index.md",
"package-3/module-1.md",
"package-3/module-2.md",
"package-3/module.index.md",
"package-4/index.md",
"package-4/interfaces/PackageInterface.md",
]
Expand Down Expand Up @@ -363,3 +375,18 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: modu
"index.md",
]
`;

exports[`Urls should gets Urls for single package entry points: outputFileStrategy: members 1`] = `
[
"index.md",
"interfaces/PackageInterface.md",
"packages.md",
]
`;

exports[`Urls should gets Urls for single package entry points: outputFileStrategy: modules 1`] = `
[
"index.md",
"packages.md",
]
`;
7 changes: 7 additions & 0 deletions packages/typedoc-plugin-markdown/test/specs/urls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ describe(`Urls`, () => {
]);
});

test(`should gets Urls for single package entry points`, () => {
expectUrlsToEqual(FixtureOutputDir.Package, [
FixtureOutputFileStrategy.Members,
FixtureOutputFileStrategy.Modules,
]);
});

test(`should gets Urls for entry module`, () => {
expectUrlsToEqual(FixtureOutputDir.EntryFiles, [
FixtureOutputFileStrategy.Members,
Expand Down
1 change: 0 additions & 1 deletion stubs/src/packages/package-3/index.ts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
export interface PackageInterface {}
1 change: 1 addition & 0 deletions stubs/src/packages/package-3/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface PackageInterface1 {}
1 change: 1 addition & 0 deletions stubs/src/packages/package-3/src/module-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface PackageInterface1 {}
1 change: 1 addition & 0 deletions stubs/src/packages/package-3/src/module-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface PackageInterface2 {}
2 changes: 1 addition & 1 deletion stubs/src/packages/package-3/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"entryPoints": ["./index.ts"],
"entryPoints": ["./src/index.ts", "./src/module-1.ts", "./src/module-2.ts"],
"readme": "none",
"outputFileStrategy": "modules"
}

0 comments on commit 5f453c8

Please sign in to comment.