Skip to content

Commit

Permalink
improve compodoc args in the angular builder to allow specifying a cu…
Browse files Browse the repository at this point in the history
…stom outputh path
  • Loading branch information
blackthread committed Aug 19, 2022
1 parent 06ffa29 commit b15e527
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
71 changes: 71 additions & 0 deletions code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
);
});

});
4 changes: 2 additions & 2 deletions code/frameworks/angular/src/builders/utils/run-compodoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,8 +22,7 @@ export const runCompodoc = (
'compodoc',
// Default options
...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]),
'-d',
`${context.workspaceRoot}`,
...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot}`]),
...compodocArgs,
];

Expand Down

0 comments on commit b15e527

Please sign in to comment.