Skip to content

Commit

Permalink
Merge pull request #11622 from storybookjs/fix/11609-generate-docs-js…
Browse files Browse the repository at this point in the history
…on-command-dynamically

CLI: Generate `docs:json` command dynamically for Angular project
  • Loading branch information
shilman authored Jul 21, 2020
2 parents 8afa7af + 6d79ed2 commit 129ea83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cypress/generated/addon-viewport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('addon-viewport', () => {
});

it('should have viewport button in the toolbar', () => {
cy.navigateToStory('button', 'Text');
cy.navigateToStory('example-button', 'Primary');

// Click on viewport button and select small mobile
cy.get('[title="Change the size of the preview"]').click();
Expand Down
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 129ea83

Please sign in to comment.