Skip to content

Commit

Permalink
Merge pull request #22663 from storybookjs/chore/angular-json-issues
Browse files Browse the repository at this point in the history
CLI: Improve error handling when dealing with angular.json files
  • Loading branch information
valentinpalkovic authored and shilman committed May 22, 2023
1 parent 1f2b405 commit 9780e77
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions code/lib/cli/src/generators/ANGULAR/index.ts
Expand Up @@ -27,17 +27,33 @@ const generator: Generator<{ projectName: string }> = async (

const angularJSON = new AngularJSON();

if (
!angularJSON.projects ||
(angularJSON.projects && Object.keys(angularJSON.projects).length === 0)
) {
throw new Error(
'Storybook was not able to find any projects in your angular.json file. Are you sure this is an Angular CLI project?'
);
}

if (angularJSON.projectsWithoutStorybook.length === 0) {
throw new Error(
'Every project in your workspace is already set up with Storybook. There is nothing to do!'
);
}

const angularProjectName = await angularJSON.getProjectName();

paddedLog(`Adding Storybook support to your "${angularProjectName}" project`);

const { root, projectType } = angularJSON.getProjectSettingsByName(angularProjectName);
const angularProject = angularJSON.getProjectSettingsByName(angularProjectName);

if (!angularProject) {
throw new Error(
`Somehow we were not able to retrieve the "${angularProjectName}" project in your angular.json file. This is likely a bug in Storybook, please file an issue.`
);
}

const { root, projectType } = angularProject;
const { projects } = angularJSON;
const useCompodoc = commandOptions.yes ? true : await promptForCompoDocs();
const storybookFolder = root ? `${root}/.storybook` : '.storybook';
Expand Down

0 comments on commit 9780e77

Please sign in to comment.