@@ -24,7 +24,7 @@ import {
2424
2525import { getSourceFile } from '../utility/source' ;
2626
27- import { strings , basename , normalize , dirname , Path } from '@angular-devkit/core' ;
27+ import { strings , basename , normalize , dirname } from '@angular-devkit/core' ;
2828
2929import {
3030 getProjectName ,
@@ -106,9 +106,7 @@ export function addViewToRouting(options: any) {
106106
107107 const name = options . name . replace ( / ^ p a g e s \/ / , '' ) ;
108108 const componentName = getRouteComponentName ( name ) ;
109- const path = `./pages/${ name } /${ name } .component` ;
110-
111- const importChanges = insertImport ( source , routingModulePath , componentName , path ) ;
109+ const importChanges = insertImport ( source , routingModulePath , componentName , `./pages/${ name } /${ name } .component` ) ;
112110 applyChanges ( host , [ importChanges ] , routingModulePath ) ;
113111 }
114112 return host ;
@@ -139,48 +137,38 @@ function overwriteModuleContent(options: any, path: string, content: string) {
139137 } ;
140138}
141139
142- function getComponentFileNames ( name : string ) {
143- const baseName = strings . dasherize ( basename ( normalize ( name ) ) ) ;
144- const path = `${ dirname ( name as Path ) } /${ baseName } ` ;
145-
146- return {
147- path,
148- ts : `${ path } /${ baseName } .component.ts` as Path ,
149- html : `${ path } /${ baseName } .component.html` as Path ,
150- style : `${ path } /${ baseName } .component.css` as Path
151- } ;
152- }
153-
154140function addContentToView ( options : any ) {
155- const { html } = getComponentFileNames ( options . name ) ;
156- const title = humanize ( strings . dasherize ( basename ( normalize ( options . name ) ) ) ) ;
141+ const name = strings . dasherize ( basename ( normalize ( options . name ) ) ) ;
142+ const path = `${ dirname ( options . name ) } /${ name } ` ;
143+ const title = humanize ( name ) ;
144+ const componentPath = `${ path } /${ name } .component.html` ;
157145 const content = `<h2>${ title } </h2>
158146<div class="content-block">
159147 <div class="dx-card responsive-paddings">Put your content here</div>
160148</div>
161149` ;
162150
163- return overwriteModuleContent ( options , html , content ) ;
151+ return overwriteModuleContent ( options , componentPath , content ) ;
164152}
165153
166154async function addContentToTS ( options : any ) {
167- const { ts, html, style } = getComponentFileNames ( options . name ) ;
168155 const name = strings . dasherize ( basename ( normalize ( options . name ) ) ) ;
169- const componentName = strings . classify ( basename ( normalize ( name ) ) ) ;
156+ const path = `${ dirname ( options . name ) } /${ name } ` ;
157+ const componentPath = `${ path } /${ name } .component.ts` ;
170158 const content = `import { Component } from '@angular/core';
171159
172160@Component({
173161 selector: 'app-${ name } ',
174- templateUrl: './${ basename ( html ) } ',
175- styleUrl: './${ basename ( style ) } ',
162+ templateUrl: './${ name } .component.html ',
163+ styleUrl: './${ name } .component.css ',
176164 standalone: true
177165})
178- export class ${ componentName } Component {
166+ export class ${ strings . classify ( basename ( normalize ( name ) ) ) } Component {
179167
180168}
181169` ;
182170
183- return overwriteModuleContent ( options , ts , content ) ;
171+ return overwriteModuleContent ( options , componentPath , content ) ;
184172}
185173
186174export default function ( options : any ) : Rule {
0 commit comments