From 4a0c9a9b0db5a465824cb138a3913ac662143788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Mon, 20 Jul 2020 21:17:07 +0200 Subject: [PATCH] fix(cli): generate `docs:json` NPM script dynamically according to tsconfig 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 --- lib/cli/src/generators/ANGULAR/angular-helpers.ts | 6 ++++++ lib/cli/src/generators/ANGULAR/index.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/cli/src/generators/ANGULAR/angular-helpers.ts b/lib/cli/src/generators/ANGULAR/angular-helpers.ts index cf38ccf2c642..bd9eecfa2bab 100644 --- a/lib/cli/src/generators/ANGULAR/angular-helpers.ts +++ b/lib/cli/src/generators/ANGULAR/angular-helpers.ts @@ -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 = { @@ -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'; +} diff --git a/lib/cli/src/generators/ANGULAR/index.ts b/lib/cli/src/generators/ANGULAR/index.ts index 9d0e5344df2d..57a4758a41ad 100644 --- a/lib/cli/src/generators/ANGULAR/index.ts +++ b/lib/cli/src/generators/ANGULAR/index.ts @@ -4,6 +4,7 @@ import { editStorybookTsConfig, getAngularAppTsConfigJson, getAngularAppTsConfigPath, + getBaseTsConfigName, } from './angular-helpers'; import { writeFileAsJson, copyTemplate } from '../../helpers'; import { baseGenerator, Generator } from '../baseGenerator'; @@ -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,