Skip to content

Commit c211e63

Browse files
committed
Add support for packageOptions
Resolves #2523
1 parent 1c6e5a5 commit c211e63

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- Added new `--projectDocuments` option to specify additional Markdown documents to be included in the generated site #247, #1870, #2288, #2565.
3939
- TypeDoc now has the architecture in place to support localization. No languages besides English
4040
are currently shipped in the package, but it is now possible to add support for additional languages, #2475.
41+
- Added support for a `packageOptions` object which specifies options that should be applied to each entry point when running with `--entryPointStrategy packages`, #2523.
4142
- `--hostedBaseUrl` will now be used to generate a `<link rel="canonical">` element in the project root page, #2550.
4243
- New option, `--customFooterHtml` to add custom HTML to the generated page footer, #2559.
4344
- Added three new sort strategies `documents-first`, `documents-last`, and `alphabetical-ignoring-documents` to order markdown documents.

src/lib/application.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,20 @@ export class Application extends ChildableComponent<
627627
// Generate a json file for each package
628628
for (const dir of packageDirs) {
629629
this.logger.verbose(`Reading project at ${nicePath(dir)}`);
630-
const opts = origOptions.copyForPackage(dir);
630+
let opts: Options;
631+
try {
632+
opts = origOptions.copyForPackage(dir);
633+
} catch (error) {
634+
ok(error instanceof Error);
635+
this.logger.error(error.message as TranslatedString);
636+
this.logger.info(
637+
this.i18n.previous_error_occurred_when_reading_options_for_0(
638+
nicePath(dir),
639+
),
640+
);
641+
continue;
642+
}
643+
631644
await opts.read(this.logger, dir);
632645
// Invalid links should only be reported after everything has been merged.
633646
opts.setValue("validation", { invalidLink: false });

src/lib/internationalization/translatable.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export const translatable = {
3636
"Failed to find any packages, ensure you have provided at least one directory as an entry point containing package.json",
3737
nested_packages_unsupported_0:
3838
"Project at {0} has entryPointStrategy set to packages, but nested packages are not supported.",
39+
previous_error_occurred_when_reading_options_for_0:
40+
"The previous error occurred when reading options for the package at {0}",
3941
converting_project_at_0: "Converting project at {0}",
4042
failed_to_convert_packages:
4143
"Failed to convert one or more packages, result will not be merged together.",
@@ -173,6 +175,8 @@ export const translatable = {
173175
"Sets the language to be used in generation and in TypeDoc's messages.",
174176
help_locales:
175177
"Add translations for a specified locale. This option is primarily intended to be used as a stopgap while waiting for official locale support to be added to TypeDoc.",
178+
help_packageOptions:
179+
"Set options which will be set within each package when entryPointStrategy is set to packages.",
176180

177181
help_entryPoints: "The entry points of your documentation.",
178182
help_entryPointStrategy:

src/lib/utils/options/declaration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface TypeDocOptionMap {
9999
plugin: string[];
100100
lang: string;
101101
locales: ManuallyValidatedOption<Record<string, Record<string, string>>>;
102+
packageOptions: ManuallyValidatedOption<TypeDocOptions>;
102103

103104
// Input
104105
entryPoints: string[];

src/lib/utils/options/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ export class Options {
119119
options._declarations = new Map(this._declarations);
120120
options.reset();
121121

122+
for (const [key, val] of Object.entries(
123+
this.getValue("packageOptions"),
124+
)) {
125+
options.setValue(key as any, val, packageDir);
126+
}
127+
122128
return options;
123129
}
124130

src/lib/utils/options/sources/typedoc.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
7878
}
7979
},
8080
});
81+
options.addDeclaration({
82+
name: "packageOptions",
83+
help: (i18n) => i18n.help_packageOptions(),
84+
type: ParameterType.Mixed,
85+
configFileOnly: true,
86+
defaultValue: {},
87+
validate(value, i18n) {
88+
if (!Validation.validate({}, value)) {
89+
throw new Error(
90+
i18n.option_0_must_be_an_object("packageOptions"),
91+
);
92+
}
93+
},
94+
});
8195

8296
///////////////////////////
8397
////// Input Options //////

0 commit comments

Comments
 (0)