From ac33f049b24f2246140d10e733828bc58947340c Mon Sep 17 00:00:00 2001 From: Isaac Mann Date: Tue, 3 Dec 2019 11:10:09 -0500 Subject: [PATCH] fix(nx): skip existing stories and cypress specs --- e2e/storybook.test.ts | 2 +- .../component-cypress-spec.ts | 30 +++++++++---------- .../component-story/component-story.ts | 26 +++++++--------- packages/angular/src/utils/ast-utils.ts | 29 +++++++++++++++++- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/e2e/storybook.test.ts b/e2e/storybook.test.ts index 1cb7c913e7..c326be5435 100644 --- a/e2e/storybook.test.ts +++ b/e2e/storybook.test.ts @@ -76,7 +76,7 @@ forEachCli(() => { `generate @nrwl/angular:storybook-configuration ${mylib} --configureCypress --generateStories --generateCypressSpecs --no-interactive` ); runCLI( - `generate @nrwl/storybook:configuration ${mylib} --no-interactive` + `generate @nrwl/angular:stories ${mylib} --generateCypressSpecs --no-interactive` ); writeFileSync( diff --git a/packages/angular/src/schematics/component-cypress-spec/component-cypress-spec.ts b/packages/angular/src/schematics/component-cypress-spec/component-cypress-spec.ts index 1a14c94e7f..3431e923d5 100644 --- a/packages/angular/src/schematics/component-cypress-spec/component-cypress-spec.ts +++ b/packages/angular/src/schematics/component-cypress-spec/component-cypress-spec.ts @@ -16,7 +16,11 @@ import { PropertyDeclaration, SyntaxKind } from 'typescript'; -import { getTsSourceFile, getDecoratorMetadata } from '../../utils/ast-utils'; +import { + getTsSourceFile, + getDecoratorMetadata, + applyWithSkipExisting +} from '../../utils/ast-utils'; import { getInputPropertyDeclarations, getKnobType @@ -67,20 +71,16 @@ export function createComponentSpecFile({ } ); const componentSelector = getComponentSelector(tree, fullComponentPath); - return chain([ - mergeWith( - apply(url('./files'), [ - template({ - projectName, - componentFileName: componentFileName, - componentName: componentName, - componentSelector, - props, - tmpl: '' - }), - move(e2eLibIntegrationFolderPath + '/' + componentPath) - ]) - ) + return applyWithSkipExisting(url('./files'), [ + template({ + projectName, + componentFileName: componentFileName, + componentName: componentName, + componentSelector, + props, + tmpl: '' + }), + move(e2eLibIntegrationFolderPath + '/' + componentPath) ]); }; } diff --git a/packages/angular/src/schematics/component-story/component-story.ts b/packages/angular/src/schematics/component-story/component-story.ts index 65c5f6a1f2..9ad9722a37 100644 --- a/packages/angular/src/schematics/component-story/component-story.ts +++ b/packages/angular/src/schematics/component-story/component-story.ts @@ -11,7 +11,7 @@ import { } from '@angular-devkit/schematics'; import { findNodes } from '@nrwl/workspace'; import { PropertyDeclaration, SyntaxKind } from 'typescript'; -import { getTsSourceFile } from '../../utils/ast-utils'; +import { getTsSourceFile, applyWithSkipExisting } from '../../utils/ast-utils'; import { getSourceNodes } from '@nrwl/workspace/src/utils/ast-utils'; export interface CreateComponentStoriesFileSchema { @@ -48,20 +48,16 @@ export function createComponentStoriesFile({ tree, libPath + '/' + componentPath + '/' + componentFileName + '.ts' ); - return chain([ - mergeWith( - apply(url('./files'), [ - template({ - componentFileName: componentFileName, - componentName: componentName, - relativeModulePath, - moduleName: ngModuleClassName, - props, - tmpl: '' - }), - move(libPath + '/' + componentPath) - ]) - ) + return applyWithSkipExisting(url('./files'), [ + template({ + componentFileName: componentFileName, + componentName: componentName, + relativeModulePath, + moduleName: ngModuleClassName, + props, + tmpl: '' + }), + move(libPath + '/' + componentPath) ]); }; } diff --git a/packages/angular/src/utils/ast-utils.ts b/packages/angular/src/utils/ast-utils.ts index 70ab7f3fd6..0aa1cb78d1 100644 --- a/packages/angular/src/utils/ast-utils.ts +++ b/packages/angular/src/utils/ast-utils.ts @@ -8,7 +8,16 @@ import { InsertChange, RemoveChange } from '@nrwl/workspace/src/utils/ast-utils'; -import { Tree, SchematicsException } from '@angular-devkit/schematics'; +import { + Tree, + SchematicsException, + Source, + Rule, + SchematicContext, + mergeWith, + apply, + forEach +} from '@angular-devkit/schematics'; import * as path from 'path'; import { toFileName } from '@nrwl/workspace/src/utils/name-utils'; @@ -647,3 +656,21 @@ export function getTsSourceFile(host: Tree, path: string): ts.SourceFile { return source; } + +export function applyWithSkipExisting(source: Source, rules: Rule[]): Rule { + return (tree: Tree, _context: SchematicContext) => { + const rule = mergeWith( + apply(source, [ + ...rules, + forEach(fileEntry => { + if (tree.exists(fileEntry.path)) { + return null; + } + return fileEntry; + }) + ]) + ); + + return rule(tree, _context); + }; +}