@@ -19,6 +19,7 @@ import {
19
19
PropertyAssignment ,
20
20
ScriptKind ,
21
21
SyntaxKind ,
22
+ TemplateLiteral ,
22
23
} from 'ts-morph' ;
23
24
import { addMetadataJson } from '../../utils' ;
24
25
import { ANGULAR_THREE_VERSION , NGXTENSION_VERSION , THREE_TYPE_VERSION , THREE_VERSION } from '../../versions' ;
@@ -264,32 +265,21 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
264
265
265
266
tree . write (
266
267
templateUrlPath ,
267
- options . sceneGraph === 'replace'
268
- ? `<ngt-canvas>
269
- <app-scene-graph *canvasContent />
270
- </ngt-canvas>`
271
- : `${ templateContent }
272
- <ngt-canvas>
273
- <app-scene-graph *canvasContent />
274
- </ngt-canvas>` ,
268
+ `${ options . sceneGraph === 'append' ? templateContent : '' }
269
+ <ngt-canvas>
270
+ <app-scene-graph *canvasContent />
271
+ </ngt-canvas>` ,
275
272
) ;
276
273
} else {
277
- const templateMetadata = componentMetadata . getFirstChild ( ( node ) : node is PropertyAssignment => {
274
+ const templateMetadata = componentMetadata . getFirstDescendant ( ( node ) : node is PropertyAssignment => {
278
275
return Node . isPropertyAssignment ( node ) && node . getName ( ) === 'template' ;
279
276
} ) ;
280
- templateMetadata . setInitializer ( ( writer ) => {
281
- if ( options . sceneGraph === 'append' ) {
282
- writer . write ( templateMetadata . getInitializer ( ) . getText ( ) ) ;
283
- writer . newLineIfLastNot ( ) ;
284
- }
285
277
286
- writer . writeLine ( '<ngt-canvas>' ) ;
287
- writer . withIndentationLevel ( 2 , ( ) => {
288
- writer . writeLine ( '<app-scene-graph *canvasContent />' ) ;
289
- } ) ;
290
- writer . writeLine ( `</ngt-canvas>` ) ;
291
- writer . newLineIfLastNot ( ) ;
292
- } ) ;
278
+ const template = templateMetadata . getInitializer ( ) as TemplateLiteral ;
279
+ template . setLiteralValue ( `${ options . sceneGraph === 'append' ? template . getFullText ( ) : '' }
280
+ <ngt-canvas>
281
+ <app-scene-graph *canvasContent />
282
+ </ngt-canvas>` ) ;
293
283
}
294
284
295
285
// update import statements
@@ -309,7 +299,7 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
309
299
} else {
310
300
componentMetadata . addPropertyAssignment ( {
311
301
name : 'imports' ,
312
- initializer : `[' NgtCanvas', ' SceneGraph' ]` ,
302
+ initializer : `[NgtCanvas, SceneGraph]` ,
313
303
} ) ;
314
304
}
315
305
0 commit comments