From d796731c97977cf4c4b65c69b5da19d5e5d990f2 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Fri, 21 Aug 2020 11:55:24 -0400 Subject: [PATCH] fix(angular): generate storybook configuration with proper linter (#3580) --- .../schematics/storybook-configuration.md | 10 ++++ .../schematics/storybook-configuration.md | 10 ++++ .../__snapshots__/configuration.spec.ts.snap | 55 +++++++++++++++++++ .../configuration.spec.ts | 14 +++++ .../storybook-configuration/configuration.ts | 1 + .../storybook-configuration/schema.d.ts | 3 + .../storybook-configuration/schema.json | 6 ++ 7 files changed, 99 insertions(+) create mode 100644 packages/angular/src/schematics/storybook-configuration/__snapshots__/configuration.spec.ts.snap diff --git a/docs/angular/api-angular/schematics/storybook-configuration.md b/docs/angular/api-angular/schematics/storybook-configuration.md index af8a25665a831..242cf06ba8f32 100644 --- a/docs/angular/api-angular/schematics/storybook-configuration.md +++ b/docs/angular/api-angular/schematics/storybook-configuration.md @@ -42,6 +42,16 @@ Type: `boolean` Automatically generate \*.stories.ts files for components declared in this library +### linter + +Default: `tslint` + +Type: `string` + +Possible values: `eslint`, `tslint` + +The tool to use for running lint checks. + ### name Type: `string` diff --git a/docs/react/api-angular/schematics/storybook-configuration.md b/docs/react/api-angular/schematics/storybook-configuration.md index 35d7f1128156e..751fd9c076927 100644 --- a/docs/react/api-angular/schematics/storybook-configuration.md +++ b/docs/react/api-angular/schematics/storybook-configuration.md @@ -42,6 +42,16 @@ Type: `boolean` Automatically generate \*.stories.ts files for components declared in this library +### linter + +Default: `tslint` + +Type: `string` + +Possible values: `eslint`, `tslint` + +The tool to use for running lint checks. + ### name Type: `string` diff --git a/packages/angular/src/schematics/storybook-configuration/__snapshots__/configuration.spec.ts.snap b/packages/angular/src/schematics/storybook-configuration/__snapshots__/configuration.spec.ts.snap new file mode 100644 index 0000000000000..58acf7e2c0ead --- /dev/null +++ b/packages/angular/src/schematics/storybook-configuration/__snapshots__/configuration.spec.ts.snap @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`schematic:configuration should generate the right files 1`] = ` +Array [ + "/workspace.json", + "/package.json", + "/nx.json", + "/tsconfig.base.json", + "/tslint.json", + "/jest.config.js", + "/libs/test-ui-lib/README.md", + "/libs/test-ui-lib/tsconfig.lib.json", + "/libs/test-ui-lib/tslint.json", + "/libs/test-ui-lib/tsconfig.json", + "/libs/test-ui-lib/jest.config.js", + "/libs/test-ui-lib/tsconfig.spec.json", + "/libs/test-ui-lib/src/index.ts", + "/libs/test-ui-lib/src/test-setup.ts", + "/libs/test-ui-lib/src/lib/test-ui-lib.module.ts", + "/libs/test-ui-lib/src/lib/test-button/test-button.component.css", + "/libs/test-ui-lib/src/lib/test-button/test-button.component.html", + "/libs/test-ui-lib/src/lib/test-button/test-button.component.spec.ts", + "/libs/test-ui-lib/src/lib/test-button/test-button.component.ts", + "/libs/test-ui-lib/src/lib/test-button/test-button.component.stories.ts", + "/libs/test-ui-lib/src/lib/nested/nested.module.ts", + "/libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.css", + "/libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.html", + "/libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.spec.ts", + "/libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.ts", + "/libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.stories.ts", + "/libs/test-ui-lib/src/lib/test-other/test-other.component.css", + "/libs/test-ui-lib/src/lib/test-other/test-other.component.html", + "/libs/test-ui-lib/src/lib/test-other/test-other.component.spec.ts", + "/libs/test-ui-lib/src/lib/test-other/test-other.component.ts", + "/libs/test-ui-lib/src/lib/test-other/test-other.component.stories.ts", + "/libs/test-ui-lib/.storybook/tsconfig.json", + "/libs/test-ui-lib/.storybook/addons.js", + "/libs/test-ui-lib/.storybook/config.js", + "/libs/test-ui-lib/.storybook/webpack.config.js", + "/.storybook/addons.js", + "/.storybook/tsconfig.json", + "/.storybook/webpack.config.js", + "/apps/test-ui-lib-e2e/tslint.json", + "/apps/test-ui-lib-e2e/cypress.json", + "/apps/test-ui-lib-e2e/tsconfig.e2e.json", + "/apps/test-ui-lib-e2e/tsconfig.json", + "/apps/test-ui-lib-e2e/src/fixtures/example.json", + "/apps/test-ui-lib-e2e/src/plugins/index.js", + "/apps/test-ui-lib-e2e/src/support/commands.ts", + "/apps/test-ui-lib-e2e/src/support/index.ts", + "/apps/test-ui-lib-e2e/src/integration/test-button/test-button.component.spec.ts", + "/apps/test-ui-lib-e2e/src/integration/test-other/test-other.component.spec.ts", + "/apps/test-ui-lib-e2e/src/integration/nested-button/nested-button.component.spec.ts", +] +`; diff --git a/packages/angular/src/schematics/storybook-configuration/configuration.spec.ts b/packages/angular/src/schematics/storybook-configuration/configuration.spec.ts index 9422e20be23b3..bfc0b796ad0e9 100644 --- a/packages/angular/src/schematics/storybook-configuration/configuration.spec.ts +++ b/packages/angular/src/schematics/storybook-configuration/configuration.spec.ts @@ -87,4 +87,18 @@ describe('schematic:configuration', () => { ) ).toBeTruthy(); }); + + it('should generate the right files', async () => { + const tree = await runSchematic( + 'storybook-configuration', + { + name: 'test-ui-lib', + configureCypress: true, + generateCypressSpecs: true, + generateStories: true, + }, + appTree + ); + expect(tree.files).toMatchSnapshot(); + }); }); diff --git a/packages/angular/src/schematics/storybook-configuration/configuration.ts b/packages/angular/src/schematics/storybook-configuration/configuration.ts index e34c90da96d26..c68ffb8b1894e 100644 --- a/packages/angular/src/schematics/storybook-configuration/configuration.ts +++ b/packages/angular/src/schematics/storybook-configuration/configuration.ts @@ -20,6 +20,7 @@ export default function (schema: StorybookConfigureSchema): Rule { name: schema.name, uiFramework: '@storybook/angular', configureCypress: schema.configureCypress, + linter: schema.linter, }), schema.generateStories ? generateStories(schema) : noop(), ]); diff --git a/packages/angular/src/schematics/storybook-configuration/schema.d.ts b/packages/angular/src/schematics/storybook-configuration/schema.d.ts index b5d205ffe85a9..be239d095a5c1 100644 --- a/packages/angular/src/schematics/storybook-configuration/schema.d.ts +++ b/packages/angular/src/schematics/storybook-configuration/schema.d.ts @@ -1,6 +1,9 @@ +import { Linter } from '@nrwl/workspace'; + export interface StorybookConfigureSchema { name: string; configureCypress: boolean; generateStories: boolean; generateCypressSpecs: boolean; + linter: Linter; } diff --git a/packages/angular/src/schematics/storybook-configuration/schema.json b/packages/angular/src/schematics/storybook-configuration/schema.json index b94e57942170e..1a55c565252b6 100644 --- a/packages/angular/src/schematics/storybook-configuration/schema.json +++ b/packages/angular/src/schematics/storybook-configuration/schema.json @@ -25,6 +25,12 @@ "type": "boolean", "description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure schematic", "x-prompt": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure schematic?" + }, + "linter": { + "description": "The tool to use for running lint checks.", + "type": "string", + "enum": ["eslint", "tslint"], + "default": "tslint" } }, "required": ["name"]