Skip to content

Commit

Permalink
fix(cli): generate docs:json NPM script dynamically according to ts…
Browse files Browse the repository at this point in the history
…config file

Angular CLI 10 introduced a `tsconfig.base.json` file that we have to use to generate doc with compodoc.
So if `tsconfig.base.json` exist then use it, otherwise assume there is a `tsconfig.json` file
  • Loading branch information
gaetanmaisse committed Jul 20, 2020
1 parent 8afa7af commit 4a0c9a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/cli/src/generators/ANGULAR/angular-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as path from 'path';
import * as fs from 'fs';
import { pathExists } from 'fs-extra';

import { readFileAsJson, writeFileAsJson } from '../../helpers';

type TsConfig = {
Expand Down Expand Up @@ -52,3 +54,7 @@ export function isDefaultProjectSet() {
const angularJson = readFileAsJson('angular.json', true);
return angularJson && !!angularJson.defaultProject;
}

export async function getBaseTsConfigName() {
return (await pathExists('./tsconfig.base.json')) ? 'tsconfig.base.json' : 'tsconfig.json';
}
4 changes: 3 additions & 1 deletion lib/cli/src/generators/ANGULAR/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
editStorybookTsConfig,
getAngularAppTsConfigJson,
getAngularAppTsConfigPath,
getBaseTsConfigName,
} from './angular-helpers';
import { writeFileAsJson, copyTemplate } from '../../helpers';
import { baseGenerator, Generator } from '../baseGenerator';
Expand Down Expand Up @@ -40,8 +41,9 @@ const generator: Generator = async (packageManager, npmOptions, options) => {
editStorybookTsConfig(path.resolve('./.storybook/tsconfig.json'));

// edit scripts to generate docs
const tsConfigFile = await getBaseTsConfigName();
packageManager.addScripts({
'docs:json': 'compodoc -p ./tsconfig.base.json -e json -d .',
'docs:json': `compodoc -p ./${tsConfigFile} -e json -d .`,
});
packageManager.addStorybookCommandInScripts({
port: 6006,
Expand Down

0 comments on commit 4a0c9a9

Please sign in to comment.