From 20db92f5ce0936afd57a9231f985e6839724fcbe Mon Sep 17 00:00:00 2001 From: Felipe Norato Date: Wed, 9 Oct 2019 15:53:07 -0300 Subject: [PATCH] Set entityConfig true as default --- .../ng-add/files/entity-metadata.ts.template | 4 +- modules/data/schematics/ng-add/index.spec.ts | 55 ++++++++++--------- modules/data/schematics/ng-add/schema.json | 2 +- .../ngrx.io/content/guide/data/install.md | 2 +- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/modules/data/schematics/ng-add/files/entity-metadata.ts.template b/modules/data/schematics/ng-add/files/entity-metadata.ts.template index c925116a4f..c35e88e682 100644 --- a/modules/data/schematics/ng-add/files/entity-metadata.ts.template +++ b/modules/data/schematics/ng-add/files/entity-metadata.ts.template @@ -1,10 +1,10 @@ -import { EntityMetadataMap } from '@ngrx/data'; +import { EntityMetadataMap, EntityDataModuleConfig } from '@ngrx/data'; const entityMetadata: EntityMetadataMap = {}; const pluralNames = { }; -export const entityConfig = { +export const entityConfig: EntityDataModuleConfig = { entityMetadata, pluralNames }; diff --git a/modules/data/schematics/ng-add/index.spec.ts b/modules/data/schematics/ng-add/index.spec.ts index 0cf7bfb24d..cd4407615c 100644 --- a/modules/data/schematics/ng-add/index.spec.ts +++ b/modules/data/schematics/ng-add/index.spec.ts @@ -68,26 +68,26 @@ describe('Data ng-add Schematic', () => { expect(thrownError).toBeDefined(); }); - it('should import EntityDataModuleWithoutEffects into a specified module', () => { - const options = { - ...defaultOptions, - module: 'app.module.ts', - effects: false, - }; + it('should add entity-metadata config to EntityDataModule', () => { + const options = { ...defaultOptions, effects: false, entityConfig: true }; const tree = schematicRunner.runSchematic('ng-add', options, appTree); const content = tree.readContent(`${projectPath}/src/app/app.module.ts`); expect(content).toMatch( - /import { EntityDataModuleWithoutEffects } from '@ngrx\/data'/ + /import { entityConfig } from '.\/entity-metadata'/ + ); + expect(content).toMatch( + /EntityDataModuleWithoutEffects.forRoot\(entityConfig\)/ ); }); - it('should register EntityDataModule in the provided module', () => { - const options = { ...defaultOptions }; + it('should add entity-metadata config file', () => { + const options = { ...defaultOptions, entityConfig: true }; const tree = schematicRunner.runSchematic('ng-add', options, appTree); - const content = tree.readContent(`${projectPath}/src/app/app.module.ts`); - expect(content).toMatch(/EntityDataModule\n/); + expect( + tree.files.indexOf(`${projectPath}/src/app/entity-metadata.ts`) + ).toBeGreaterThanOrEqual(0); }); it('should add entity-metadata config to EntityDataModule', () => { @@ -101,34 +101,35 @@ describe('Data ng-add Schematic', () => { expect(content).toMatch(/EntityDataModule.forRoot\(entityConfig\)/); }); - it('should register EntityDataModuleWithoutEffects in the provided module', () => { - const options = { ...defaultOptions, effects: false }; + it('should import EntityDataModuleWithoutEffects into a specified module', () => { + const options = { + ...defaultOptions, + module: 'app.module.ts', + effects: false, + entityConfig: false, + }; const tree = schematicRunner.runSchematic('ng-add', options, appTree); const content = tree.readContent(`${projectPath}/src/app/app.module.ts`); - expect(content).toMatch(/EntityDataModuleWithoutEffects\n/); + expect(content).toMatch( + /import { EntityDataModuleWithoutEffects } from '@ngrx\/data'/ + ); }); - it('should add entity-metadata config to EntityDataModule', () => { - const options = { ...defaultOptions, effects: false, entityConfig: true }; + it('should register EntityDataModule in the provided module', () => { + const options = { ...defaultOptions, entityConfig: false }; const tree = schematicRunner.runSchematic('ng-add', options, appTree); const content = tree.readContent(`${projectPath}/src/app/app.module.ts`); - expect(content).toMatch( - /import { entityConfig } from '.\/entity-metadata'/ - ); - expect(content).toMatch( - /EntityDataModuleWithoutEffects.forRoot\(entityConfig\)/ - ); + expect(content).toMatch(/EntityDataModule\n/); }); - it('should add entity-metadata config file', () => { - const options = { ...defaultOptions, entityConfig: true }; + it('should register EntityDataModuleWithoutEffects in the provided module', () => { + const options = { ...defaultOptions, effects: false, entityConfig: false }; const tree = schematicRunner.runSchematic('ng-add', options, appTree); - expect( - tree.files.indexOf(`${projectPath}/src/app/entity-metadata.ts`) - ).toBeGreaterThanOrEqual(0); + const content = tree.readContent(`${projectPath}/src/app/app.module.ts`); + expect(content).toMatch(/EntityDataModuleWithoutEffects\n/); }); describe('Migration of ngrx-data', () => { diff --git a/modules/data/schematics/ng-add/schema.json b/modules/data/schematics/ng-add/schema.json index ca896523d0..c94c82cc92 100644 --- a/modules/data/schematics/ng-add/schema.json +++ b/modules/data/schematics/ng-add/schema.json @@ -42,7 +42,7 @@ }, "entityConfig": { "type": "boolean", - "default": false, + "default": true, "description": "Create the Entity config file" } }, diff --git a/projects/ngrx.io/content/guide/data/install.md b/projects/ngrx.io/content/guide/data/install.md index 2b7c8a2f1b..34755bae90 100644 --- a/projects/ngrx.io/content/guide/data/install.md +++ b/projects/ngrx.io/content/guide/data/install.md @@ -30,7 +30,7 @@ ng add @ngrx/data * module - name of file containing the module that you wish to add the import for the `EntityDataModule` to. Can also include the relative path to the file. For example, `src/app/app.module.ts`. * effects - if `false` it will use the `EntityDataModuleWithoutEffects` module instead of the default `EntityDataModule`. * migrateNgRxData - if `true` it will replace the `ngrx-data` module with the `@ngrx/data` module. -* entityConfig - if `true` it will create and declare the `entity-metadata` file. +* entityConfig - if `false` it will not create and declare the `entity-metadata` file. This command will automate the following steps: