Skip to content

Commit

Permalink
feat(cli): Add support for angular/cli@14.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefanos Lignos Zivver committed May 26, 2022
1 parent 13b40e3 commit 8601ed1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 18 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,23 @@ 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 {
const { defaultProject, projects } = angularJson;

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

if (defaultProject) {
return defaultProject;
}

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

throw new Error('No angular projects found');
}

export async function getBaseTsConfigName() {
Expand Down
6 changes: 0 additions & 6 deletions lib/cli/src/generators/ANGULAR/index.ts
@@ -1,7 +1,6 @@
import path from 'path';
import semver from '@storybook/semver';
import {
isDefaultProjectSet,
editStorybookTsConfig,
getAngularAppTsConfigJson,
getAngularAppTsConfigPath,
Expand All @@ -28,11 +27,6 @@ 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.'
);
}
const angularVersion = semver.coerce(
packageManager.retrievePackageJson().dependencies['@angular/core']
)?.version;
Expand Down

0 comments on commit 8601ed1

Please sign in to comment.