From b15e5272d3136b1e267d364216364bb1330c9c0c Mon Sep 17 00:00:00 2001 From: skeyen Date: Fri, 19 Aug 2022 11:22:27 +0200 Subject: [PATCH] improve compodoc args in the angular builder to allow specifying a custom outputh path --- .../src/builders/utils/run-compodoc.spec.ts | 71 +++++++++++++++++++ .../src/builders/utils/run-compodoc.ts | 4 +- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts b/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts index 900bc6a7669f..7b31eb45795b 100644 --- a/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts +++ b/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts @@ -77,4 +77,75 @@ describe('runCompodoc', () => { } ); }); + + + it('should run compodoc with default output folder.', async () => { + runCompodoc( + { + compodocArgs: [], + tsconfig: 'path/to/tsconfig.json', + }, + { + workspaceRoot: 'path/to/project', + logger: builderContextLoggerMock, + } as BuilderContext + ) + .pipe(take(1)) + .subscribe(); + + expect(cpSpawnMock.spawn).toHaveBeenCalledWith( + 'npx', + ['compodoc', '-p', 'path/to/tsconfig.json', '-d', 'path/to/project'], + { + cwd: 'path/to/project', + } + ); + }); + + it('should run with custom output folder specified with --output compodocArgs', async () => { + runCompodoc( + { + compodocArgs: ['--output', 'path/to/customFolder'], + tsconfig: 'path/to/tsconfig.json', + }, + { + workspaceRoot: 'path/to/project', + logger: builderContextLoggerMock, + } as BuilderContext + ) + .pipe(take(1)) + .subscribe(); + + expect(cpSpawnMock.spawn).toHaveBeenCalledWith( + 'npx', + ['compodoc', '-p', 'path/to/tsconfig.json', '--output', 'path/to/customFolder'], + { + cwd: 'path/to/project', + } + ); + }); + + it('should run with custom output folder specified with -d compodocArgs', async () => { + runCompodoc( + { + compodocArgs: ['-d', 'path/to/customFolder'], + tsconfig: 'path/to/tsconfig.json', + }, + { + workspaceRoot: 'path/to/project', + logger: builderContextLoggerMock, + } as BuilderContext + ) + .pipe(take(1)) + .subscribe(); + + expect(cpSpawnMock.spawn).toHaveBeenCalledWith( + 'npx', + ['compodoc', '-p', 'path/to/tsconfig.json', '-d', 'path/to/customFolder'], + { + cwd: 'path/to/project', + } + ); + }); + }); diff --git a/code/frameworks/angular/src/builders/utils/run-compodoc.ts b/code/frameworks/angular/src/builders/utils/run-compodoc.ts index 74551841046b..5b8c3729895c 100644 --- a/code/frameworks/angular/src/builders/utils/run-compodoc.ts +++ b/code/frameworks/angular/src/builders/utils/run-compodoc.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; import * as path from 'path'; const hasTsConfigArg = (args: string[]) => args.indexOf('-p') !== -1; +const hasOutputArg = (args: string[]) => args.indexOf('-d') !== -1 || args.indexOf('--output') !== -1 // path.relative is necessary to workaround a compodoc issue with // absolute paths on windows machines @@ -21,8 +22,7 @@ export const runCompodoc = ( 'compodoc', // Default options ...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]), - '-d', - `${context.workspaceRoot}`, + ...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot}`]), ...compodocArgs, ];