Skip to content

Commit

Permalink
Merge pull request #18334 from stefanoslig/feat/angular-cli-default-p…
Browse files Browse the repository at this point in the history
…roject-deprecation

feat(cli): Add support for angular/cli@14.0.0
  • Loading branch information
yannbf committed Jun 3, 2022
2 parents 6e63509 + e5841e4 commit 95bd68d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
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

0 comments on commit 95bd68d

Please sign in to comment.