From dcb839c49d102f5d50b5d54875750120c2090faf Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Mon, 17 Jan 2022 17:46:24 +0200 Subject: [PATCH] fix(storybook): handle defaultProject issues with projectBuildConfig flag (#8494) * fix(storybook): better error logging for missing projectBuildConfig * feat(storybook): migrator to add projectBuildConfig * fix(storybook): set projectBuildConfig in storybook configuration generator * fix(storybook): find the correct targets for build and storybook --- packages/storybook/migrations.json | 6 + .../build-storybook.impl.spec.ts | 1 + .../storybook/storybook.impl.spec.ts | 1 + packages/storybook/src/executors/utils.ts | 85 ++-- .../configuration/configuration.spec.ts | 41 +- .../generators/configuration/configuration.ts | 23 +- .../set-project-build-config.spec.ts.snap | 403 ++++++++++++++++++ .../set-project-build-config.spec.ts | 41 ++ .../update-13-4-6/set-project-build-config.ts | 76 ++++ .../test-configs/custom-names-config.json | 146 +++++++ .../test-configs/default-config.json | 146 +++++++ .../test-configs/non-angular.json | 60 +++ 12 files changed, 1000 insertions(+), 29 deletions(-) create mode 100644 packages/storybook/src/migrations/update-13-4-6/__snapshots__/set-project-build-config.spec.ts.snap create mode 100644 packages/storybook/src/migrations/update-13-4-6/set-project-build-config.spec.ts create mode 100644 packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts create mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json create mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json create mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json diff --git a/packages/storybook/migrations.json b/packages/storybook/migrations.json index f92ac756f26c9..6fd6dd78b9b17 100644 --- a/packages/storybook/migrations.json +++ b/packages/storybook/migrations.json @@ -72,6 +72,12 @@ "cli": "nx", "description": "Adjust Storybook tsconfig to add styled-jsx typings", "factory": "./src/migrations/update-12-8-0/update-storybook-styled-jsx-typings" + }, + "update-13.4.6": { + "version": "13.4.6-beta.1", + "cli": "nx", + "description": "Add projectBuildConfig option to project's Storybook config.", + "factory": "./src/migrations/update-13-4-6/set-project-build-config" } }, "packageJsonUpdates": { diff --git a/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts b/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts index c6365cc2e7bd7..471f800bf9bf8 100644 --- a/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts +++ b/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts @@ -43,6 +43,7 @@ describe('Build storybook', () => { options = { uiFramework, outputPath, + projectBuildConfig: 'proj', config, }; diff --git a/packages/storybook/src/executors/storybook/storybook.impl.spec.ts b/packages/storybook/src/executors/storybook/storybook.impl.spec.ts index 5b722a87c61df..eb8662799c563 100644 --- a/packages/storybook/src/executors/storybook/storybook.impl.spec.ts +++ b/packages/storybook/src/executors/storybook/storybook.impl.spec.ts @@ -35,6 +35,7 @@ describe('@nrwl/storybook:storybook', () => { options = { uiFramework: '@storybook/angular', port: 4400, + projectBuildConfig: 'proj', config: { configFolder: storybookPath, }, diff --git a/packages/storybook/src/executors/utils.ts b/packages/storybook/src/executors/utils.ts index 1d10790b166d2..71ebc28939676 100644 --- a/packages/storybook/src/executors/utils.ts +++ b/packages/storybook/src/executors/utils.ts @@ -5,7 +5,10 @@ import { parseTargetString, readTargetOptions, } from '@nrwl/devkit'; -import { Workspaces } from '@nrwl/tao/src/shared/workspace'; +import { + TargetConfiguration, + Workspaces, +} from '@nrwl/tao/src/shared/workspace'; import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils'; import 'dotenv/config'; import { existsSync, readFileSync } from 'fs'; @@ -205,31 +208,36 @@ export function resolveCommonStorybookOptionMapper( storybookOptions.angularBrowserTarget = targetString; } else { - // to preserve the backwards compatibility for our users Nx resolves the - // default project just as Storybook used to before - - const ws = new Workspaces(context.root); - const defaultProjectName = ws.calculateDefaultProjectName( - context.cwd, - context.workspace - ); - - buildProjectName = defaultProjectName; - - targetOptions = readTargetOptions( - { - project: defaultProjectName, - target: targetName, - configuration: '', - }, - context - ); - - storybookOptions.angularBrowserTarget = normalizeTargetString( - defaultProjectName, - targetName + const { storybookBuildTarget, storybookTarget, buildTarget } = + findStorybookAndBuildTargets( + context?.workspace?.projects?.[context.projectName]?.targets + ); + + throw new Error( + ` + No projectBuildConfig was provided. + + To fix this, you can try one of the following options: + + 1. You can run the ${ + context.targetName ? context.targetName : storybookTarget + } executor by providing the projectBuildConfig flag as follows: + + nx ${context.targetName ? context.targetName : storybookTarget} ${ + context.projectName + } --projectBuildConfig=${context.projectName}${ + !buildTarget && storybookBuildTarget ? `:${storybookBuildTarget}` : '' + } + + 2. In your project configuration, under the "${ + context.targetName ? context.targetName : storybookTarget + }" target options, you can + set the "projectBuildConfig" property to the name of the project of which you want to use + the build configuration for Storybook. + ` ); } + const project = context.workspace.projects[buildProjectName]; const angularDevkitCompatibleLogger = { @@ -280,3 +288,32 @@ function isStorybookGTE6_4() { '6.4.0-rc.1' ); } + +export function findStorybookAndBuildTargets(targets: { + [targetName: string]: TargetConfiguration; +}): { + storybookBuildTarget?: string; + storybookTarget?: string; + buildTarget?: string; +} { + const returnObject: { + storybookBuildTarget?: string; + storybookTarget?: string; + buildTarget?: string; + } = {}; + Object.entries(targets).forEach(([target, targetConfig]) => { + if (targetConfig.executor === '@nrwl/storybook:storybook') { + returnObject.storybookTarget = target; + } + if (targetConfig.executor === '@nrwl/storybook:build') { + returnObject.storybookBuildTarget = target; + } + if ( + targetConfig.executor === '@angular-devkit/build-angular:browser' || + targetConfig.executor === '@nrwl/angular:ng-packagr-lite' + ) { + returnObject.buildTarget = target; + } + }); + return returnObject; +} diff --git a/packages/storybook/src/generators/configuration/configuration.spec.ts b/packages/storybook/src/generators/configuration/configuration.spec.ts index 385f0fa66cfc7..822223df4a5a9 100644 --- a/packages/storybook/src/generators/configuration/configuration.spec.ts +++ b/packages/storybook/src/generators/configuration/configuration.spec.ts @@ -136,7 +136,7 @@ describe('@nrwl/storybook:configuration', () => { expect(tree.read('.storybook/main.js', 'utf-8')).toEqual(newContents); }); - it('should update workspace file', async () => { + it('should update workspace file for react libs', async () => { await configurationGenerator(tree, { name: 'test-ui-lib', uiFramework: '@storybook/react', @@ -169,6 +169,45 @@ describe('@nrwl/storybook:configuration', () => { }); }); + it('should update workspace file for angular libs', async () => { + // Setup a new lib + await libraryGenerator(tree, { + name: 'test-ui-lib-2', + standaloneConfig: false, + }); + await configurationGenerator(tree, { + name: 'test-ui-lib-2', + uiFramework: '@storybook/angular', + standaloneConfig: false, + }); + const project = readProjectConfiguration(tree, 'test-ui-lib-2'); + + expect(project.targets.storybook).toEqual({ + executor: '@nrwl/storybook:storybook', + configurations: { + ci: { + quiet: true, + }, + }, + options: { + port: 4400, + projectBuildConfig: 'test-ui-lib-2:build-storybook', + uiFramework: '@storybook/angular', + config: { + configFolder: 'libs/test-ui-lib-2/.storybook', + }, + }, + }); + + expect(project.targets.lint).toEqual({ + executor: '@nrwl/linter:eslint', + outputs: ['{options.outputFile}'], + options: { + lintFilePatterns: ['libs/test-ui-lib-2/**/*.ts'], + }, + }); + }); + it('should update `tsconfig.lib.json` file', async () => { await configurationGenerator(tree, { name: 'test-ui-lib', diff --git a/packages/storybook/src/generators/configuration/configuration.ts b/packages/storybook/src/generators/configuration/configuration.ts index 9d40399207ed4..a9370e36bdba3 100644 --- a/packages/storybook/src/generators/configuration/configuration.ts +++ b/packages/storybook/src/generators/configuration/configuration.ts @@ -26,10 +26,10 @@ import { } from '../../utils/utilities'; import { cypressProjectGenerator } from '../cypress-project/cypress-project'; import { StorybookConfigureSchema } from './schema'; -import { storybookVersion } from '../../utils/versions'; import { initGenerator } from '../init/init'; import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils'; import { gte } from 'semver'; +import { findStorybookAndBuildTargets } from '../../executors/utils'; export async function configurationGenerator( tree: Tree, @@ -41,7 +41,9 @@ export async function configurationGenerator( const workspaceStorybookVersion = getCurrentWorkspaceStorybookVersion(tree); - const { projectType } = readProjectConfiguration(tree, schema.name); + const { projectType, targets } = readProjectConfiguration(tree, schema.name); + + const { buildTarget } = findStorybookAndBuildTargets(targets); const initTask = await initGenerator(tree, { uiFramework: schema.uiFramework, @@ -59,7 +61,7 @@ export async function configurationGenerator( configureTsProjectConfig(tree, schema); configureTsSolutionConfig(tree, schema); updateLintConfig(tree, schema); - addStorybookTask(tree, schema.name, schema.uiFramework); + addStorybookTask(tree, schema.name, schema.uiFramework, buildTarget); if (schema.configureCypress) { if (projectType !== 'application') { const cypressTask = await cypressProjectGenerator(tree, { @@ -300,7 +302,8 @@ function dedupe(arr: string[]) { function addStorybookTask( tree: Tree, projectName: string, - uiFramework: string + uiFramework: string, + buildTargetForAngularProjects: string ) { const projectConfig = readProjectConfiguration(tree, projectName); projectConfig.targets['storybook'] = { @@ -311,6 +314,12 @@ function addStorybookTask( config: { configFolder: `${projectConfig.root}/.storybook`, }, + projectBuildConfig: + uiFramework === '@storybook/angular' + ? buildTargetForAngularProjects + ? projectName + : `${projectName}:build-storybook` + : undefined, }, configurations: { ci: { @@ -327,6 +336,12 @@ function addStorybookTask( config: { configFolder: `${projectConfig.root}/.storybook`, }, + projectBuildConfig: + uiFramework === '@storybook/angular' + ? buildTargetForAngularProjects + ? projectName + : `${projectName}:build-storybook` + : undefined, }, configurations: { ci: { diff --git a/packages/storybook/src/migrations/update-13-4-6/__snapshots__/set-project-build-config.spec.ts.snap b/packages/storybook/src/migrations/update-13-4-6/__snapshots__/set-project-build-config.spec.ts.snap new file mode 100644 index 0000000000000..e25d901fa41dd --- /dev/null +++ b/packages/storybook/src/migrations/update-13-4-6/__snapshots__/set-project-build-config.spec.ts.snap @@ -0,0 +1,403 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Set the projectBuildConfig option in the Storybook configuration for Angular projects for all types of angular projects - non-buildable and buildable libs/apps should set the projectBuildConfig in the Storybook config according to the type of project 1`] = ` +Object { + "projects": Object { + "main-app": Object { + "prefix": "katst", + "projectType": "application", + "root": "apps/main-app", + "sourceRoot": "apps/main-app/src", + "targets": Object { + "build": Object { + "executor": "@angular-devkit/build-angular:browser", + "outputs": Array [ + "{options.outputPath}", + ], + }, + "build-storybook": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "apps/main-app/.storybook", + }, + "outputPath": "dist/storybook/main-app", + "projectBuildConfig": "main-app", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + "storybook": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "apps/main-app/.storybook", + }, + "port": 4400, + "projectBuildConfig": "main-app", + "uiFramework": "@storybook/angular", + }, + }, + }, + }, + "ui-one": Object { + "projectType": "library", + "root": "libs/ui/one", + "sourceRoot": "libs/ui/one/src", + "targets": Object { + "build-storybook": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "libs/ui/one/.storybook", + }, + "outputPath": "dist/storybook/ui/one", + "projectBuildConfig": "ui-one:build-storybook", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + "storybook": Object { + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "libs/ui/one/.storybook", + }, + "port": 4400, + "projectBuildConfig": "ui-one:build-storybook", + "uiFramework": "@storybook/angular", + }, + }, + }, + }, + "ui-three": Object { + "projectType": "library", + "root": "libs/ui/three", + "sourceRoot": "libs/ui/three/src", + "targets": Object { + "build-storybook": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "libs/ui/three/.storybook", + }, + "outputPath": "dist/storybook/ui/three", + "projectBuildConfig": "ui-three:build-storybook", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + "storybook": Object { + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "libs/ui/three/.storybook", + }, + "port": 4400, + "projectBuildConfig": "ui-three:build-storybook", + "uiFramework": "@storybook/angular", + }, + }, + }, + }, + "ui-two": Object { + "projectType": "library", + "root": "libs/ui/two", + "sourceRoot": "libs/ui/two/src", + "targets": Object { + "build-storybook": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "libs/ui/two/.storybook", + }, + "outputPath": "dist/storybook/ui/two", + "projectBuildConfig": "ui-two:build-storybook", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + "storybook": Object { + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "libs/ui/two/.storybook", + }, + "port": 4400, + "projectBuildConfig": "ui-two:build-storybook", + "uiFramework": "@storybook/angular", + }, + }, + }, + }, + }, + "version": 1, +} +`; + +exports[`Set the projectBuildConfig option in the Storybook configuration for Angular projects for all types of angular projects - non-buildable and buildable libs/apps should still set the projectBuildConfig even if target names are not the default 1`] = ` +Object { + "projects": Object { + "main-app": Object { + "prefix": "katst", + "projectType": "application", + "root": "apps/main-app", + "sourceRoot": "apps/main-app/src", + "targets": Object { + "lmfkcn": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "apps/main-app/.storybook", + }, + "port": 4400, + "projectBuildConfig": "main-app", + "uiFramework": "@storybook/angular", + }, + }, + "njdfvndfjnv": Object { + "executor": "@angular-devkit/build-angular:browser", + "outputs": Array [ + "{options.outputPath}", + ], + }, + "odmwjbc": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "apps/main-app/.storybook", + }, + "outputPath": "dist/storybook/main-app", + "projectBuildConfig": "main-app", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + }, + }, + "ui-one": Object { + "projectType": "library", + "root": "libs/ui/one", + "sourceRoot": "libs/ui/one/src", + "targets": Object { + "asdgsdfg": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "libs/ui/one/.storybook", + }, + "outputPath": "dist/storybook/ui/one", + "projectBuildConfig": "ui-one:asdgsdfg", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + "trthrngb": Object { + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "libs/ui/one/.storybook", + }, + "port": 4400, + "projectBuildConfig": "ui-one:asdgsdfg", + "uiFramework": "@storybook/angular", + }, + }, + }, + }, + "ui-three": Object { + "projectType": "library", + "root": "libs/ui/three", + "sourceRoot": "libs/ui/three/src", + "targets": Object { + "aaaa": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "libs/ui/three/.storybook", + }, + "outputPath": "dist/storybook/ui/three", + "projectBuildConfig": "ui-three:aaaa", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + "nmkgd": Object { + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "libs/ui/three/.storybook", + }, + "port": 4400, + "projectBuildConfig": "ui-three:aaaa", + "uiFramework": "@storybook/angular", + }, + }, + }, + }, + "ui-two": Object { + "projectType": "library", + "root": "libs/ui/two", + "sourceRoot": "libs/ui/two/src", + "targets": Object { + "sdft": Object { + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "libs/ui/two/.storybook", + }, + "port": 4400, + "projectBuildConfig": "ui-two:thjkkb", + "uiFramework": "@storybook/angular", + }, + }, + "thjkkb": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "libs/ui/two/.storybook", + }, + "outputPath": "dist/storybook/ui/two", + "projectBuildConfig": "ui-two:thjkkb", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + }, + }, + }, + "version": 1, +} +`; + +exports[`Set the projectBuildConfig option in the Storybook configuration for Angular projects for non-angular projects should not change their Storybook configuration 1`] = ` +Object { + "projects": Object { + "main-app": Object { + "prefix": "katst", + "projectType": "application", + "root": "apps/main-app", + "sourceRoot": "apps/main-app/src", + "targets": Object { + "storybook": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "apps/main-app/.storybook", + }, + "port": 4400, + "uiFramework": "@storybook/react", + }, + }, + }, + }, + "ui-one": Object { + "projectType": "library", + "root": "libs/ui/one", + "sourceRoot": "libs/ui/one/src", + "targets": Object { + "build-storybook": Object { + "configurations": Object { + "ci": Object { + "quiet": true, + }, + }, + "executor": "@nrwl/storybook:build", + "options": Object { + "config": Object { + "configFolder": "libs/ui/one/.storybook", + }, + "outputPath": "dist/storybook/ui/one", + "uiFramework": "@storybook/angular", + }, + "outputs": Array [ + "{options.outputPath}", + ], + }, + "storybook": Object { + "executor": "@nrwl/storybook:storybook", + "options": Object { + "config": Object { + "configFolder": "libs/ui/one/.storybook", + }, + "port": 4400, + "uiFramework": "@storybook/react", + }, + }, + }, + }, + }, + "version": undefined, +} +`; diff --git a/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.spec.ts b/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.spec.ts new file mode 100644 index 0000000000000..35aeeaeed1518 --- /dev/null +++ b/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.spec.ts @@ -0,0 +1,41 @@ +import { Tree, writeJson } from '@nrwl/devkit'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import { readWorkspace } from 'packages/devkit/src/generators/project-configuration'; +import setProjectBuildConfig from './set-project-build-config'; +import * as defaultConfig from './test-configs/default-config.json'; +import * as customNames from './test-configs/custom-names-config.json'; +import * as nonAngular from './test-configs/non-angular.json'; + +describe('Set the projectBuildConfig option in the Storybook configuration for Angular projects', () => { + let tree: Tree; + + describe('for all types of angular projects - non-buildable and buildable libs/apps', () => { + beforeEach(async () => { + tree = createTreeWithEmptyWorkspace(); + }); + + it(`should set the projectBuildConfig in the Storybook config according to the type of project`, async () => { + writeJson(tree, 'workspace.json', defaultConfig); + await setProjectBuildConfig(tree); + expect(readWorkspace(tree)).toMatchSnapshot(); + }); + + it(`should still set the projectBuildConfig even if target names are not the default`, async () => { + writeJson(tree, 'workspace.json', customNames); + await setProjectBuildConfig(tree); + expect(readWorkspace(tree)).toMatchSnapshot(); + }); + }); + + describe('for non-angular projects', () => { + beforeEach(async () => { + tree = createTreeWithEmptyWorkspace(); + writeJson(tree, 'workspace.json', nonAngular); + }); + + it(`should not change their Storybook configuration`, async () => { + await setProjectBuildConfig(tree); + expect(readWorkspace(tree)).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts b/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts new file mode 100644 index 0000000000000..eb437792be0f1 --- /dev/null +++ b/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts @@ -0,0 +1,76 @@ +import { + logger, + Tree, + formatFiles, + updateProjectConfiguration, + getProjects, +} from '@nrwl/devkit'; +import { findStorybookAndBuildTargets } from '../../executors/utils'; + +export default async function setProjectBuildConfig(tree: Tree) { + let changesMade = false; + const projects = getProjects(tree); + [...projects.entries()].forEach(([projectName, projectConfiguration]) => { + const { storybookBuildTarget, storybookTarget, buildTarget } = + findStorybookAndBuildTargets(projectConfiguration.targets); + if ( + projectName && + storybookTarget && + projectConfiguration?.targets?.[storybookTarget]?.options?.uiFramework === + '@storybook/angular' + ) { + if (buildTarget) { + if ( + !projectConfiguration.targets[storybookTarget].options + .projectBuildConfig + ) { + projectConfiguration.targets[ + storybookTarget + ].options.projectBuildConfig = projectName; + changesMade = true; + } + if ( + storybookBuildTarget && + !projectConfiguration.targets[storybookBuildTarget].options + .projectBuildConfig + ) { + projectConfiguration.targets[ + storybookBuildTarget + ].options.projectBuildConfig = projectName; + changesMade = true; + } + } else { + if (storybookBuildTarget) { + if ( + !projectConfiguration.targets[storybookTarget].options + .projectBuildConfig + ) { + projectConfiguration.targets[ + storybookTarget + ].options.projectBuildConfig = `${projectName}:${storybookBuildTarget}`; + changesMade = true; + } + if ( + !projectConfiguration.targets[storybookBuildTarget].options + .projectBuildConfig + ) { + projectConfiguration.targets[ + storybookBuildTarget + ].options.projectBuildConfig = `${projectName}:${storybookBuildTarget}`; + changesMade = true; + } + } else { + logger.warn(`Could not find a build target for ${projectName}.`); + } + } + + if (changesMade) { + updateProjectConfiguration(tree, projectName, projectConfiguration); + } + } + }); + + if (changesMade) { + await formatFiles(tree); + } +} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json new file mode 100644 index 0000000000000..492fb8d1cd54f --- /dev/null +++ b/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json @@ -0,0 +1,146 @@ +{ + "projects": { + "ui-one": { + "projectType": "library", + "root": "libs/ui/one", + "sourceRoot": "libs/ui/one/src", + "targets": { + "trthrngb": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "libs/ui/one/.storybook" + } + } + }, + "asdgsdfg": { + "executor": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/ui/one", + "config": { + "configFolder": "libs/ui/one/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + }, + "ui-two": { + "projectType": "library", + "root": "libs/ui/two", + "sourceRoot": "libs/ui/two/src", + "targets": { + "sdft": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "libs/ui/two/.storybook" + } + } + }, + "thjkkb": { + "executor": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/ui/two", + "config": { + "configFolder": "libs/ui/two/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + }, + "ui-three": { + "projectType": "library", + "root": "libs/ui/three", + "sourceRoot": "libs/ui/three/src", + "targets": { + "nmkgd": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "libs/ui/three/.storybook" + } + } + }, + "aaaa": { + "executor": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/ui/three", + "config": { + "configFolder": "libs/ui/three/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + }, + "main-app": { + "projectType": "application", + "root": "apps/main-app", + "sourceRoot": "apps/main-app/src", + "prefix": "katst", + "architect": { + "njdfvndfjnv": { + "builder": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"] + }, + "lmfkcn": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "apps/main-app/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + }, + "odmwjbc": { + "builder": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/main-app", + "config": { + "configFolder": "apps/main-app/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + } + } +} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json new file mode 100644 index 0000000000000..439d649ab4604 --- /dev/null +++ b/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json @@ -0,0 +1,146 @@ +{ + "projects": { + "ui-one": { + "projectType": "library", + "root": "libs/ui/one", + "sourceRoot": "libs/ui/one/src", + "targets": { + "storybook": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "libs/ui/one/.storybook" + } + } + }, + "build-storybook": { + "executor": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/ui/one", + "config": { + "configFolder": "libs/ui/one/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + }, + "ui-two": { + "projectType": "library", + "root": "libs/ui/two", + "sourceRoot": "libs/ui/two/src", + "targets": { + "storybook": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "libs/ui/two/.storybook" + } + } + }, + "build-storybook": { + "executor": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/ui/two", + "config": { + "configFolder": "libs/ui/two/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + }, + "ui-three": { + "projectType": "library", + "root": "libs/ui/three", + "sourceRoot": "libs/ui/three/src", + "targets": { + "storybook": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "libs/ui/three/.storybook" + } + } + }, + "build-storybook": { + "executor": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/ui/three", + "config": { + "configFolder": "libs/ui/three/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + }, + "main-app": { + "projectType": "application", + "root": "apps/main-app", + "sourceRoot": "apps/main-app/src", + "prefix": "katst", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"] + }, + "storybook": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/angular", + "port": 4400, + "config": { + "configFolder": "apps/main-app/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + }, + "build-storybook": { + "builder": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/main-app", + "config": { + "configFolder": "apps/main-app/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + } + } +} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json new file mode 100644 index 0000000000000..db81e6f301526 --- /dev/null +++ b/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json @@ -0,0 +1,60 @@ +{ + "projects": { + "ui-one": { + "projectType": "library", + "root": "libs/ui/one", + "sourceRoot": "libs/ui/one/src", + "targets": { + "storybook": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/react", + "port": 4400, + "config": { + "configFolder": "libs/ui/one/.storybook" + } + } + }, + "build-storybook": { + "executor": "@nrwl/storybook:build", + "outputs": ["{options.outputPath}"], + "options": { + "uiFramework": "@storybook/angular", + "outputPath": "dist/storybook/ui/one", + "config": { + "configFolder": "libs/ui/one/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + }, + "main-app": { + "projectType": "application", + "root": "apps/main-app", + "sourceRoot": "apps/main-app/src", + "prefix": "katst", + "architect": { + "storybook": { + "builder": "@nrwl/storybook:storybook", + "options": { + "uiFramework": "@storybook/react", + "port": 4400, + "config": { + "configFolder": "apps/main-app/.storybook" + } + }, + "configurations": { + "ci": { + "quiet": true + } + } + } + } + } + } +}