diff --git a/modules/store/schematics/ng-add/index.spec.ts b/modules/store/schematics/ng-add/index.spec.ts index 8da20a2644..50423fa36d 100644 --- a/modules/store/schematics/ng-add/index.spec.ts +++ b/modules/store/schematics/ng-add/index.spec.ts @@ -16,10 +16,9 @@ describe('Store ng-add Schematic', () => { path.join(__dirname, '../collection.json') ); const defaultOptions: RootStoreOptions = { - name: 'foo', skipPackageJson: false, project: 'bar', - module: undefined, + module: 'app', }; const projectPath = getTestProjectPath(); @@ -58,18 +57,21 @@ describe('Store ng-add Schematic', () => { ).toBeGreaterThanOrEqual(0); }); - it('should not be provided by default', () => { + it('should be provided by default', () => { const options = { ...defaultOptions }; const tree = schematicRunner.runSchematic('ng-add', options, appTree); const content = tree.readContent(`${projectPath}/src/app/app.module.ts`); - expect(content).not.toMatch( + expect(content).toMatch( /import { reducers, metaReducers } from '\.\/reducers';/ ); + expect(content).toMatch( + /StoreModule.forRoot\(reducers, { metaReducers }\)/ + ); }); it('should import into a specified module', () => { - const options = { ...defaultOptions, module: 'app.module.ts' }; + const options = { ...defaultOptions }; const tree = schematicRunner.runSchematic('ng-add', options, appTree); const content = tree.readContent(`${projectPath}/src/app/app.module.ts`); diff --git a/modules/store/schematics/ng-add/index.ts b/modules/store/schematics/ng-add/index.ts index 4aa482036a..9ebbdd03a1 100644 --- a/modules/store/schematics/ng-add/index.ts +++ b/modules/store/schematics/ng-add/index.ts @@ -55,23 +55,19 @@ function addImportToNgModule(options: RootStoreOptions): Rule { true ); - const statePath = `${options.path}/${options.statePath}`; + const statePath = `/${options.path}/${options.statePath}`; const relativePath = buildRelativePath(modulePath, statePath); - const srcPath = dirname(options.path as Path); - const environmentsPath = buildRelativePath( - statePath, - `/${srcPath}/environments/environment` + const [storeNgModuleImport] = addImportToModule( + source, + modulePath, + 'StoreModule.forRoot(reducers, { metaReducers })', + relativePath ); const changes = [ insertImport(source, modulePath, 'StoreModule', '@ngrx/store'), insertImport(source, modulePath, 'reducers, metaReducers', relativePath), - addImportToModule( - source, - modulePath, - 'StoreModule.forRoot(reducers, { metaReducers })', - relativePath - ), + storeNgModuleImport, ]; const recorder = host.beginUpdate(modulePath); @@ -103,8 +99,7 @@ export default function(options: RootStoreOptions): Rule { return (host: Tree, context: SchematicContext) => { options.path = getProjectPath(host, options); - const parsedPath = parseName(options.path, options.name); - options.name = parsedPath.name; + const parsedPath = parseName(options.path, ''); options.path = parsedPath.path; const statePath = `/${options.path}/${options.statePath}/index.ts`; @@ -115,7 +110,11 @@ export default function(options: RootStoreOptions): Rule { ); if (options.module) { - options.module = findModuleFromOptions(host, options); + options.module = findModuleFromOptions(host, { + name: '', + module: options.module, + path: options.path, + }); } if (options.stateInterface && options.stateInterface !== 'State') { @@ -132,7 +131,6 @@ export default function(options: RootStoreOptions): Rule { ]); return chain([ - options && options.skipPackageJson ? noop() : addNgRxStoreToPackageJson(), branchAndMerge( chain([ filter( @@ -144,6 +142,7 @@ export default function(options: RootStoreOptions): Rule { mergeWith(templateSource), ]) ), + options && options.skipPackageJson ? noop() : addNgRxStoreToPackageJson(), ])(host, context); }; } diff --git a/modules/store/schematics/ng-add/schema.json b/modules/store/schematics/ng-add/schema.json index b4f7016859..7d1d125de0 100644 --- a/modules/store/schematics/ng-add/schema.json +++ b/modules/store/schematics/ng-add/schema.json @@ -4,14 +4,6 @@ "title": "NgRx Root State Management Options Schema", "type": "object", "properties": { - "name": { - "description": "The name of the state.", - "type": "string", - "$default": { - "$source": "argv", - "index": 0 - } - }, "skipPackageJson": { "type": "boolean", "default": false, @@ -21,12 +13,12 @@ "path": { "type": "string", "format": "path", - "description": "The path to create the component.", + "description": "The path to create the state.", "visible": false }, "module": { "type": "string", - "default": "", + "default": "app", "description": "Allows specification of the declaring module.", "alias": "m", "subtype": "filepath" diff --git a/modules/store/schematics/ng-add/schema.ts b/modules/store/schematics/ng-add/schema.ts index 3f9671fc19..f9fe5c7201 100644 --- a/modules/store/schematics/ng-add/schema.ts +++ b/modules/store/schematics/ng-add/schema.ts @@ -1,5 +1,4 @@ export interface Schema { - name: string; skipPackageJson?: boolean; path?: string; project?: string;