@@ -60,9 +60,7 @@ import {
6060 findRoutesInSource
6161} from '../utility/routing' ;
6262
63- import {
64- addImportToModule , addProviderToModule , insertImport
65- } from '@schematics/angular/utility/ast-utils' ;
63+ import { insertImport } from '@schematics/angular/utility/ast-utils' ;
6664
6765import { getWorkspace } from '@schematics/angular/utility/workspace' ;
6866import { Change } from '@schematics/angular/utility/change' ;
@@ -168,29 +166,25 @@ function modifyFileRule(path: string, callback: (source: SourceFile) => Change[]
168166 } ;
169167}
170168
171- function updateAppModule ( host : Tree , sourcePath : string ) {
172- const appModulePath = sourcePath + 'app.component.ts' ;
169+ function updateAppComponent ( sourcePath : string , templateOptions : any = { } ) {
170+ const appMComponentPath = sourcePath + 'app.component.ts' ;
173171
174- const importSetter = ( importName : string , path : string ) => {
172+ const importSetter = ( importName : string , path : string , alias : string ) => {
175173 return ( source : SourceFile ) => {
176- return addImportToModule ( source , appModulePath , importName , path ) ;
174+ return [ insertImport ( source , appMComponentPath , importName , path , false , alias ) ] ;
177175 } ;
178176 } ;
179177
180- /*const providerSetter = (importName: string, path: string) => {
181- return (source: SourceFile) => {
182- return addProviderToModule(source, appModulePath, importName, path);
183- };
184- };*/
185-
186178 const rules = [
187- modifyFileRule ( appModulePath , importSetter ( 'DxHttpModule' , 'devextreme-angular/http' ) ) ,
179+ modifyFileRule ( appMComponentPath , importSetter (
180+ templateOptions . layout === 'side-nav-outer-toolbar'
181+ ? 'SideNavOuterToolbarComponent'
182+ : 'SideNavInnerToolbarComponent' ,
183+ './layouts' ,
184+ 'SideNavToolbarComponent' ,
185+ ) ) ,
188186 ] ;
189187
190- if ( ! hasRoutingModule ( host , sourcePath ) ) {
191- rules . push ( modifyFileRule ( appModulePath , importSetter ( 'routes' , './app.routes' ) ) ) ;
192- }
193-
194188 return chain ( rules ) ;
195189}
196190
@@ -214,7 +208,7 @@ function getComponentName(host: Tree, sourcePath: string) {
214208 return name ;
215209}
216210
217- function hasRoutingModule ( host : Tree , sourcePath : string ) {
211+ function hasRouting ( host : Tree , sourcePath : string ) {
218212 return host . exists ( sourcePath + 'app.routes.ts' ) ;
219213}
220214
@@ -294,18 +288,17 @@ function updateDevextremeConfig(sourcePath: string = '') {
294288 return modifyContentByTemplate ( './' , workspaceFilesSource , devextremeConfigPath , templateOptions , modifyConfig ) ;
295289}
296290
297- const modifyRoutingModule = ( host : Tree , routingModulePath : string ) => {
291+ const modifyRouting = ( host : Tree , routingFilePath : string ) => {
298292 // TODO: Try to use the isolated host to generate the result string
299- let source = getSourceFile ( host , routingModulePath ) ! ;
300- const importChange = insertImport ( source , routingModulePath , 'LoginFormComponent' , './shared/components' ) ;
301- const providerChanges = addProviderToModule ( source , routingModulePath , 'AuthGuardService' , './shared/services' ) ;
302- applyChanges ( host , [ importChange , ...providerChanges ] , routingModulePath ) ;
293+ let source = getSourceFile ( host , routingFilePath ) ! ;
294+ const importChange = insertImport ( source , routingFilePath , 'LoginFormComponent' , './shared/components' ) ;
295+ applyChanges ( host , [ importChange ] , routingFilePath ) ;
303296
304- source = getSourceFile ( host , routingModulePath ) ! ;
297+ source = getSourceFile ( host , routingFilePath ) ! ;
305298 const routes = findRoutesInSource ( source ) ! ;
306299 if ( ! hasComponentInRoutes ( routes , 'login-form' ) ) {
307300 const loginFormRoute = getRoute ( 'login-form' ) ;
308- insertItemToArray ( host , routingModulePath , routes , loginFormRoute ) ;
301+ insertItemToArray ( host , routingFilePath , routes , loginFormRoute ) ;
309302 }
310303} ;
311304
@@ -336,8 +329,8 @@ export default function(options: any): Rule {
336329 return `${ currentContent } \n${ templateContent } ` ;
337330 }
338331
339- if ( basename ( filePath ) === 'app.routes.ts' && hasRoutingModule ( host , appPath ) ) {
340- modifyRoutingModule ( host , filePath ) ;
332+ if ( basename ( filePath ) === 'app.routes.ts' && hasRouting ( host , appPath ) ) {
333+ modifyRouting ( host , filePath ) ;
341334 return currentContent ;
342335 }
343336
@@ -347,7 +340,7 @@ export default function(options: any): Rule {
347340 const rules = [
348341 modifyContentByTemplate ( sourcePath , projectFilesSource , null , templateOptions , modifyContent ) ,
349342 updateDevextremeConfig ( sourcePath ) ,
350- updateAppModule ( host , appPath ) ,
343+ updateAppComponent ( appPath , templateOptions ) ,
351344 addBuildThemeScript ( ) ,
352345 ( ) => addCustomThemeStyles ( host , options , sourcePath ) as any ,
353346 addViewportToBody ( sourcePath ) ,
0 commit comments