From de1b91f4834b077166a8e28a467c4864bcd4b2b7 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Mon, 6 Jun 2022 12:57:45 +0200 Subject: [PATCH] feat(eslint-plugin): improve install flow --- .../schematics/ng-add/schema.json | 2 +- modules/store/schematics/ng-add/index.spec.ts | 2 ++ modules/store/schematics/ng-add/index.ts | 27 ++++++++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/modules/eslint-plugin/schematics/ng-add/schema.json b/modules/eslint-plugin/schematics/ng-add/schema.json index 9819f90e5f..fedb208070 100644 --- a/modules/eslint-plugin/schematics/ng-add/schema.json +++ b/modules/eslint-plugin/schematics/ng-add/schema.json @@ -24,7 +24,7 @@ "all-requiring-type-checking" ], "x-prompt": { - "message": "Which config would you like to use?", + "message": "Which ESLint configuration would you like to use?", "type": "list", "items": [ { diff --git a/modules/store/schematics/ng-add/index.spec.ts b/modules/store/schematics/ng-add/index.spec.ts index 98bcaf486d..4f4e01f0b7 100644 --- a/modules/store/schematics/ng-add/index.spec.ts +++ b/modules/store/schematics/ng-add/index.spec.ts @@ -151,6 +151,8 @@ describe('Store ng-add Schematic', () => { it('adds the @ngrx/eslint-plugin schematic', async () => { const options = { ...defaultOptions, skipESLintPlugin: false }; + appTree.create('.eslintrc.json', '{}'); + await schematicRunner .runSchematicAsync('ng-add', options, appTree) .toPromise(); diff --git a/modules/store/schematics/ng-add/index.ts b/modules/store/schematics/ng-add/index.ts index d9536111c7..6ab8008f8c 100644 --- a/modules/store/schematics/ng-add/index.ts +++ b/modules/store/schematics/ng-add/index.ts @@ -120,18 +120,21 @@ function addNgRxStoreToPackageJson() { function addNgRxESLintPlugin() { return (host: Tree, context: SchematicContext) => { - addPackageToPackageJson( - host, - 'devDependencies', - '@ngrx/eslint-plugin', - platformVersion - ); - - const installTaskId = context.addTask(new NodePackageInstallTask()); - context.addTask(new RunSchematicTask('@ngrx/eslint-plugin', 'ng-add', {}), [ - installTaskId, - ]); - + const eslint = host.read('.eslintrc.json')?.toString('utf-8'); + if (eslint) { + addPackageToPackageJson( + host, + 'devDependencies', + '@ngrx/eslint-plugin', + platformVersion + ); + + const installTaskId = context.addTask(new NodePackageInstallTask()); + context.addTask( + new RunSchematicTask('@ngrx/eslint-plugin', 'ng-add', {}), + [installTaskId] + ); + } return host; }; }