@@ -19,6 +19,7 @@ import {
1919 PropertyAssignment ,
2020 ScriptKind ,
2121 SyntaxKind ,
22+ TemplateLiteral ,
2223} from 'ts-morph' ;
2324import { addMetadataJson } from '../../utils' ;
2425import { ANGULAR_THREE_VERSION , NGXTENSION_VERSION , THREE_TYPE_VERSION , THREE_VERSION } from '../../versions' ;
@@ -264,32 +265,21 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
264265
265266 tree . write (
266267 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>` ,
275272 ) ;
276273 } else {
277- const templateMetadata = componentMetadata . getFirstChild ( ( node ) : node is PropertyAssignment => {
274+ const templateMetadata = componentMetadata . getFirstDescendant ( ( node ) : node is PropertyAssignment => {
278275 return Node . isPropertyAssignment ( node ) && node . getName ( ) === 'template' ;
279276 } ) ;
280- templateMetadata . setInitializer ( ( writer ) => {
281- if ( options . sceneGraph === 'append' ) {
282- writer . write ( templateMetadata . getInitializer ( ) . getText ( ) ) ;
283- writer . newLineIfLastNot ( ) ;
284- }
285277
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>` ) ;
293283 }
294284
295285 // update import statements
@@ -309,7 +299,7 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
309299 } else {
310300 componentMetadata . addPropertyAssignment ( {
311301 name : 'imports' ,
312- initializer : `[' NgtCanvas', ' SceneGraph' ]` ,
302+ initializer : `[NgtCanvas, SceneGraph]` ,
313303 } ) ;
314304 }
315305
0 commit comments