Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular: Use dedicated tsconfig for compodocs #26214

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions code/frameworks/angular/src/builders/build-storybook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ const commandBuilder: BuilderHandlerFn<StorybookBuilderOptions> = (
): BuilderOutputLike => {
const builder = from(setup(options, context)).pipe(
switchMap(({ tsConfig }) => {
const docTSConfig = findUpSync('tsconfig.doc.json', { cwd: options.configDir });
const runCompodoc$ = options.compodoc
? runCompodoc({ compodocArgs: options.compodocArgs, tsconfig: tsConfig }, context).pipe(
mapTo({ tsConfig })
)
? runCompodoc(
{ compodocArgs: options.compodocArgs, tsconfig: docTSConfig ?? tsConfig },
context
).pipe(mapTo({ tsConfig }))
: of({});

return runCompodoc$.pipe(mapTo({ tsConfig }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ export type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
const commandBuilder: BuilderHandlerFn<StorybookBuilderOptions> = (options, context) => {
const builder = from(setup(options, context)).pipe(
switchMap(({ tsConfig }) => {
const docTSConfig = findUpSync('tsconfig.doc.json', { cwd: options.configDir });

const runCompodoc$ = options.compodoc
? runCompodoc(
{
compodocArgs: [...options.compodocArgs, ...(options.quiet ? ['--silent'] : [])],
tsconfig: tsConfig,
tsconfig: docTSConfig ?? tsConfig,
},
context
).pipe(mapTo({ tsConfig }))
Expand Down
14 changes: 14 additions & 0 deletions code/lib/cli/src/generators/ANGULAR/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { join } from 'path';
import prompts from 'prompts';
import dedent from 'ts-dedent';
import { MissingAngularJsonError } from '@storybook/core-events/server-errors';
import boxen from 'boxen';
import { logger } from '@storybook/node-logger';

export const ANGULAR_JSON_PATH = 'angular.json';

Expand All @@ -13,6 +15,18 @@ export const compoDocPreviewPrefix = dedent`
`.trimStart();

export const promptForCompoDocs = async (): Promise<boolean> => {
logger.plain(
// Create a text which explains the user why compodoc is necessary
boxen(
dedent`
Compodoc is a great tool to generate documentation for your Angular projects.
Storybook can use the documentation generated by Compodoc to extract argument definitions
and JSDOC comments to display them in the Storybook UI. We highly recommend using Compodoc for
your Angular projects to get the best experience out of Storybook.
`,
{ title: 'Compodoc', borderStyle: 'round', padding: 1, borderColor: '#F1618C' }
)
);
const { useCompoDoc } = await prompts({
type: 'confirm',
name: 'useCompoDoc',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This tsconfig is used by Compodoc to generate the documentation for the project.
// If Compodoc is not used, this file can be deleted.
{
"extends": "./tsconfig.json",
// Exclude all files that are not needed for documentation generation.
"exclude": ["../src/test.ts", "../src/**/*.spec.ts", "../src/**/*.stories.ts"],
// Please make sure to include all files from which Compodoc should generate documentation.
"include": ["../src/**/*"],
"files": ["./typings.d.ts"]
}
Loading