Skip to content

Commit

Permalink
fix(core): further typedoc beta fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jun 2, 2024
1 parent a6cf4bc commit 48fbe69
Show file tree
Hide file tree
Showing 95 changed files with 1,902 additions and 1,048 deletions.
5 changes: 5 additions & 0 deletions devtools/packages/fixtures/typedoc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ module.exports = {
navigation: {
includeGroups: true,
},
locales: {
en: {
theme_defined_in: 'Source',
},
},
};
2 changes: 1 addition & 1 deletion devtools/packages/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const PRESETS_PATH = `${process.cwd()}/src/options/presets.ts`;
export const DOCS_CONFIG: Record<string, DocsConfig> = {
['typedoc-plugin-markdown']: {
declarationsPath: `${process.cwd()}/src/options/declarations.ts`,
translatablePath: `${process.cwd()}/src/app/translatable.ts`,
translatablePath: `${process.cwd()}/src/app/internationalization/locales/en.ts`,
optionsPath: '/docs',
docsPath: '/docs',
declarations: true,
Expand Down
6 changes: 5 additions & 1 deletion devtools/packages/prebuild-options/tasks/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ ${presetsJson}
if (
option.type !== ParameterType.Flags &&
option.type !== ParameterType.Array &&
option.type !== ParameterType.Mixed
option.type !== ParameterType.Mixed &&
option.type !== ParameterType.Object
) {
meta.push(`Defaults to \`${getDefaultValue(option)}\`.`);
}
Expand Down Expand Up @@ -306,6 +307,9 @@ function getDefaultValue(option) {
if (option.type === ParameterType.Mixed) {
return JSON.stringify(option.defaultValue);
}
if (option.type === ParameterType.Object) {
return JSON.stringify(option.defaultValue);
}
return `"${option.defaultValue}"`;
}

Expand Down
53 changes: 49 additions & 4 deletions devtools/packages/prebuild-options/tasks/generate-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ async function writeOptionsTypes(
option.type === ParameterType.Mixed && option.defaultValue,
);

const optionsOutput = `
// THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY.
const optionsOutput: string[] = [
`// THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY.
`,
];
optionsOutput.push(`
/**
* Describes the options declared by the plugin.
*
Expand Down Expand Up @@ -117,20 +120,41 @@ ${name}: ${getType(name, option, true)};`,
`;
})
.join('\n')}
`;
`);

const optionsModelFile = path.join(
path.dirname(docsConfig.declarationsPath as string),
'option-types.ts',
);

const formatted = await prettier.format(optionsOutput, {
const formatted = await prettier.format(optionsOutput.join('\n\n'), {
parser: 'typescript',
singleQuote: true,
trailingComma: 'all',
});

fs.writeFileSync(optionsModelFile, formatted);

if (docsConfig.translatablePath) {
const translatableOutput: string[] = [
'// THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY.',
];
const { translatable } = await import(docsConfig.translatablePath);
translatableOutput.push(
`
export interface TranslatableStrings ${getTranslationsInterface(translatable)}`,
);
const formatted = await prettier.format(translatableOutput.join('\n\n'), {
parser: 'typescript',
singleQuote: true,
trailingComma: 'all',
});
const translatableModelFile = path.join(
path.dirname(docsConfig.translatablePath as string),
'../translatable-types.ts',
);
fs.writeFileSync(translatableModelFile, formatted);
}
}

function getTranslations(inputObject: { [key: string]: string }) {
Expand All @@ -142,6 +166,14 @@ function getTranslations(inputObject: { [key: string]: string }) {
return JSON.stringify(output).replace(/"/g, '');
}

function getTranslationsInterface(inputObject: { [key: string]: string }) {
const output: { [key: string]: string } = {};
for (const [key] of Object.entries(inputObject)) {
output[key] = 'string';
}
return JSON.stringify(output).replace(/"/g, '');
}

function getComments(name: string) {
if (name === 'textContentMappings') {
return 'Describes the keys available to replace static text.';
Expand Down Expand Up @@ -208,9 +240,22 @@ function getType(
.map((value) => `"${value}"`)
.join(' | ')}`;
}
if (option.type === ParameterType.Object) {
const outType = `{${Object.keys(option.defaultValue as any)
.map((key) => `'${key}': ${getObjectType(name)};`)
.join('')}}`;
return isInterface ? outType : `ManuallyValidatedOption<${outType}>`;
}
return 'any';
}

function getObjectType(name: string) {
if (name === 'reflectionFormats') {
return "'list'|'table'|'htmlTable'";
}
return 'string';
}

function capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
43 changes: 30 additions & 13 deletions docs/pages/api-docs/Class.MarkdownPageEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,81 @@ export function load(app: MarkdownApplication) {

### project

> **project**: [`ProjectReflection`](https://typedoc.org/api/classes/Models.ProjectReflection.html)
```ts
project: ProjectReflection;
```

The project the renderer is currently processing.
The [`ProjectReflection`](https://typedoc.org/api/classes/Models.ProjectReflection.html) instance the renderer is currently processing.

***

### model

> `readonly` **model**: `Model`
```ts
readonly model: Model;
```

The model that should be rendered on this page.
The model that that is being rendered on this page.
Either a [`DeclarationReflection`](https://typedoc.org/api/classes/Models.DeclarationReflection.html) or [`ProjectReflection`](https://typedoc.org/api/classes/Models.ProjectReflection.html).

***

### url

> **url**: `string`
```ts
url: string;
```

The url this page will be located at.
The url `string` of the page.

***

### filename

> **filename**: `string`
```ts
filename: string;
```

The filename the page will be written to.
The complete `string` filename where the file will be written..

***

### contents?

> `optional` **contents**: `string`
```ts
optional contents: string;
```

The final markdown content of this page.
The final markdown `string` content of the page.

Should be rendered by layout templates and can be modified by plugins.

***

### frontmatter?

> `optional` **frontmatter**: `Record`\<`string`, `any`\>
```ts
optional frontmatter: Record<string, any>;
```

The frontmatter of this page represented as a key value object. This property can be utilised by other plugins.

## Events

### BEGIN

> `static` `readonly` **BEGIN**: `"beginPage"` = `'beginPage'`
```ts
static readonly BEGIN: "beginPage" = 'beginPage';
```

Triggered before a document will be rendered.

***

### END

> `static` `readonly` **END**: `"endPage"` = `'endPage'`
```ts
static readonly END: "endPage" = 'endPage';
```

Triggered after a document has been rendered, just before it is written to disc.
24 changes: 18 additions & 6 deletions docs/pages/api-docs/Class.MarkdownRendererEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,58 @@ app.renderer.on(MarkdownRendererEvent.BEGIN, (event) => {

### project

> `readonly` **project**: [`ProjectReflection`](https://typedoc.org/api/classes/Models.ProjectReflection.html)
```ts
readonly project: ProjectReflection;
```

The project the renderer is currently processing.

***

### outputDirectory

> `readonly` **outputDirectory**: `string`
```ts
readonly outputDirectory: string;
```

The path of the directory the documentation should be written to.

***

### urls?

> `optional` **urls**: [`UrlMapping`](/api-docs/Interface.UrlMapping.md)\<[`Reflection`](https://typedoc.org/api/classes/Models.Reflection.html)\>[]
```ts
optional urls: UrlMapping<Reflection>[];
```

A list of all pages that should be generated.

***

### navigation?

> `optional` **navigation**: [`NavigationItem`](/api-docs/Interface.NavigationItem.md)[]
```ts
optional navigation: NavigationItem[];
```

The navigation structure of the project that can be utilised by plugins.

## Events

### BEGIN

> `static` `readonly` **BEGIN**: `"beginRender"` = `'beginRender'`
```ts
static readonly BEGIN: "beginRender" = 'beginRender';
```

Triggered before the renderer starts rendering a project.

***

### END

> `static` `readonly` **END**: `"endRender"` = `'endRender'`
```ts
static readonly END: "endRender" = 'endRender';
```

Triggered after the renderer has written all documents.
36 changes: 33 additions & 3 deletions docs/pages/api-docs/Class.MarkdownTheme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,37 @@ class MyMarkdownTheme extends MarkdownTheme {

- [`Theme`](https://typedoc.org/api/classes/Theme.html)

## Constructors

### new MarkdownTheme()

```ts
new MarkdownTheme(owner): MarkdownTheme
```

Create new Component instance.

#### Parameters

| Parameter | Type |
| :------ | :------ |
| `owner` | [`Renderer`](https://typedoc.org/api/classes/Renderer.html) |

#### Returns

[`MarkdownTheme`](/api-docs/Class.MarkdownTheme.md)

#### Inherited from

`Theme.constructor`

## Methods

### getRenderContext()

> **getRenderContext**(`page`): [`MarkdownThemeContext`](/api-docs/Class.MarkdownThemeContext.md)
```ts
getRenderContext(page): MarkdownThemeContext
```

Creates a new instance of the current theme context.

Expand All @@ -48,7 +74,9 @@ This method can be overridden to provide an alternative theme context.

### getUrls()

> **getUrls**(`project`): [`UrlMapping`](/api-docs/Interface.UrlMapping.md)\<[`Reflection`](https://typedoc.org/api/classes/Models.Reflection.html)\>[]
```ts
getUrls(project): UrlMapping<Reflection>[]
```

Maps the models of the given project to the desired output files.

Expand All @@ -72,7 +100,9 @@ This method can be overriden to provide an alternative url structure.

### getNavigation()

> **getNavigation**(`project`): [`NavigationItem`](/api-docs/Interface.NavigationItem.md)[]
```ts
getNavigation(project): NavigationItem[]
```

Map the models of the given project to a navigation structure.

Expand Down
Loading

0 comments on commit 48fbe69

Please sign in to comment.