Skip to content

Commit

Permalink
Merge pull request #26214 from storybookjs/kasper/fix-angular-compodocs
Browse files Browse the repository at this point in the history
Angular: Use dedicated tsconfig for compodocs
  • Loading branch information
valentinpalkovic authored Feb 28, 2024
2 parents 524d657 + 5728f0e commit 9d26611
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
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"]
}

0 comments on commit 9d26611

Please sign in to comment.