From 53a3df9129bd2a0c0508caf9e18c27730a668e30 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Mon, 28 Mar 2022 17:04:53 +0300 Subject: [PATCH] feat(storybook): keeping only things that are needed --- docs/generated/packages/react.json | 20 ----- docs/packages.json | 1 - .../compat.ts | 4 - .../schema.json | 11 --- .../storybook-migrate-defaults-5-to-6.spec.ts | 90 ------------------- .../storybook-migrate-defaults-5-to-6.ts | 10 --- .../compat.ts | 4 - .../migrate-stories-to-6-2.ts | 8 -- .../schema.json | 11 --- packages/react/generators.json | 7 -- .../migrate-defaults-5-to-6.spec.ts | 53 ----------- .../migrate-defaults-5-to-6.ts | 11 --- .../schema.json | 10 --- packages/storybook/index.ts | 2 - .../generators/configuration/configuration.ts | 4 +- .../migrate-defaults-5-to-6/schema.json | 10 --- .../migrate-stories-to-6-2/schema.json | 10 --- .../migrate-defaults-5-to-6.spec.ts | 8 +- .../migrate-defaults-5-to-6.ts | 15 ++-- .../migrate-stories-to-6-2.spec.ts | 36 ++++---- .../migrate-stories-to-6-2.ts | 6 -- .../update-14-0-0/migrate-to-storybook-6.ts | 4 +- packages/storybook/src/utils/testing.ts | 1 - 23 files changed, 35 insertions(+), 301 deletions(-) delete mode 100644 packages/angular/src/generators/storybook-migrate-defaults-5-to-6/compat.ts delete mode 100644 packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.json delete mode 100644 packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.spec.ts delete mode 100644 packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.ts delete mode 100644 packages/angular/src/generators/storybook-migrate-stories-to-6-2/compat.ts delete mode 100644 packages/angular/src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2.ts delete mode 100644 packages/angular/src/generators/storybook-migrate-stories-to-6-2/schema.json delete mode 100644 packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts delete mode 100644 packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts delete mode 100644 packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.json delete mode 100644 packages/storybook/src/generators/migrate-defaults-5-to-6/schema.json delete mode 100644 packages/storybook/src/generators/migrate-stories-to-6-2/schema.json rename packages/storybook/src/{generators => migrations/update-14-0-0}/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts (94%) rename packages/storybook/src/{generators => migrations/update-14-0-0}/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts (94%) rename packages/{angular/src/generators/storybook-migrate-stories-to-6-2 => storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2}/migrate-stories-to-6-2.spec.ts (80%) rename packages/storybook/src/{generators => migrations/update-14-0-0}/migrate-stories-to-6-2/migrate-stories-to-6-2.ts (98%) diff --git a/docs/generated/packages/react.json b/docs/generated/packages/react.json index abbdb6883fc595..d686e618731841 100644 --- a/docs/generated/packages/react.json +++ b/docs/generated/packages/react.json @@ -634,26 +634,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": {}, - "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/packages.json b/docs/packages.json index 46e12c515ecac1..e777f7bf8f55b7 100644 --- a/docs/packages.json +++ b/docs/packages.json @@ -198,7 +198,6 @@ "component", "redux", "storybook-configuration", - "storybook-migrate-defaults-5-to-6", "component-story", "stories", "component-cypress-spec", 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.json b/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.json deleted file mode 100644 index 37041e0088dc49..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/schema.json +++ /dev/null @@ -1,11 +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": {}, - "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 6557389631a8d1..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.spec.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { Tree } from '@nrwl/devkit'; -import { readJson, updateJson } from '@nrwl/devkit'; -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'; - const storybookRoot = 'libs/test-ui-lib/.storybook'; - - beforeEach(async () => { - tree = await createStorybookTestWorkspaceForLib(libName); - - updateJson(tree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@nrwl/storybook': '13.9.0', - '@nrwl/workspace': '13.9.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, - }); - - // Make Storybook versions older - updateJson(tree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@storybook/addon-knobs': '^5.3.8', - '@storybook/angular': '^5.3.8', - }, - }; - }); - - // Remove new Storybook configuration - tree.delete(`.storybook/main.js`); - tree.delete(`.storybook/tsconfig.json`); - tree.delete(`${storybookRoot}/main.js`); - tree.delete(`${storybookRoot}/preview.js`); - tree.delete(`${storybookRoot}/tsconfig.json`); - - // Create old Storybook configuration - tree.write(`.storybook/addons.js`, 'console.log("hello")'); - tree.write(`.storybook/webpack.config.js`, 'console.log("hello")'); - tree.write(`.storybook/tsconfig.json`, '{"test": "hello"}'); - tree.write(`${storybookRoot}/config.js`, 'console.log("hello")'); - tree.write(`${storybookRoot}/addons.js`, 'console.log("hello")'); - tree.write(`${storybookRoot}/webpack.config.js`, 'console.log("hello")'); - tree.write(`${storybookRoot}/tsconfig.json`, '{"test": "hello"}'); - }); - - it('should update the correct dependencies', () => { - storybookMigrateDefaults5To6Generator(tree); - - 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); - - 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(`${storybookRoot}/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 54489920be4d72..00000000000000 --- a/packages/angular/src/generators/storybook-migrate-defaults-5-to-6/storybook-migrate-defaults-5-to-6.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { GeneratorCallback, Tree } from '@nrwl/devkit'; -import { migrateDefaultsGenerator } from '@nrwl/storybook'; - -export function storybookMigrateDefaults5To6Generator( - tree: Tree -): GeneratorCallback { - return migrateDefaultsGenerator(tree); -} - -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 188b9fc85af93a..19a74d0b285ca3 100644 --- a/packages/react/generators.json +++ b/packages/react/generators.json @@ -122,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/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 b1ed40df20daf7..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); - 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 c0c98ec801e366..00000000000000 --- a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { convertNxGenerator, Tree } from '@nrwl/devkit'; -import { migrateDefaultsGenerator } from '@nrwl/storybook'; - -export function storybookMigration5to6Generator(host: Tree) { - return migrateDefaultsGenerator(host); -} - -export default storybookMigration5to6Generator; -export const storybookMigration5to6Schematic = convertNxGenerator( - storybookMigration5to6Generator -); 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 999d3c0f4d713a..00000000000000 --- a/packages/react/src/generators/storybook-migrate-defaults-5-to-6/schema.json +++ /dev/null @@ -1,10 +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": {}, - "required": [] -} 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/src/generators/configuration/configuration.ts b/packages/storybook/src/generators/configuration/configuration.ts index 08c672c1f63caa..d3c7b9ffbc6d38 100644 --- a/packages/storybook/src/generators/configuration/configuration.ts +++ b/packages/storybook/src/generators/configuration/configuration.ts @@ -213,8 +213,8 @@ function configureTsSolutionConfig( const tsConfigContent = readJson(tree, tsConfigPath); if ( - !tsConfigContent.references - .map((reference) => reference.path) + !tsConfigContent?.references + ?.map((reference) => reference.path) .includes('./.storybook/tsconfig.json') ) { tsConfigContent.references = [ 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 3c65a1c9155f8d..00000000000000 --- a/packages/storybook/src/generators/migrate-defaults-5-to-6/schema.json +++ /dev/null @@ -1,10 +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": {}, - "required": [] -} 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/generators/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 similarity index 94% rename from packages/storybook/src/generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts rename to packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts index 507993b3d2d94c..b57b282966f7fe 100644 --- a/packages/storybook/src/generators/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 @@ -1,11 +1,11 @@ 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 { - deleteNewConfigurationAndCreateNew, createTestUILibNoNgDevkit, -} from '../../utils/testing'; -import { storybookVersion } from '../../utils/versions'; -import configurationGenerator from '../configuration/configuration'; + deleteNewConfigurationAndCreateNew, +} from '../../../utils/testing'; import { migrateDefaultsGenerator } from './migrate-defaults-5-to-6'; describe('migrate-defaults-5-to-6 Generator', () => { 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 94% 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 35413a88a0fc5b..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,7 +11,7 @@ import { offsetFromRoot, } from '@nrwl/devkit'; import { lte } from 'semver'; -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'; @@ -168,7 +167,10 @@ function migrateProjectLevelStorybookInstance( } generateFiles( tree, - join(__dirname, '../configuration/project-files/.storybook'), + join( + __dirname, + '../../../generators/configuration/project-files/.storybook' + ), configFolder, { tmpl: '', @@ -194,7 +196,7 @@ function migrateRootLevelStorybookInstance(tree: Tree) { generateFiles( tree, - join(__dirname, '../configuration/root-files/.storybook'), + join(__dirname, '../../../generators/configuration/root-files/.storybook'), '.storybook', { rootTsConfigPath: getRootTsConfigPathInTree(tree) } ); @@ -205,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 5da923fcf6bfd7..26e56cb3419952 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 index 12b1f33b668525..3e84c94c746fb4 100644 --- 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 @@ -1,6 +1,6 @@ import { Tree } from '@nrwl/devkit'; -import { migrateDefaultsGenerator } from '../../generators/migrate-defaults-5-to-6/migrate-defaults-5-to-6'; -import migrateStoriesTo62Generator from '../../generators/migrate-stories-to-6-2/migrate-stories-to-6-2'; +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); diff --git a/packages/storybook/src/utils/testing.ts b/packages/storybook/src/utils/testing.ts index 0e617f6dfc01a0..bb32fe0f591aeb 100644 --- a/packages/storybook/src/utils/testing.ts +++ b/packages/storybook/src/utils/testing.ts @@ -146,7 +146,6 @@ export function deleteNewConfigurationAndCreateNew( appTree: NrwlTree, projectStorybookRoot: string ): NrwlTree { - console.log('KATERINA projectStorybookRoot', projectStorybookRoot); // Remove new Storybook configuration appTree.delete(`.storybook/main.js`); appTree.delete(`.storybook/tsconfig.json`);