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

feat(cli): Add support for angular/cli@14.0.0 #18334

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions lib/cli/src/generators/ANGULAR/angular-helpers.ts
Expand Up @@ -10,7 +10,7 @@ type TsConfig = {

export function getAngularAppTsConfigPath() {
const angularJson = readFileAsJson('angular.json', true);
const { defaultProject } = angularJson;
const defaultProject = getDefaultProjectName(angularJson);
const tsConfigPath = angularJson.projects[defaultProject].architect.build.options.tsConfig;

if (!tsConfigPath || !fs.existsSync(path.resolve(tsConfigPath))) {
Expand Down Expand Up @@ -50,9 +50,33 @@ export function editStorybookTsConfig(tsconfigPath: string) {
writeFileAsJson(tsconfigPath, tsConfigJson);
}

export function isDefaultProjectSet() {
const angularJson = readFileAsJson('angular.json', true);
return angularJson && !!angularJson.defaultProject;
export function getDefaultProjectName(angularJson: any): string | undefined {
const { defaultProject, projects } = angularJson;

if (projects?.storybook) {
return 'storybook';
}

if (defaultProject) {
return defaultProject;
}

const firstProjectName = projects ? Object.keys(projects)[0] : undefined;
if (firstProjectName) {
return firstProjectName;
}

return undefined;
}

export function checkForProjects() {
const { projects } = readFileAsJson('angular.json', true);

if (!projects || Object.keys(projects).length === 0) {
throw new Error(
'Could not find a project in your Angular workspace. \nAdd a project and re-run the installation'
);
}
}

export async function getBaseTsConfigName() {
Expand Down
9 changes: 3 additions & 6 deletions lib/cli/src/generators/ANGULAR/index.ts
@@ -1,7 +1,7 @@
import path from 'path';
import semver from '@storybook/semver';
import {
isDefaultProjectSet,
checkForProjects,
editStorybookTsConfig,
getAngularAppTsConfigJson,
getAngularAppTsConfigPath,
Expand All @@ -28,11 +28,8 @@ function editAngularAppTsConfig() {
}

const generator: Generator = async (packageManager, npmOptions, options) => {
if (!isDefaultProjectSet()) {
throw new Error(
'Could not find a default project in your Angular workspace.\nSet a defaultProject in your angular.json and re-run the installation.'
);
}
checkForProjects();

const angularVersion = semver.coerce(
packageManager.retrievePackageJson().dependencies['@angular/core']
)?.version;
Expand Down