Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Improve error handling when dealing with angular.json files #22663

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions code/lib/cli/src/generators/ANGULAR/index.ts
Original file line number Diff line number Diff line change
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