-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Expand file tree
/
Copy pathrun-compodoc.ts
More file actions
41 lines (35 loc) · 1.31 KB
/
run-compodoc.ts
File metadata and controls
41 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { BuilderContext } from '@angular-devkit/architect';
import * as path from 'path';
import { JsPackageManagerFactory } from '@storybook/core-common';
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
const toRelativePath = (pathToTsConfig: string) => {
return path.isAbsolute(pathToTsConfig) ? path.relative('.', pathToTsConfig) : pathToTsConfig;
};
export const runCompodoc = async (
{ compodocArgs, tsconfig }: { compodocArgs: string[]; tsconfig: string },
context: BuilderContext
): Promise<void> => {
const tsConfigPath = toRelativePath(tsconfig);
const finalCompodocArgs = [
...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]),
...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot || '.'}`]),
...compodocArgs,
];
const packageManager = JsPackageManagerFactory.getPackageManager();
try {
const stdout = packageManager.runPackageCommandSync(
'compodoc',
finalCompodocArgs,
context.workspaceRoot,
'inherit'
);
context.logger.info(stdout);
} catch (e) {
context.logger.error(e);
throw e;
}
};