diff --git a/docs/generated/packages/angular.json b/docs/generated/packages/angular.json index 53066b39b158ca..be06c666705f7e 100644 --- a/docs/generated/packages/angular.json +++ b/docs/generated/packages/angular.json @@ -1654,64 +1654,6 @@ "hidden": false, "path": "/packages/angular/src/generators/storybook-configuration/schema.json" }, - { - "name": "storybook-migrate-defaults-5-to-6", - "factory": "./src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6", - "schema": { - "$schema": "http://json-schema.org/schema", - "$id": "NxStorybookMigrateDefaults5To6Generator", - "title": "Storybook migrate default 5 to 6", - "description": "Generates default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x.`", - "cli": "nx", - "type": "object", - "properties": { - "all": { - "type": "boolean", - "description": "Generate new Storybook configurations for all Storybook instances across all applications and libraries.", - "default": true - }, - "keepOld": { - "type": "boolean", - "description": "Keep the old configuration files by placing them in a folder called `.old_storybook`.", - "default": true - }, - "name": { - "type": "string", - "description": "Library or application name for which you want to generate the new Storybook configuration. Leave empty to upgrade all Storybook instances. Only use this if you want to do a gradual migration.", - "$default": { "$source": "argv", "index": 0 } - } - }, - "additionalProperties": false, - "required": [], - "presets": [] - }, - "description": "Generates default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "implementation": "/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.ts", - "aliases": [], - "hidden": false, - "path": "/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.json" - }, - { - "name": "storybook-migrate-stories-to-6-2", - "factory": "./src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2", - "schema": { - "$schema": "http://json-schema.org/schema", - "$id": "NxAngularStorybookMigrateStoriesTo62Generator", - "title": "Storybook migrate stories to 6.2", - "description": "Migrates stories to match the new syntax in `v6.2` where the component declaration should be in the default export.", - "type": "object", - "cli": "nx", - "properties": {}, - "additionalProperties": false, - "required": [], - "presets": [] - }, - "description": "Migrates stories to match the new syntax in `v6.2` where the component declaration should be in the default export.", - "implementation": "/packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.ts", - "aliases": [], - "hidden": false, - "path": "/packages/angular/src/generators/storybook-migrate-stories-to-6-2/schema.json" - }, { "name": "upgrade-module", "factory": "./src/generators/upgrade-module/upgrade-module", diff --git a/docs/generated/packages/react.json b/docs/generated/packages/react.json index 8ef0eef2c42695..8041801934619f 100644 --- a/docs/generated/packages/react.json +++ b/docs/generated/packages/react.json @@ -638,42 +638,6 @@ "aliases": [], "path": "/packages/react/src/generators/storybook-configuration/schema.json" }, - { - "name": "storybook-migrate-defaults-5-to-6", - "factory": "./src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6#storybookMigration5to6Generator", - "schema": { - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "$id": "storybook-migrate-defaults-5-to-6", - "title": "Storybook migrate defaults 5 to 6", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "type": "object", - "properties": { - "all": { - "type": "boolean", - "description": "Generate new Storybook configurations for all Storybook instances across all apps and libs.", - "default": true - }, - "keepOld": { - "type": "boolean", - "description": "Keep the old configuration files - put them in a folder called `.old_storybook`.", - "default": true - }, - "name": { - "type": "string", - "description": "Leave empty to upgrade all Storybook instances. Only use this if you want to do a gradual migration. Library or application name for which you want to generate the new Storybook configuration.", - "$default": { "$source": "argv", "index": 0 } - } - }, - "required": [], - "presets": [] - }, - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "hidden": false, - "implementation": "/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6#storybookMigration5to6Generator.ts", - "aliases": [], - "path": "/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.json" - }, { "name": "component-story", "factory": "./src/generators/component-story/component-story#componentStoryGenerator", diff --git a/docs/generated/packages/storybook.json b/docs/generated/packages/storybook.json index 65b4b2bf23920c..6fdcd1b8e804ab 100644 --- a/docs/generated/packages/storybook.json +++ b/docs/generated/packages/storybook.json @@ -143,62 +143,6 @@ "implementation": "/packages/storybook/src/generators/cypress-project/cypress-project.ts", "aliases": [], "path": "/packages/storybook/src/generators/cypress-project/schema.json" - }, - { - "name": "migrate-defaults-5-to-6", - "factory": "./src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6", - "schema": { - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "$id": "migrate-defaults-5-to-6", - "title": "Migrate defaults 5 to 6", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "type": "object", - "properties": { - "all": { - "type": "boolean", - "description": "Generate new Storybook configurations for all Storybook instances across all apps and libs.", - "default": true - }, - "keepOld": { - "type": "boolean", - "description": "Keep the old configuration files - put them in a folder called `.old_storybook`.", - "default": true - }, - "name": { - "type": "string", - "description": "Leave empty to upgrade all Storybook instances. Only use this if you want to do a gradual migration. Library or application name for which you want to generate the new Storybook configuration.", - "$default": { "$source": "argv", "index": 0 } - } - }, - "required": [], - "presets": [] - }, - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "hidden": false, - "implementation": "/packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts", - "aliases": [], - "path": "/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.json" - }, - { - "name": "migrate-stories-to-6-2", - "factory": "./src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2", - "schema": { - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "$id": "migrate-stories-to-6-2", - "title": "Migrate stories to 6.2", - "description": "Migrate stories syntax to `6.2`.", - "type": "object", - "properties": {}, - "required": [], - "presets": [] - }, - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "hidden": false, - "implementation": "/packages/storybook/src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2.ts", - "aliases": [], - "path": "/packages/storybook/src/generators/migrate-stories-to-6-2/schema.json" } ], "executors": [ diff --git a/docs/map.json b/docs/map.json index f3e00853f3696c..f90feb54181eed 100644 --- a/docs/map.json +++ b/docs/map.json @@ -675,16 +675,6 @@ "id": "storybook-configuration", "path": "/packages/angular/generators/storybook-configuration" }, - { - "name": "storybook-migrate-defaults-5-to-6 generator", - "id": "storybook-migrate-defaults-5-to-6", - "path": "/packages/angular/generators/storybook-migrate-defaults-5-to-6" - }, - { - "name": "storybook-migrate-stories-to-6-2 generator", - "id": "storybook-migrate-stories-to-6-2", - "path": "/packages/angular/generators/storybook-migrate-stories-to-6-2" - }, { "name": "upgrade-module generator", "id": "upgrade-module", @@ -771,11 +761,6 @@ "id": "storybook-configuration", "path": "/packages/react/generators/storybook-configuration" }, - { - "name": "storybook-migrate-defaults-5-to-6 generator", - "id": "storybook-migrate-defaults-5-to-6", - "path": "/packages/react/generators/storybook-migrate-defaults-5-to-6" - }, { "name": "hook generator", "id": "hook", @@ -869,16 +854,6 @@ "id": "cypress-project", "path": "/packages/storybook/generators/cypress-project" }, - { - "name": "migrate-defaults-5-to-6 generator", - "id": "migrate-defaults-5-to-6", - "path": "/packages/storybook/generators/migrate-defaults-5-to-6" - }, - { - "name": "migrate-stories-to-6-2 generator", - "id": "migrate-stories-to-6-2", - "path": "/packages/storybook/generators/migrate-stories-to-6-2" - }, { "name": "Executors: Build", "id": "executors-build", diff --git a/docs/packages.json b/docs/packages.json index 397039021a807e..6388bec419b49a 100644 --- a/docs/packages.json +++ b/docs/packages.json @@ -41,8 +41,6 @@ "setup-tailwind", "stories", "storybook-configuration", - "storybook-migrate-defaults-5-to-6", - "storybook-migrate-stories-to-6-2", "upgrade-module", "web-worker" ] @@ -200,7 +198,6 @@ "component", "redux", "storybook-configuration", - "storybook-migrate-defaults-5-to-6", "component-story", "stories", "component-cypress-spec", @@ -240,13 +237,7 @@ "path": "generated/packages/storybook.json", "schemas": { "executors": ["storybook", "build"], - "generators": [ - "init", - "configuration", - "cypress-project", - "migrate-defaults-5-to-6", - "migrate-stories-to-6-2" - ] + "generators": ["init", "configuration", "cypress-project"] } }, { diff --git a/docs/shared/guides/storybook/storybook-v6-angular.md b/docs/shared/guides/storybook/storybook-v6-angular.md index f647d364ef153a..c4fcc0f34ddac8 100644 --- a/docs/shared/guides/storybook/storybook-v6-angular.md +++ b/docs/shared/guides/storybook/storybook-v6-angular.md @@ -1,4 +1,6 @@ -# Upgrading to Storybook 6 (and Nx versions >10.1.x) +# Upgrading to Storybook 6 (and Nx versions >10.1.x and <14.0.0) + +_Disclaimer: From Nx 14.0.0 and on, Nx does not support Storybook v.5. If your workspace is on a version of Nx older than Nx 14, then you will be able to use the generators described in this guide. If you're using Nx >14, then you will already have been automatically migrated to Storybook 6._ Nx now comes with [Storybook version 6](https://storybook.js.org/releases/6.0). Chances are, if you used Nx version `10.1.x` or older with Storybook, you are using [Storybook version 5.3](https://storybook.js.org/releases/5.3) with configuration files of [Storybook version 5.2](https://storybook.js.org/releases/5.2). diff --git a/docs/shared/guides/storybook/storybook-v6-react.md b/docs/shared/guides/storybook/storybook-v6-react.md index 461e8a6f2516c9..d5e89e77230260 100644 --- a/docs/shared/guides/storybook/storybook-v6-react.md +++ b/docs/shared/guides/storybook/storybook-v6-react.md @@ -1,4 +1,6 @@ -# Upgrading to Storybook 6 (and Nx versions >10.1.x) +# Upgrading to Storybook 6 (and Nx versions >10.1.x and <14.0.0) + +_Disclaimer: From Nx 14.0.0 and on, Nx does not support Storybook v.5. If your workspace is on a version of Nx older than Nx 14, then you will be able to use the generators described in this guide. If you're using Nx >14, then you will already have been automatically migrated to Storybook 6._ Nx now comes with [Storybook version 6](https://storybook.js.org/releases/6.0). Chances are, if you used Nx version `10.1.x` or older with Storybook, you are using [Storybook version 5.3](https://storybook.js.org/releases/5.3) with configuration files of [Storybook version 5.2](https://storybook.js.org/releases/5.2). diff --git a/nx-dev/nx-dev/redirect-rules.config.js b/nx-dev/nx-dev/redirect-rules.config.js index 9693df74295e8f..06025cbfce4f8b 100644 --- a/nx-dev/nx-dev/redirect-rules.config.js +++ b/nx-dev/nx-dev/redirect-rules.config.js @@ -45,10 +45,6 @@ const schemaUrls = { '/angular/stories': '/packages/angular/generators/stories', '/angular/storybook-configuration': '/packages/angular/generators/storybook-configuration', - '/angular/storybook-migrate-defaults-5-to-6': - '/packages/angular/generators/storybook-migrate-defaults-5-to-6', - '/angular/storybook-migrate-stories-to-6-2': - '/packages/angular/generators/storybook-migrate-stories-to-6-2', '/angular/upgrade-module': '/packages/angular/generators/upgrade-module', '/angular/web-worker': '/packages/angular/generators/web-worker', '/angular/delegate-build': '/packages/angular/executors/delegate-build', @@ -66,8 +62,6 @@ const schemaUrls = { '/react/stories': '/packages/react/generators/stories', '/react/storybook-configuration': '/packages/react/generators/storybook-configuration', - '/react/storybook-migrate-defaults-5-to-6': - '/packages/react/generators/storybook-migrate-defaults-5-to-6', '/react/hook': '/packages/react/generators/hook', '/jest/jest': '/packages/jest/executors/jest', '/cypress/cypress': '/packages/cypress/executors/cypress', diff --git a/packages/angular/generators.json b/packages/angular/generators.json index 90843b8857b566..9efdae5565e8b4 100644 --- a/packages/angular/generators.json +++ b/packages/angular/generators.json @@ -140,16 +140,6 @@ "schema": "./src/generators/storybook-configuration/schema.json", "description": "Adds Storybook configuration to a project." }, - "storybook-migrate-defaults-5-to-6": { - "factory": "./src/generators/storybook-migrate-defaults-5-to-6/compat", - "schema": "./src/generators/storybook-migrate-defaults-5-to-6/schema.json", - "description": "Generates default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`." - }, - "storybook-migrate-stories-to-6-2": { - "factory": "./src/generators/storybook-migrate-stories-to-6-2/compat", - "schema": "./src/generators/storybook-migrate-stories-to-6-2/schema.json", - "description": "Migrates stories to match the new syntax in `v6.2` where the component declaration should be in the default export." - }, "upgrade-module": { "factory": "./src/generators/upgrade-module/compat", "schema": "./src/generators/upgrade-module/schema.json", @@ -299,16 +289,6 @@ "schema": "./src/generators/storybook-configuration/schema.json", "description": "Adds Storybook configuration to a project." }, - "storybook-migrate-defaults-5-to-6": { - "factory": "./src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6", - "schema": "./src/generators/storybook-migrate-defaults-5-to-6/schema.json", - "description": "Generates default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`." - }, - "storybook-migrate-stories-to-6-2": { - "factory": "./src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2", - "schema": "./src/generators/storybook-migrate-stories-to-6-2/schema.json", - "description": "Migrates stories to match the new syntax in `v6.2` where the component declaration should be in the default export." - }, "upgrade-module": { "factory": "./src/generators/upgrade-module/upgrade-module", "schema": "./src/generators/upgrade-module/schema.json", diff --git a/packages/angular/generators.ts b/packages/angular/generators.ts index 4bce969fa262c4..f0a51b657d0f17 100644 --- a/packages/angular/generators.ts +++ b/packages/angular/generators.ts @@ -11,8 +11,6 @@ export * from './src/generators/ngrx/ngrx'; export * from './src/generators/setup-tailwind/setup-tailwind'; export * from './src/generators/stories/stories'; export * from './src/generators/storybook-configuration/storybook-configuration'; -export * from './src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6'; -export * from './src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2'; export * from './src/generators/upgrade-module/upgrade-module'; export * from './src/generators/setup-mfe/setup-mfe'; export * from './src/generators/mfe-host/mfe-host'; diff --git a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/compat.ts b/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/compat.ts deleted file mode 100644 index 92ecb01933bfd5..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/compat.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { convertNxGenerator } from '@nrwl/devkit'; -import { storybookMigrateDefaults5To6Generator } from './storybook-migrate-defaults-5-to-6'; - -export default convertNxGenerator(storybookMigrateDefaults5To6Generator); diff --git a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.d.ts b/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.d.ts deleted file mode 100644 index c2dab2c3c1c3a0..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface StorybookMigrateDefault5to6Schema { - name?: string; - all?: boolean; - keepOld?: boolean; -} diff --git a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.json b/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.json deleted file mode 100644 index 17e9459770ddc9..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "$id": "NxStorybookMigrateDefaults5To6Generator", - "title": "Storybook migrate default 5 to 6", - "description": "Generates default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x.`", - "cli": "nx", - "type": "object", - "properties": { - "all": { - "type": "boolean", - "description": "Generate new Storybook configurations for all Storybook instances across all applications and libraries.", - "default": true - }, - "keepOld": { - "type": "boolean", - "description": "Keep the old configuration files by placing them in a folder called `.old_storybook`.", - "default": true - }, - "name": { - "type": "string", - "description": "Library or application name for which you want to generate the new Storybook configuration. Leave empty to upgrade all Storybook instances. Only use this if you want to do a gradual migration.", - "$default": { - "$source": "argv", - "index": 0 - } - } - }, - "additionalProperties": false, - "required": [] -} diff --git a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.spec.ts b/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.spec.ts deleted file mode 100644 index 1fc95c91862a42..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.spec.ts +++ /dev/null @@ -1,69 +0,0 @@ -import type { Tree } from '@nrwl/devkit'; -import { joinPathFragments, readJson, updateJson } from '@nrwl/devkit'; -import { overrideCollectionResolutionForTesting } from '@nrwl/devkit/ngcli-adapter'; -import { Linter } from '@nrwl/linter'; -import { storybookVersion } from '../../../../storybook/src/utils/versions'; -import storybookConfigurationGenerator from '../storybook-configuration/storybook-configuration'; -import { createStorybookTestWorkspaceForLib } from '../utils/testing'; -import { storybookMigrateDefaults5To6Generator } from './storybook-migrate-defaults-5-to-6'; - -describe('storybookMigrateDefaults5To6 generator', () => { - let tree: Tree; - const libName = 'test-ui-lib'; - - beforeEach(async () => { - overrideCollectionResolutionForTesting({ - '@nrwl/storybook': joinPathFragments( - __dirname, - '../../../../storybook/generators.json' - ), - }); - - tree = await createStorybookTestWorkspaceForLib(libName); - - updateJson(tree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@nrwl/storybook': '10.4.0', - '@nrwl/workspace': '10.4.0', - '@storybook/addon-knobs': '^5.3.8', - '@storybook/angular': '^5.3.8', - }, - }; - }); - - await storybookConfigurationGenerator(tree, { - name: libName, - configureCypress: false, - generateCypressSpecs: false, - generateStories: false, - linter: Linter.EsLint, - }); - }); - - it('should update the correct dependencies', () => { - storybookMigrateDefaults5To6Generator(tree, { all: true }); - - const packageJson = readJson(tree, 'package.json'); - // general deps - expect(packageJson.devDependencies['@storybook/angular']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - storybookVersion - ); - }); - - it('should create the new files', () => { - storybookMigrateDefaults5To6Generator(tree, { all: true }); - - expect(tree.exists('.old_storybook/addons.js')).toBeTruthy(); - expect(tree.exists('.storybook/main.js')).toBeTruthy(); - expect( - tree.exists(`libs/${libName}/.old_storybook/addons.js`) - ).toBeTruthy(); - expect(tree.exists(`libs/${libName}/.storybook/main.js`)).toBeTruthy(); - }); -}); diff --git a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.ts b/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.ts deleted file mode 100644 index 62e3d3da4ca4c7..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { GeneratorCallback, Tree } from '@nrwl/devkit'; -import { migrateDefaultsGenerator } from '@nrwl/storybook'; -import type { StorybookMigrateDefault5to6Schema } from './schema'; - -export function storybookMigrateDefaults5To6Generator( - tree: Tree, - options: StorybookMigrateDefault5to6Schema -): GeneratorCallback { - return migrateDefaultsGenerator(tree, { - name: options.name, - all: options.all, - keepOld: options.keepOld, - }); -} - -export default storybookMigrateDefaults5To6Generator; diff --git a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/compat.ts b/packages/angular/src/generators/storybook-migrate-stories-to-6-2/compat.ts deleted file mode 100644 index e2766bdb3e0ae2..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/compat.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { convertNxGenerator } from '@nrwl/devkit'; -import { angularMigrateStoriesTo62Generator } from './migrate-stories-to-6-2'; - -export default convertNxGenerator(angularMigrateStoriesTo62Generator); diff --git a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.ts b/packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.ts deleted file mode 100644 index 0adcfe8781c449..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { Tree } from '@nrwl/devkit'; -import { migrateStoriesTo62Generator } from '@nrwl/storybook'; - -export async function angularMigrateStoriesTo62Generator(tree: Tree) { - await migrateStoriesTo62Generator(tree); -} - -export default angularMigrateStoriesTo62Generator; diff --git a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/schema.json b/packages/angular/src/generators/storybook-migrate-stories-to-6-2/schema.json deleted file mode 100644 index 4f0559c42c2003..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/schema.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "$id": "NxAngularStorybookMigrateStoriesTo62Generator", - "title": "Storybook migrate stories to 6.2", - "description": "Migrates stories to match the new syntax in `v6.2` where the component declaration should be in the default export.", - "type": "object", - "cli": "nx", - "properties": {}, - "additionalProperties": false, - "required": [] -} diff --git a/packages/react/generators.json b/packages/react/generators.json index c03e879fd618d6..970696b68b4ae0 100644 --- a/packages/react/generators.json +++ b/packages/react/generators.json @@ -48,13 +48,6 @@ "hidden": false }, - "storybook-migrate-defaults-5-to-6": { - "factory": "./src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6#storybookMigration5to6Schematic", - "schema": "./src/generators/storybook-migrate-defaults-5-to-6/schema.json", - "description": "Generate default Storybook configuration files using Storybook version >=6.x specs, for projects that already have Storybook instances and configurations of versions <6.x.", - "hidden": false - }, - "component-story": { "factory": "./src/generators/component-story/component-story#componentStorySchematic", "schema": "./src/generators/component-story/schema.json", @@ -129,13 +122,6 @@ "hidden": false }, - "storybook-migrate-defaults-5-to-6": { - "factory": "./src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6#storybookMigration5to6Generator", - "schema": "./src/generators/storybook-migrate-defaults-5-to-6/schema.json", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "hidden": false - }, - "component-story": { "factory": "./src/generators/component-story/component-story#componentStoryGenerator", "schema": "./src/generators/component-story/schema.json", diff --git a/packages/react/index.ts b/packages/react/index.ts index e9c6a07620353b..a6fc25e0ff40a2 100644 --- a/packages/react/index.ts +++ b/packages/react/index.ts @@ -15,6 +15,5 @@ export { reactInitGenerator } from './src/generators/init/init'; export { reduxGenerator } from './src/generators/redux/redux'; export { storiesGenerator } from './src/generators/stories/stories'; export { storybookConfigurationGenerator } from './src/generators/storybook-configuration/configuration'; -export { storybookMigration5to6Generator } from './src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6'; export { mfeHostGenerator } from './src/generators/mfe-host/mfe-host'; export type { SupportedStyles } from './typings/style'; diff --git a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts b/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts deleted file mode 100644 index 40784369b182c1..00000000000000 --- a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { createTestUILib } from '../stories/stories-lib.spec'; -import { storybookVersion } from '@nrwl/storybook'; -import { logger, readJson, Tree, updateJson } from '@nrwl/devkit'; -import storybookConfigurationGenerator from '../storybook-configuration/configuration'; -import { storybookMigration5to6Generator } from '@nrwl/react'; - -describe('migrate-defaults-5-to-6 schematic', () => { - let appTree: Tree; - - beforeEach(async () => { - appTree = await createTestUILib('test-ui-lib'); - - updateJson(appTree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@nrwl/storybook': '10.4.0', - '@nrwl/workspace': '10.4.0', - '@storybook/addon-knobs': '^5.3.8', - '@storybook/react': '^5.3.8', - }, - }; - }); - - await storybookConfigurationGenerator(appTree, { - name: 'test-ui-lib', - configureCypress: false, - generateCypressSpecs: false, - generateStories: false, - standaloneConfig: false, - }); - - jest.spyOn(logger, 'warn').mockImplementation(() => {}); - jest.spyOn(logger, 'debug').mockImplementation(() => {}); - }); - - afterEach(() => { - jest.restoreAllMocks(); - }); - - it('should update the correct dependencies', async () => { - storybookMigration5to6Generator(appTree, { all: true }); - const packageJson = readJson(appTree, 'package.json'); - // general deps - expect(packageJson.devDependencies['@storybook/react']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - storybookVersion - ); - }); -}); diff --git a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts b/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts deleted file mode 100644 index 405b82144544aa..00000000000000 --- a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { StorybookMigrateDefault5to6Schema } from './schema'; - -import { convertNxGenerator, Tree } from '@nrwl/devkit'; -import { migrateDefaultsGenerator } from '@nrwl/storybook'; - -export function storybookMigration5to6Generator( - host: Tree, - schema: StorybookMigrateDefault5to6Schema -) { - return migrateDefaultsGenerator(host, { - name: schema.name, - all: schema.all, - keepOld: schema.keepOld, - }); -} - -export default storybookMigration5to6Generator; -export const storybookMigration5to6Schematic = convertNxGenerator( - storybookMigration5to6Generator -); diff --git a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.d.ts b/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.d.ts deleted file mode 100644 index c2dab2c3c1c3a0..00000000000000 --- a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface StorybookMigrateDefault5to6Schema { - name?: string; - all?: boolean; - keepOld?: boolean; -} diff --git a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.json b/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.json deleted file mode 100644 index 8e65f9a57ec09b..00000000000000 --- a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "$id": "storybook-migrate-defaults-5-to-6", - "title": "Storybook migrate defaults 5 to 6", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "type": "object", - "properties": { - "all": { - "type": "boolean", - "description": "Generate new Storybook configurations for all Storybook instances across all apps and libs.", - "default": true - }, - "keepOld": { - "type": "boolean", - "description": "Keep the old configuration files - put them in a folder called `.old_storybook`.", - "default": true - }, - "name": { - "type": "string", - "description": "Leave empty to upgrade all Storybook instances. Only use this if you want to do a gradual migration. Library or application name for which you want to generate the new Storybook configuration.", - "$default": { - "$source": "argv", - "index": 0 - } - } - }, - "required": [] -} diff --git a/packages/storybook/.eslintrc.json b/packages/storybook/.eslintrc.json index 4cbaee8bf5e0f3..7ae61b6bd9f653 100644 --- a/packages/storybook/.eslintrc.json +++ b/packages/storybook/.eslintrc.json @@ -8,11 +8,7 @@ }, { "files": ["**/*.ts"], - "excludedFiles": [ - "./src/migrations/**", - "./src/generators/migrate-defaults-5-to-6/*.spec.ts", - "./src/utils/testing.ts" - ], + "excludedFiles": ["./src/migrations/**", "./src/utils/testing.ts"], "rules": { "no-restricted-imports": [ "error", diff --git a/packages/storybook/generators.json b/packages/storybook/generators.json index dac4892e5c02df..bec4d213845934 100644 --- a/packages/storybook/generators.json +++ b/packages/storybook/generators.json @@ -20,18 +20,6 @@ "schema": "./src/generators/cypress-project/schema.json", "description": "Add cypress e2e app to test a UI library that is set up for Storybook.", "hidden": false - }, - "migrate-defaults-5-to-6": { - "factory": "./src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6#migrateDefaultsSchematic", - "schema": "./src/generators/migrate-defaults-5-to-6/schema.json", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "hidden": false - }, - "migrate-stories-to-6-2": { - "factory": "./src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2#migrateStoriesSchematic", - "schema": "./src/generators/migrate-stories-to-6-2/schema.json", - "description": "Migrate stories syntax to `6.2`.", - "hidden": false } }, "generators": { @@ -53,18 +41,6 @@ "schema": "./src/generators/cypress-project/schema.json", "description": "Add cypress e2e app to test a UI library that is set up for Storybook.", "hidden": false - }, - "migrate-defaults-5-to-6": { - "factory": "./src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6", - "schema": "./src/generators/migrate-defaults-5-to-6/schema.json", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "hidden": false - }, - "migrate-stories-to-6-2": { - "factory": "./src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2", - "schema": "./src/generators/migrate-stories-to-6-2/schema.json", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "hidden": false } } } diff --git a/packages/storybook/index.ts b/packages/storybook/index.ts index f4d7843866269e..731af7dde6584c 100644 --- a/packages/storybook/index.ts +++ b/packages/storybook/index.ts @@ -1,5 +1,3 @@ export { configurationGenerator } from './src/generators/configuration/configuration'; export { cypressProjectGenerator } from './src/generators/cypress-project/cypress-project'; -export { migrateDefaultsGenerator } from './src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6'; -export { migrateStoriesTo62Generator } from './src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2'; export { storybookVersion } from './src/utils/versions'; diff --git a/packages/storybook/migrations.json b/packages/storybook/migrations.json index dce1301887f134..d9189472e47903 100644 --- a/packages/storybook/migrations.json +++ b/packages/storybook/migrations.json @@ -78,6 +78,12 @@ "cli": "nx", "description": "Add projectBuildConfig option to project's Storybook config.", "factory": "./src/migrations/update-13-4-6/set-project-build-config" + }, + "update-14.0.0": { + "version": "14.0.0", + "cli": "nx", + "description": "Migrate Storybook to v6", + "factory": "./src/migrations/update-14-0-0/migrate-to-storybook-6" } }, "packageJsonUpdates": { diff --git a/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts b/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts index c882e4b8634e21..75ac0c221bdee5 100644 --- a/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts +++ b/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts @@ -1,11 +1,9 @@ import { ExecutorContext, logger } from '@nrwl/devkit'; import * as build from '@storybook/core/standalone'; import 'dotenv/config'; -import { showStorybookV5Warning } from '../../utils/utilities'; import { CommonNxStorybookConfig } from '../models'; import { getStorybookFrameworkPath, - isStorybookLT6, normalizeAngularBuilderStylesOptions, resolveCommonStorybookOptionMapper, runStorybookSetupCheck, @@ -32,10 +30,6 @@ export default async function buildStorybookExecutor( // print warnings runStorybookSetupCheck(options); - if (isStorybookLT6()) { - showStorybookV5Warning(options.uiFramework); - } - logger.info(`NX Storybook builder starting ...`); await runInstance(option); logger.info(`NX Storybook builder finished ...`); diff --git a/packages/storybook/src/executors/storybook/storybook.impl.ts b/packages/storybook/src/executors/storybook/storybook.impl.ts index 9667c0b25217d8..8dad9c0c3c559b 100644 --- a/packages/storybook/src/executors/storybook/storybook.impl.ts +++ b/packages/storybook/src/executors/storybook/storybook.impl.ts @@ -1,14 +1,12 @@ import { ExecutorContext, logger } from '@nrwl/devkit'; import { buildDevStandalone } from '@storybook/core-server'; import 'dotenv/config'; -import { showStorybookV5Warning } from '../../utils/utilities'; import { CommonNxStorybookConfig } from '../models'; import { getStorybookFrameworkPath, normalizeAngularBuilderStylesOptions, resolveCommonStorybookOptionMapper, runStorybookSetupCheck, - isStorybookLT6, } from '../utils'; export interface StorybookExecutorOptions extends CommonNxStorybookConfig { host?: string; @@ -35,10 +33,6 @@ export default async function* storybookExecutor( // print warnings runStorybookSetupCheck(options); - if (isStorybookLT6()) { - showStorybookV5Warning(options.uiFramework); - } - await runInstance(option); yield { success: true }; diff --git a/packages/storybook/src/executors/utils.ts b/packages/storybook/src/executors/utils.ts index 5e2aa5d067cf7d..b270ceb105f577 100644 --- a/packages/storybook/src/executors/utils.ts +++ b/packages/storybook/src/executors/utils.ts @@ -3,16 +3,14 @@ import { joinPathFragments, logger, parseTargetString, - readProjectConfiguration, readTargetOptions, TargetConfiguration, - Tree, } from '@nrwl/devkit'; import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils'; import 'dotenv/config'; import { existsSync, readFileSync } from 'fs'; import { join } from 'path'; -import { gte, lt } from 'semver'; +import { gte } from 'semver'; import { findOrCreateConfig, readCurrentWorkspaceStorybookVersionFromExecutor, @@ -295,49 +293,6 @@ function isStorybookGTE6_4() { ); } -export function isStorybookLT6() { - const storybookVersion = readCurrentWorkspaceStorybookVersionFromExecutor(); - - return lt( - checkAndCleanWithSemver('@storybook/core', storybookVersion), - '6.0.0' - ); -} - -export function customProjectBuildConfigIsValid( - tree: Tree, - projectBuildConfig: string -): boolean { - if (projectBuildConfig.includes(':')) { - const { project, target } = parseTargetString(projectBuildConfig); - const projectConfig = readProjectConfiguration(tree, project); - if (projectConfig?.targets?.[target]) { - return true; - } else { - logger.warn(` - The projectBuildConfig you provided is not valid. - ${!projectConfig ? 'The project ' + project + ' does not exist.' : ''} - ${ - projectConfig && - !projectConfig.targets?.[target] && - `The project ${project} does not have the target ${target}.` - } - The default projectBuildConfig is going to be used. - `); - } - } else { - try { - return Boolean(readProjectConfiguration(tree, projectBuildConfig)); - } catch (e) { - logger.warn(` - The projectBuildConfig you provided is not valid. - The project ${projectBuildConfig} does not exist. - The default projectBuildConfig is going to be used. - `); - } - } -} - export function findStorybookAndBuildTargets(targets: { [targetName: string]: TargetConfiguration; }): { diff --git a/packages/storybook/src/generators/configuration/configuration.ts b/packages/storybook/src/generators/configuration/configuration.ts index bab9bbef0d387f..4f36a112a6d8bb 100644 --- a/packages/storybook/src/generators/configuration/configuration.ts +++ b/packages/storybook/src/generators/configuration/configuration.ts @@ -22,7 +22,6 @@ import { join } from 'path'; import { isFramework, readCurrentWorkspaceStorybookVersionFromGenerator, - showStorybookV5Warning, TsConfig, } from '../../utils/utilities'; import { cypressProjectGenerator } from '../cypress-project/cypress-project'; @@ -44,8 +43,6 @@ export async function configurationGenerator( const tasks: GeneratorCallback[] = []; - const workspaceStorybookVersion = getCurrentWorkspaceStorybookVersion(tree); - const { projectType, targets } = readProjectConfiguration(tree, schema.name); const { buildTarget } = findStorybookAndBuildTargets(targets); @@ -55,14 +52,8 @@ export async function configurationGenerator( }); tasks.push(initTask); - createRootStorybookDir(tree, schema.js, workspaceStorybookVersion); - createProjectStorybookDir( - tree, - schema.name, - schema.uiFramework, - schema.js, - workspaceStorybookVersion - ); + createRootStorybookDir(tree, schema.js); + createProjectStorybookDir(tree, schema.name, schema.uiFramework, schema.js); configureTsProjectConfig(tree, schema); configureTsSolutionConfig(tree, schema); updateLintConfig(tree, schema); @@ -88,10 +79,6 @@ export async function configurationGenerator( } } - if (workspaceStorybookVersion !== '6') { - showStorybookV5Warning(rawSchema.uiFramework); - } - await formatFiles(tree); return runTasksInSerial(...tasks); @@ -111,26 +98,16 @@ function normalizeSchema( }; } -function createRootStorybookDir( - tree: Tree, - js: boolean, - workspaceStorybookVersion: string -) { +function createRootStorybookDir(tree: Tree, js: boolean) { if (tree.exists('.storybook')) { logger.warn( `.storybook folder already exists at root! Skipping generating files in it.` ); return; } - logger.debug( - `adding .storybook folder to the root directory - - based on the Storybook version installed (v${workspaceStorybookVersion}), we'll bootstrap a scaffold for that particular version.` - ); + logger.debug(`adding .storybook folder to the root directory`); - const templatePath = join( - __dirname, - workspaceStorybookVersion === '6' ? './root-files' : './root-files-5' - ); + const templatePath = join(__dirname, './root-files'); generateFiles(tree, templatePath, '', { rootTsConfigPath: getRootTsConfigPathInTree(tree), }); @@ -144,16 +121,8 @@ function createProjectStorybookDir( tree: Tree, projectName: string, uiFramework: StorybookConfigureSchema['uiFramework'], - js: boolean, - workspaceStorybookVersion: string + js: boolean ) { - /** - * Here, same as above - * Check storybook version - * and use the correct folder - * lib-files-5 or lib-files-6 - */ - const { root, projectType } = readProjectConfiguration(tree, projectName); const projectDirectory = projectType === 'application' ? 'app' : 'lib'; @@ -166,13 +135,8 @@ function createProjectStorybookDir( return; } - logger.debug( - `adding .storybook folder to ${projectDirectory} - using Storybook version ${workspaceStorybookVersion}` - ); - const templatePath = join( - __dirname, - workspaceStorybookVersion === '6' ? './project-files' : './project-files-5' - ); + logger.debug(`adding .storybook folder to ${projectDirectory}`); + const templatePath = join(__dirname, './project-files'); generateFiles(tree, templatePath, root, { tmpl: '', diff --git a/packages/storybook/src/generators/configuration/project-files-5/.storybook/addons.js__tmpl__ b/packages/storybook/src/generators/configuration/project-files-5/.storybook/addons.js__tmpl__ deleted file mode 100644 index 9ba582015be3ae..00000000000000 --- a/packages/storybook/src/generators/configuration/project-files-5/.storybook/addons.js__tmpl__ +++ /dev/null @@ -1 +0,0 @@ -import '<%= offsetFromRoot %>../.storybook/addons'; diff --git a/packages/storybook/src/generators/configuration/project-files-5/.storybook/config.js__tmpl__ b/packages/storybook/src/generators/configuration/project-files-5/.storybook/config.js__tmpl__ deleted file mode 100644 index 3478c695ec78db..00000000000000 --- a/packages/storybook/src/generators/configuration/project-files-5/.storybook/config.js__tmpl__ +++ /dev/null @@ -1,5 +0,0 @@ -import { configure, addDecorator } from '<%= uiFramework %>'; -import { withKnobs } from '@storybook/addon-knobs'; - -addDecorator(withKnobs); -configure(require.context('../src/<%= projectType %>', true, /\.stories\.(j|t)sx?$/), module); \ No newline at end of file diff --git a/packages/storybook/src/generators/configuration/project-files-5/.storybook/tsconfig.json__tmpl__ b/packages/storybook/src/generators/configuration/project-files-5/.storybook/tsconfig.json__tmpl__ deleted file mode 100644 index 034761f7e51086..00000000000000 --- a/packages/storybook/src/generators/configuration/project-files-5/.storybook/tsconfig.json__tmpl__ +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "<%= offsetFromRoot %>../<%= rootTsConfigPath %>", - "compilerOptions": { - "emitDecoratorMetadata": true - }, - "exclude": ["../**/*.spec.ts" <% if(uiFramework === '@storybook/react') { %>, "../**/*.spec.js", "../**/*.spec.tsx", "../**/*.spec.jsx"<% } %>], - "include": ["../src/**/*"] -} diff --git a/packages/storybook/src/generators/configuration/project-files-5/.storybook/webpack.config.js__tmpl__ b/packages/storybook/src/generators/configuration/project-files-5/.storybook/webpack.config.js__tmpl__ deleted file mode 100644 index 01e6265ee9627e..00000000000000 --- a/packages/storybook/src/generators/configuration/project-files-5/.storybook/webpack.config.js__tmpl__ +++ /dev/null @@ -1,99 +0,0 @@ -const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); -const rootWebpackConfig = require('<%= offsetFromRoot %>../.storybook/webpack.config'); -/** - * Export a function. Accept the base config as the only param. - * - * @param {Parameters[0]} options - */ -module.exports = async ({ config, mode }) => { - config = await rootWebpackConfig({ config, mode }); - - const tsPaths = new TsconfigPathsPlugin({ - configFile: './<%= rootTsConfigPath %>', - }); - - config.resolve.plugins - ? config.resolve.plugins.push(tsPaths) - : (config.resolve.plugins = [tsPaths]) - - <% if(uiFramework === '@storybook/react') { %> - config.resolve.extensions.push('.ts', '.tsx'); - - config.module.rules.push({ - test: /\.(ts|tsx)$/, - loader: require.resolve('babel-loader'), - options: { - presets: [ - '@babel/preset-env', - '@babel/preset-react', - '@babel/preset-typescript' - ] - } - }); - - - // Found this here: https://github.com/nrwl/nx/issues/2859 - // And copied the part of the solution that made it work - - const svgRuleIndex = config.module.rules.findIndex(rule => { - const { test } = rule; - - return test.toString().startsWith('/\\.(svg|ico'); - }); - config.module.rules[svgRuleIndex].test = /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/; - - config.module.rules.push( - { - test: /\.(png|jpe?g|gif|webp)$/, - loader: require.resolve('url-loader'), - options: { - limit: 10000, // 10kB - name: '[name].[hash:7].[ext]', - }, - }, - { - test: /\.svg$/, - oneOf: [ - // If coming from JS/TS file, then transform into React component using SVGR. - { - issuer: { - test: /\.[jt]sx?$/, - }, - use: [ - { - loader: require.resolve('@svgr/webpack'), - options: { - svgo: false, - titleProp: true, - ref: true, - }, - }, - { - loader: require.resolve('url-loader'), - options: { - limit: 10000, // 10kB - name: '[name].[hash:7].[ext]', - esModule: false, - }, - }, - ], - }, - // Fallback to plain URL loader. - { - use: [ - { - loader: require.resolve('url-loader'), - options: { - limit: 10000, // 10kB - name: '[name].[hash:7].[ext]', - }, - }, - ], - }, - ], - } - ); - - <% } %> - return config; -}; \ No newline at end of file diff --git a/packages/storybook/src/generators/configuration/root-files-5/.storybook/addons.js b/packages/storybook/src/generators/configuration/root-files-5/.storybook/addons.js deleted file mode 100644 index 6622fe475d5fef..00000000000000 --- a/packages/storybook/src/generators/configuration/root-files-5/.storybook/addons.js +++ /dev/null @@ -1 +0,0 @@ -import '@storybook/addon-knobs/register'; diff --git a/packages/storybook/src/generators/configuration/root-files-5/.storybook/tsconfig.json b/packages/storybook/src/generators/configuration/root-files-5/.storybook/tsconfig.json deleted file mode 100644 index 1e25d668b5a97c..00000000000000 --- a/packages/storybook/src/generators/configuration/root-files-5/.storybook/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "../<%= rootTsConfigPath %>", - "exclude": [ - "../**/*.spec.js", - "../**/*.test.js", - "../**/*.spec.ts", - "../**/*.test.ts", - "../**/*.spec.tsx", - "../**/*.test.tsx", - "../**/*.spec.jsx", - "../**/*.test.jsx" - ], - "include": ["../**/*"] -} diff --git a/packages/storybook/src/generators/configuration/root-files-5/.storybook/webpack.config.js b/packages/storybook/src/generators/configuration/root-files-5/.storybook/webpack.config.js deleted file mode 100644 index 69fcea76977dc0..00000000000000 --- a/packages/storybook/src/generators/configuration/root-files-5/.storybook/webpack.config.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Export a function. Accept the base config as the only param. - * @param {Object} options - * @param {Required} options.config - * @param {'DEVELOPMENT' | 'PRODUCTION'} options.mode - change the build configuration. 'PRODUCTION' is used when building the static version of storybook. - */ -module.exports = async ({ config, mode }) => { - // Make whatever fine-grained changes you need - - // Return the altered config - return config; -}; diff --git a/packages/storybook/src/generators/init/init.ts b/packages/storybook/src/generators/init/init.ts index e777a8ebf45ba0..25557b68af1d5e 100644 --- a/packages/storybook/src/generators/init/init.ts +++ b/packages/storybook/src/generators/init/init.ts @@ -31,48 +31,14 @@ function checkDependenciesInstalled(host: Tree, schema: Schema) { // base deps devDependencies['@nrwl/storybook'] = nxVersion; - - /** - * If Storybook already exists, do NOT update it to the latest version. - * Leave it alone. - */ - - if ( - !packageJson.dependencies['@storybook/core-server'] && - !packageJson.devDependencies['@storybook/core-server'] - ) { - devDependencies['@storybook/core-server'] = storybookVersion; - } - - if ( - !packageJson.dependencies['@storybook/addon-essentials'] && - !packageJson.devDependencies['@storybook/addon-essentials'] - ) { - devDependencies['@storybook/addon-essentials'] = storybookVersion; - } + devDependencies['@storybook/core-server'] = storybookVersion; + devDependencies['@storybook/addon-essentials'] = storybookVersion; if (isFramework('angular', schema)) { - if ( - !packageJson.dependencies['@storybook/angular'] && - !packageJson.devDependencies['@storybook/angular'] - ) { - devDependencies['@storybook/angular'] = storybookVersion; - } - - if ( - !packageJson.dependencies['@storybook/builder-webpack5'] && - !packageJson.devDependencies['@storybook/builder-webpack5'] - ) { - devDependencies['@storybook/builder-webpack5'] = storybookVersion; - } - - if ( - !packageJson.dependencies['@storybook/manager-webpack5'] && - !packageJson.devDependencies['@storybook/manager-webpack5'] - ) { - devDependencies['@storybook/manager-webpack5'] = storybookVersion; - devDependencies['webpack'] = webpack5Version; - } + devDependencies['@storybook/angular'] = storybookVersion; + devDependencies['@storybook/builder-webpack5'] = storybookVersion; + devDependencies['@storybook/manager-webpack5'] = storybookVersion; + devDependencies['webpack'] = webpack5Version; if ( !packageJson.dependencies['@angular/forms'] && @@ -89,27 +55,9 @@ function checkDependenciesInstalled(host: Tree, schema: Schema) { devDependencies['babel-loader'] = babelLoaderVersion; devDependencies['@babel/core'] = babelCoreVersion; devDependencies['@babel/preset-typescript'] = babelPresetTypescriptVersion; - - if ( - !packageJson.dependencies['@storybook/react'] && - !packageJson.devDependencies['@storybook/react'] - ) { - devDependencies['@storybook/react'] = storybookVersion; - } - - if ( - !packageJson.dependencies['@storybook/builder-webpack5'] && - !packageJson.devDependencies['@storybook/builder-webpack5'] - ) { - devDependencies['@storybook/builder-webpack5'] = storybookVersion; - } - - if ( - !packageJson.dependencies['@storybook/manager-webpack5'] && - !packageJson.devDependencies['@storybook/manager-webpack5'] - ) { - devDependencies['@storybook/manager-webpack5'] = storybookVersion; - } + devDependencies['@storybook/react'] = storybookVersion; + devDependencies['@storybook/builder-webpack5'] = storybookVersion; + devDependencies['@storybook/manager-webpack5'] = storybookVersion; } if (isFramework('html', schema)) { @@ -133,52 +81,17 @@ function checkDependenciesInstalled(host: Tree, schema: Schema) { } if (isFramework('react-native', schema)) { - if ( - !packageJson.dependencies['@storybook/react-native'] && - !packageJson.devDependencies['@storybook/react-native'] - ) { - devDependencies['@storybook/react-native'] = storybookReactNativeVersion; - } - - if ( - !packageJson.dependencies['@storybook/addon-ondevice-actions'] && - !packageJson.devDependencies['@storybook/addon-ondevice-actions'] - ) { - devDependencies['@storybook/addon-ondevice-actions'] = - storybookReactNativeVersion; - } - - if ( - !packageJson.dependencies['@storybook/addon-ondevice-backgrounds'] && - !packageJson.devDependencies['@storybook/addon-ondevice-backgrounds'] - ) { - devDependencies['@storybook/addon-ondevice-backgrounds'] = - storybookReactNativeVersion; - } - - if ( - !packageJson.dependencies['@storybook/addon-ondevice-controls'] && - !packageJson.devDependencies['@storybook/addon-ondevice-controls'] - ) { - devDependencies['@storybook/addon-ondevice-controls'] = - storybookReactNativeVersion; - } - - if ( - !packageJson.dependencies['@storybook/addon-ondevice-notes'] && - !packageJson.devDependencies['@storybook/addon-ondevice-notes'] - ) { - devDependencies['@storybook/addon-ondevice-notes'] = - storybookReactNativeVersion; - } - - if ( - !packageJson.dependencies['react-native-storybook-loader'] && - !packageJson.devDependencies['react-native-storybook-loader'] - ) { - devDependencies['react-native-storybook-loader'] = - reactNativeStorybookLoader; - } + devDependencies['@storybook/react-native'] = storybookReactNativeVersion; + devDependencies['@storybook/addon-ondevice-actions'] = + storybookReactNativeVersion; + devDependencies['@storybook/addon-ondevice-backgrounds'] = + storybookReactNativeVersion; + devDependencies['@storybook/addon-ondevice-controls'] = + storybookReactNativeVersion; + devDependencies['@storybook/addon-ondevice-notes'] = + storybookReactNativeVersion; + devDependencies['react-native-storybook-loader'] = + reactNativeStorybookLoader; } return addDependenciesToPackageJson(host, dependencies, devDependencies); diff --git a/packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts b/packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts deleted file mode 100644 index 1de9bf1ef42d6a..00000000000000 --- a/packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts +++ /dev/null @@ -1,293 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree, updateJsonInTree } from '@nrwl/workspace'; -import { - callRule, - createTestUILib, - runSchematic, - runExternalSchematic, -} from '../../utils/testing'; -import { storybookVersion } from '../../utils/versions'; - -// TODO: migrate these tests when schematics are moved over to generators -// These Tests would fail if rewritten with @nrwl/devkit -// Keeping these as is so we can still test teh functionality -describe('migrate-defaults-5-to-6 schematic', () => { - let appTree: Tree; - - describe('angular project', () => { - beforeEach(async () => { - appTree = await createTestUILib('test-ui-lib1', '@nrwl/angular'); - - appTree = await callRule( - updateJsonInTree('package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@nrwl/storybook': '10.4.0', - '@nrwl/workspace': '10.4.0', - '@storybook/addon-knobs': '^5.3.8', - '@storybook/angular': '^5.3.8', - }, - }; - }), - appTree - ); - - appTree = await runExternalSchematic( - '@nrwl/angular', - 'library', - { - name: 'test-ui-lib2', - }, - appTree - ); - - appTree = await runSchematic( - 'configuration', - { - name: 'test-ui-lib1', - }, - appTree - ); - - appTree = await runSchematic( - 'configuration', - { - name: 'test-ui-lib2', - }, - appTree - ); - }); - - describe('a single project run', () => { - it('should not update dependencies when a single project is run', async () => { - appTree = await runSchematic( - 'migrate-defaults-5-to-6', - { - name: 'test-ui-lib1', - }, - appTree - ); - const packageJson = readJsonInTree(appTree, 'package.json'); - // general deps - expect(packageJson.devDependencies['@storybook/angular']).toEqual( - '^5.3.8' - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - '^5.3.8' - ); - }); - - it('should update that project and leave others unchanged', async () => { - appTree = await runSchematic( - 'migrate-defaults-5-to-6', - { - name: 'test-ui-lib1', - }, - appTree - ); - - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') - ).toBeFalsy(); - }); - - it('should not update the root config', async () => { - appTree = await runSchematic( - 'migrate-defaults-5-to-6', - { - name: 'test-ui-lib1', - }, - appTree - ); - - expect(appTree.exists('.storybook/addons.js')).toBeTruthy(); - - expect(appTree.exists('.storybook/main.js')).toBeFalsy(); - }); - }); - - describe('all projects run', () => { - it('should update dependencies', async () => { - appTree = await runSchematic('migrate-defaults-5-to-6', {}, appTree); - const packageJson = readJsonInTree(appTree, 'package.json'); - // general deps - expect(packageJson.devDependencies['@storybook/angular']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - storybookVersion - ); - }); - - it('should update root config', async () => { - appTree = await runSchematic( - 'migrate-defaults-5-to-6', - { - all: true, - }, - appTree - ); - - expect(appTree.exists('.storybook/addons.js')).toBeFalsy(); - - expect(appTree.exists('.storybook/main.js')).toBeTruthy(); - }); - - it('should update all projects', async () => { - appTree = await runSchematic( - 'migrate-defaults-5-to-6', - { - all: true, - }, - appTree - ); - - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') - ).toBeTruthy(); - - expect( - appTree.exists('libs/test-ui-lib1/.storybook/main.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.storybook/main.js') - ).toBeTruthy(); - }); - }); - - describe('--keepOld', () => { - it('should keep old files by default', async () => { - appTree = await runSchematic('migrate-defaults-5-to-6', {}, appTree); - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/config.js') - ).toBeTruthy(); - - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/config.js') - ).toBeTruthy(); - - expect(appTree.exists('.old_storybook/addons.js')).toBeTruthy(); - }); - - it('should delete old files when set to false', async () => { - appTree = await runSchematic( - 'migrate-defaults-5-to-6', - { - keepOld: false, - }, - appTree - ); - expect( - appTree.exists('libs/test-ui-lib1/.storybook/addons.js') - ).toBeFalsy(); - expect( - appTree.exists('libs/test-ui-lib1/.storybook/config.js') - ).toBeFalsy(); - - expect( - appTree.exists('libs/test-ui-lib2/.storybook/addons.js') - ).toBeFalsy(); - expect( - appTree.exists('libs/test-ui-lib2/.storybook/config.js') - ).toBeFalsy(); - - expect(appTree.exists('.storybook/addons.js')).toBeFalsy(); - }); - }); - }); - - describe('react project', () => { - beforeEach(async () => { - appTree = await createTestUILib('test-ui-lib1', '@nrwl/react'); - - appTree = await callRule( - updateJsonInTree('package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@nrwl/storybook': '10.4.0', - '@nrwl/workspace': '10.4.0', - '@storybook/addon-knobs': '^5.3.8', - '@storybook/react': '^5.3.8', - }, - }; - }), - appTree - ); - - appTree = await runExternalSchematic( - '@nrwl/react', - 'library', - { - name: 'test-ui-lib2', - }, - appTree - ); - - appTree = await runSchematic( - 'configuration', - { - name: 'test-ui-lib1', - }, - appTree - ); - - appTree = await runSchematic( - 'configuration', - { - name: 'test-ui-lib2', - }, - appTree - ); - }); - - describe('a single project run', () => { - it('should not update dependencies when a single project is run', async () => { - appTree = await runSchematic( - 'migrate-defaults-5-to-6', - { - name: 'test-ui-lib1', - }, - appTree - ); - const packageJson = readJsonInTree(appTree, 'package.json'); - // general deps - expect(packageJson.devDependencies['@storybook/react']).toEqual( - '^5.3.8' - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - '^5.3.8' - ); - }); - }); - - describe('all projects run', () => { - it('should update dependencies', async () => { - appTree = await runSchematic('migrate-defaults-5-to-6', {}, appTree); - const packageJson = readJsonInTree(appTree, 'package.json'); - // general deps - expect(packageJson.devDependencies['@storybook/react']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - storybookVersion - ); - }); - }); - }); -}); diff --git a/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.d.ts b/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.d.ts deleted file mode 100644 index c2dab2c3c1c3a0..00000000000000 --- a/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface StorybookMigrateDefault5to6Schema { - name?: string; - all?: boolean; - keepOld?: boolean; -} diff --git a/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.json b/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.json deleted file mode 100644 index 88db64479849da..00000000000000 --- a/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "$id": "migrate-defaults-5-to-6", - "title": "Migrate defaults 5 to 6", - "description": "Generate default Storybook configuration files using Storybook version `>=6.x` specs, for projects that already have Storybook instances and configurations of versions `<6.x`.", - "type": "object", - "properties": { - "all": { - "type": "boolean", - "description": "Generate new Storybook configurations for all Storybook instances across all apps and libs.", - "default": true - }, - "keepOld": { - "type": "boolean", - "description": "Keep the old configuration files - put them in a folder called `.old_storybook`.", - "default": true - }, - "name": { - "type": "string", - "description": "Leave empty to upgrade all Storybook instances. Only use this if you want to do a gradual migration. Library or application name for which you want to generate the new Storybook configuration.", - "$default": { - "$source": "argv", - "index": 0 - } - } - }, - "required": [] -} diff --git a/packages/storybook/src/generators/migrate-stories-to-6-2/schema.d.ts b/packages/storybook/src/generators/migrate-stories-to-6-2/schema.d.ts deleted file mode 100644 index 9a3778884b2671..00000000000000 --- a/packages/storybook/src/generators/migrate-stories-to-6-2/schema.d.ts +++ /dev/null @@ -1 +0,0 @@ -export interface StorybookMigrateStoriesTo62 {} diff --git a/packages/storybook/src/generators/migrate-stories-to-6-2/schema.json b/packages/storybook/src/generators/migrate-stories-to-6-2/schema.json deleted file mode 100644 index 132e9a87918054..00000000000000 --- a/packages/storybook/src/generators/migrate-stories-to-6-2/schema.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "$id": "migrate-stories-to-6-2", - "title": "Migrate stories to 6.2", - "description": "Migrate stories syntax to `6.2`.", - "type": "object", - "properties": {}, - "required": [] -} diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts new file mode 100644 index 00000000000000..b57b282966f7fe --- /dev/null +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts @@ -0,0 +1,116 @@ +import { readJson, Tree, updateJson } from '@nrwl/devkit'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import { storybookVersion } from '../../../utils/versions'; +import configurationGenerator from '../../../generators/configuration/configuration'; +import { + createTestUILibNoNgDevkit, + deleteNewConfigurationAndCreateNew, +} from '../../../utils/testing'; +import { migrateDefaultsGenerator } from './migrate-defaults-5-to-6'; + +describe('migrate-defaults-5-to-6 Generator', () => { + let appTree: Tree; + + beforeEach(async () => { + appTree = createTreeWithEmptyWorkspace(); + updateJson(appTree, 'package.json', (json) => { + return { + ...json, + devDependencies: { + ...json.devDependencies, + '@nrwl/storybook': '10.4.0', + '@nrwl/workspace': '10.4.0', + '@storybook/addon-knobs': '^5.3.8', + '@storybook/angular': '^5.3.8', + }, + }; + }); + await createTestUILibNoNgDevkit(appTree, 'test-ui-lib1'); + await createTestUILibNoNgDevkit(appTree, 'test-ui-lib2'); + + await configurationGenerator(appTree, { + name: 'test-ui-lib1', + uiFramework: '@storybook/react', + }); + + appTree = deleteNewConfigurationAndCreateNew( + appTree, + 'libs/test-ui-lib1/.storybook' + ); + + await configurationGenerator(appTree, { + name: 'test-ui-lib2', + uiFramework: '@storybook/react', + }); + + appTree = deleteNewConfigurationAndCreateNew( + appTree, + 'libs/test-ui-lib2/.storybook' + ); + + updateJson(appTree, 'package.json', (json) => { + return { + ...json, + devDependencies: { + ...json.devDependencies, + '@storybook/addon-knobs': '^5.3.8', + '@storybook/angular': '^5.3.8', + }, + }; + }); + }); + + it('should update Storybook packages to latest version', async () => { + migrateDefaultsGenerator(appTree); + + const packageJson = readJson(appTree, 'package.json'); + // general deps + expect(packageJson.devDependencies['@storybook/angular']).toEqual( + storybookVersion + ); + expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( + storybookVersion + ); + }); + + it('should update root config to version 6', async () => { + migrateDefaultsGenerator(appTree); + + expect(appTree.exists('.storybook/addons.js')).toBeFalsy(); + + expect(appTree.exists('.storybook/main.js')).toBeTruthy(); + }); + + it('should update configuration of all projects', async () => { + migrateDefaultsGenerator(appTree); + + expect( + appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') + ).toBeTruthy(); + expect( + appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') + ).toBeTruthy(); + + expect(appTree.exists('libs/test-ui-lib1/.storybook/main.js')).toBeTruthy(); + expect(appTree.exists('libs/test-ui-lib2/.storybook/main.js')).toBeTruthy(); + }); + + it('should keep old files and put them in .old_storybook directory', async () => { + migrateDefaultsGenerator(appTree); + expect( + appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') + ).toBeTruthy(); + expect( + appTree.exists('libs/test-ui-lib1/.old_storybook/config.js') + ).toBeTruthy(); + + expect( + appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') + ).toBeTruthy(); + expect( + appTree.exists('libs/test-ui-lib2/.old_storybook/config.js') + ).toBeTruthy(); + + expect(appTree.exists('.old_storybook/addons.js')).toBeTruthy(); + }); +}); diff --git a/packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts similarity index 64% rename from packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts rename to packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts index f87f27404abd6f..b567da962251d4 100644 --- a/packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts @@ -1,5 +1,4 @@ import { - convertNxGenerator, generateFiles, GeneratorCallback, getProjects, @@ -12,69 +11,19 @@ import { offsetFromRoot, } from '@nrwl/devkit'; import { lte } from 'semver'; -import { StorybookMigrateDefault5to6Schema } from './schema'; -import { storybookVersion } from '../../utils/versions'; +import { storybookVersion } from '../../../utils/versions'; import { join } from 'path'; import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils'; import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript'; -export function migrateDefaultsGenerator( - tree: Tree, - schema: StorybookMigrateDefault5to6Schema -) { - if (schema.all === undefined) { - schema.all = true; - } - if (schema.keepOld === undefined) { - schema.keepOld = true; - } - - /** - * The "all" flag - or the absense of "name" - * should indicate that all Storybook instances everywhere in the - * project should be migrated. - * - * Not running a migration for "all" does NOT make - * sense, since everything links back to the root .storybook - * directory, which will get migrated. - * However, someone may want to do it step by step. But all should be migrated - * eventually. - */ - let configFolder: string; - let uiFramework: string; - const runAll = schema.all && !schema.name; +export function migrateDefaultsGenerator(tree: Tree) { + migrateAllStorybookInstances(tree); - if (!runAll && schema.name) { - const projectConfig = readProjectConfiguration(tree, schema.name); - if (projectConfig.targets && projectConfig.targets.storybook) { - configFolder = - projectConfig.targets.storybook.options.config.configFolder; - uiFramework = projectConfig.targets.storybook.options.uiFramework; - } - if (projectConfig.targets && projectConfig.targets.storybook) { - configFolder = - projectConfig.targets.storybook.options.config.configFolder; - uiFramework = projectConfig.targets.storybook.options.uiFramework; - } - } - if (!runAll && configFolder) { - migrateStorybookInstance( - tree, - schema.keepOld, - schema.name, - uiFramework, - configFolder - ); - } else { - migrateAllStorybookInstances(tree, schema.keepOld); - } - if (runAll) { - migrateRootLevelStorybookInstance(tree, schema.keepOld); - return upgradeStorybookPackagesInPackageJson(tree); - } + migrateRootLevelStorybookInstance(tree); + return upgradeStorybookPackagesInPackageJson(tree); } -export function migrateAllStorybookInstances(tree: Tree, keepOld: boolean) { +export function migrateAllStorybookInstances(tree: Tree) { logger.debug('adding .storybook folder to project'); const projects = getProjects(tree); const projectsThatHaveStorybookConfiguration: { @@ -100,7 +49,6 @@ export function migrateAllStorybookInstances(tree: Tree, keepOld: boolean) { for (const projectWithStorybook of projectsThatHaveStorybookConfiguration) { migrateStorybookInstance( tree, - keepOld, projectWithStorybook.name, projectWithStorybook.uiFramework, projectWithStorybook.configFolder @@ -110,14 +58,12 @@ export function migrateAllStorybookInstances(tree: Tree, keepOld: boolean) { export function migrateStorybookInstance( tree: Tree, - keepOld: boolean, projectName: string, uiFramework: string, configFolder?: string ) { migrateProjectLevelStorybookInstance( tree, - keepOld, projectName, uiFramework, configFolder @@ -189,27 +135,16 @@ function upgradeStorybookPackagesInPackageJson(tree: Tree) { return maybeUpdateVersion(tree); } -function deleteOldFiles(tree: Tree, configFolderDir: string) { - visitNotIgnoredFiles(tree, configFolderDir, (file) => { - if (file.includes('addons.js') || file.includes('config.js')) { - tree.delete(file); - } - }); - // tree.delete(configFolderDir); -} - function moveOldFiles(tree: Tree, configFolderDir: string) { moveDirectory( tree, configFolderDir, configFolderDir.replace('.storybook', '.old_storybook') ); - // tree.delete(configFolderDir); } function migrateProjectLevelStorybookInstance( tree: Tree, - keepOld: boolean, projectName: string, uiFramework: string, configFolder: string @@ -220,21 +155,22 @@ function migrateProjectLevelStorybookInstance( configFolder.replace('.storybook', '.old_storybook') ); const new_config_exists_already = tree.exists(`${configFolder}/main.js`); + if (old_folder_exists_already || new_config_exists_already) { return; } - if (keepOld) { - moveOldFiles(tree, configFolder); - } else { - deleteOldFiles(tree, configFolder); - } + moveOldFiles(tree, configFolder); + if (tree.exists(configFolder)) { return; } generateFiles( tree, - join(__dirname, '../configuration/project-files/.storybook'), + join( + __dirname, + '../../../generators/configuration/project-files/.storybook' + ), configFolder, { tmpl: '', @@ -248,22 +184,19 @@ function migrateProjectLevelStorybookInstance( ); } -function migrateRootLevelStorybookInstance(tree: Tree, keepOld: boolean) { +function migrateRootLevelStorybookInstance(tree: Tree) { const old_folder_exists_already = tree.exists('.old_storybook'); const new_config_exists_already = tree.exists(`.storybook/main.js`); + if (old_folder_exists_already || new_config_exists_already) { return; } - if (keepOld) { - moveOldFiles(tree, '.storybook'); - } else { - deleteOldFiles(tree, '.storybook'); - } + moveOldFiles(tree, '.storybook'); generateFiles( tree, - join(__dirname, '../configuration/root-files/.storybook'), + join(__dirname, '../../../generators/configuration/root-files/.storybook'), '.storybook', { rootTsConfigPath: getRootTsConfigPathInTree(tree) } ); @@ -274,8 +207,3 @@ export function moveDirectory(tree: Tree, from: string, to: string) { tree.rename(file, file.replace(from, to)); }); } - -export default migrateDefaultsGenerator; -export const migrateDefaultsSchematic = convertNxGenerator( - migrateDefaultsGenerator -); diff --git a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts similarity index 80% rename from packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts rename to packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts index 7be29c4cfa914b..e5c45e2e2c29e4 100644 --- a/packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts @@ -1,16 +1,15 @@ import type { Tree } from '@nrwl/devkit'; import { joinPathFragments, writeJson } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { Linter } from '@nrwl/linter'; import { storybookVersion } from '@nrwl/storybook'; import { findNodes } from '@nrwl/workspace/src/utils/ast-utils'; import * as ts from 'typescript'; import { SyntaxKind } from 'typescript'; -import { getTsSourceFile } from '../../utils/nx-devkit/ast-utils'; -import { nxVersion } from '../../utils/versions'; -import { storybookConfigurationGenerator } from '../storybook-configuration/storybook-configuration'; -import { angularMigrateStoriesTo62Generator } from './migrate-stories-to-6-2'; -import libraryGenerator from '../library/library'; +import { nxVersion } from '../../../utils/versions'; +import { + getTsSourceFile, + migrateStoriesTo62Generator, +} from './migrate-stories-to-6-2'; import { overrideCollectionResolutionForTesting, wrapAngularDevkitSchematic, @@ -20,6 +19,15 @@ const componentSchematic = wrapAngularDevkitSchematic( '@schematics/angular', 'component' ); +const runAngularLibrarySchematic = wrapAngularDevkitSchematic( + '@schematics/angular', + 'library' +); + +const runAngularStorybookSchematic = wrapAngularDevkitSchematic( + '@nrwl/angular', + 'storybook-configuration' +); describe('migrate-stories-to-6-2 schematic', () => { let appTree: Tree; @@ -29,13 +37,13 @@ describe('migrate-stories-to-6-2 schematic', () => { overrideCollectionResolutionForTesting({ '@nrwl/storybook': joinPathFragments( __dirname, - '../../../../storybook/generators.json' + '../../../../generators.json' ), }); appTree = createTreeWithEmptyWorkspace(); - await libraryGenerator(appTree, { + await runAngularLibrarySchematic(appTree, { name: 'test-ui-lib', }); @@ -51,17 +59,15 @@ describe('migrate-stories-to-6-2 schematic', () => { '@storybook/angular': storybookVersion, }, }); + writeJson(appTree, 'test-ui-lib/tsconfig.json', {}); - await storybookConfigurationGenerator(appTree, { + await runAngularStorybookSchematic(appTree, { name: 'test-ui-lib', configureCypress: true, - generateCypressSpecs: true, - generateStories: true, - linter: Linter.EsLint, }); appTree.write( - `libs/test-ui-lib/src/lib/test-button/test-button.component.stories.ts`, + `test-ui-lib/src/lib/test-button/test-button.component.stories.ts`, ` import { text, number, boolean } from '@storybook/addon-knobs'; import { TestButtonComponent } from './test-button.component'; @@ -95,9 +101,9 @@ describe('migrate-stories-to-6-2 schematic', () => { }); it('should move the component from the story to parameters.component', async () => { - await angularMigrateStoriesTo62Generator(appTree); + await migrateStoriesTo62Generator(appTree); const storyFilePath = - 'libs/test-ui-lib/src/lib/test-button/test-button.component.stories.ts'; + 'test-ui-lib/src/lib/test-button/test-button.component.stories.ts'; const file = getTsSourceFile(appTree, storyFilePath); const storiesExportDefault = findNodes(file, [ ts.SyntaxKind.ExportAssignment, diff --git a/packages/storybook/src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts similarity index 98% rename from packages/storybook/src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2.ts rename to packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts index 4d1d9f77242cf7..e8b72e092055bb 100644 --- a/packages/storybook/src/generators/migrate-stories-to-6-2/migrate-stories-to-6-2.ts +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts @@ -1,7 +1,6 @@ import { applyChangesToString, ChangeType, - convertNxGenerator, formatFiles, getProjects, logger, @@ -425,8 +424,3 @@ async function changeSyntaxOfStory(tree: Tree, storyFilePath: string) { await formatFiles(tree); } - -export default migrateStoriesTo62Generator; -export const migrateStoriesSchematic = convertNxGenerator( - migrateStoriesTo62Generator -); diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-to-storybook-6.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-to-storybook-6.ts new file mode 100644 index 00000000000000..3e84c94c746fb4 --- /dev/null +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-to-storybook-6.ts @@ -0,0 +1,8 @@ +import { Tree } from '@nrwl/devkit'; +import { migrateDefaultsGenerator } from './migrate-defaults-5-to-6/migrate-defaults-5-to-6'; +import { migrateStoriesTo62Generator } from './migrate-stories-to-6-2/migrate-stories-to-6-2'; + +export default async function migrateToStorybook6(tree: Tree) { + migrateStoriesTo62Generator(tree); + return migrateDefaultsGenerator(tree); +} diff --git a/packages/storybook/src/utils/testing.ts b/packages/storybook/src/utils/testing.ts index 654b881196808b..bb32fe0f591aeb 100644 --- a/packages/storybook/src/utils/testing.ts +++ b/packages/storybook/src/utils/testing.ts @@ -1,8 +1,13 @@ import { join } from 'path'; import { externalSchematic, Rule, Tree } from '@angular-devkit/schematics'; +import { Tree as NrwlTree } from '@nrwl/devkit'; + import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { createEmptyWorkspace } from '@nrwl/workspace/testing'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import libraryGenerator from '@nrwl/workspace/src/generators/library/library'; +import { Linter } from '@nrwl/linter'; const testRunner = new SchematicTestRunner( '@nrwl/storybook', @@ -46,6 +51,22 @@ export function runMigration(migrationName: string, options: any, tree: Tree) { .toPromise(); } +export async function createTestUILibNoNgDevkit( + appTree: NrwlTree, + libName: string +): Promise { + await libraryGenerator(appTree, { + linter: Linter.EsLint, + skipFormat: true, + skipTsConfig: false, + unitTestRunner: 'none', + name: libName, + standaloneConfig: false, + }); + + return appTree; +} + export async function createTestUILib( libName: string, collectionName: '@nrwl/angular' | '@nrwl/react', @@ -120,3 +141,29 @@ export class TestButtonComponent implements OnInit { ); } } + +export function deleteNewConfigurationAndCreateNew( + appTree: NrwlTree, + projectStorybookRoot: string +): NrwlTree { + // Remove new Storybook configuration + appTree.delete(`.storybook/main.js`); + appTree.delete(`.storybook/tsconfig.json`); + appTree.delete(`${projectStorybookRoot}/main.js`); + appTree.delete(`${projectStorybookRoot}/preview.js`); + appTree.delete(`${projectStorybookRoot}/tsconfig.json`); + + // Create old Storybook configuration + appTree.write(`.storybook/addons.js`, 'console.log("hello")'); + appTree.write(`.storybook/webpack.config.js`, 'console.log("hello")'); + appTree.write(`.storybook/tsconfig.json`, '{"test": "hello"}'); + appTree.write(`${projectStorybookRoot}/config.js`, 'console.log("hello")'); + appTree.write(`${projectStorybookRoot}/addons.js`, 'console.log("hello")'); + appTree.write( + `${projectStorybookRoot}/webpack.config.js`, + 'console.log("hello")' + ); + appTree.write(`${projectStorybookRoot}/tsconfig.json`, '{"test": "hello"}'); + + return appTree; +} diff --git a/packages/storybook/src/utils/utilities.ts b/packages/storybook/src/utils/utilities.ts index 873fc0774682c7..60d758ad018435 100644 --- a/packages/storybook/src/utils/utilities.ts +++ b/packages/storybook/src/utils/utilities.ts @@ -204,30 +204,3 @@ function createStorybookConfig( ); return tmpFolder; } - -export function showStorybookV5Warning( - uiFramework: - | '@storybook/angular' - | '@storybook/react' - | '@storybook/html' - | '@storybook/web-components' - | '@storybook/vue' - | '@storybook/vue3' - | '@storybook/svelte' - | '@storybook/react-native' -) { - logger.warn( - `It looks like you're using Storybook version 5. - Please note that starting with version 14, Nx will drop support for Storybook version 5. - Before upgrading to Nx 14, please make sure you have migrated your Storybook configurations - to the latest version of Storybook. - - For more information, please take a look at our upgrade guide: - ${ - uiFramework === '@storybook/angular' - ? 'https://nx.dev/storybook/upgrade-storybook-v6-angular' - : 'https://nx.dev/storybook/upgrade-storybook-v6-react' - } - ` - ); -}