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

Output-compodoc-args #20338

Merged
merged 5 commits into from
Dec 20, 2022
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
69 changes: 69 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 @@ -79,4 +79,73 @@ 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',
}
);
});
});
5 changes: 3 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,8 @@ 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 +23,7 @@ export const runCompodoc = (
'compodoc',
// Default options
...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]),
'-d',
`${context.workspaceRoot}`,
...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot}`]),
...compodocArgs,
];

Expand Down