@@ -9,17 +9,17 @@ import {
99 updateJson ,
1010} from '@nx/devkit' ;
1111import { prompt } from 'enquirer' ;
12- import { join , relative } from 'node:path' ;
12+ import { dirname , join , relative } from 'node:path' ;
1313import {
1414 ArrayLiteralExpression ,
1515 CallExpression ,
1616 Node ,
17+ NoSubstitutionTemplateLiteral ,
1718 ObjectLiteralExpression ,
1819 Project ,
1920 PropertyAssignment ,
2021 ScriptKind ,
2122 SyntaxKind ,
22- TemplateLiteral ,
2323} from 'ts-morph' ;
2424import { addMetadataJson } from '../../utils' ;
2525import { ANGULAR_THREE_VERSION , NGXTENSION_VERSION , THREE_TYPE_VERSION , THREE_VERSION } from '../../versions' ;
@@ -275,21 +275,25 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
275275 return Node . isPropertyAssignment ( node ) && node . getName ( ) === 'template' ;
276276 } ) ;
277277
278- const template = templateMetadata . getInitializer ( ) as TemplateLiteral ;
279- template . setLiteralValue ( `${ options . sceneGraph === 'append' ? template . getFullText ( ) : '' }
278+ const template = templateMetadata . getInitializer ( ) as NoSubstitutionTemplateLiteral ;
279+ template . setLiteralValue ( `${ options . sceneGraph === 'append' ? template . getLiteralValue ( ) : '' }
280280<ngt-canvas>
281281 <app-scene-graph *canvasContent />
282282</ngt-canvas>` ) ;
283283 }
284284
285285 // update import statements
286+ let relativeSceneGraphPath = relative ( dirname ( componentPath ) , join ( sceneGraphPath , 'scene-graph' ) ) ;
287+ if ( ! relativeSceneGraphPath . startsWith ( '.' ) ) {
288+ relativeSceneGraphPath = `./${ relativeSceneGraphPath } ` ;
289+ }
286290 componentSourceFile . addImportDeclarations ( [
287291 { moduleSpecifier : 'angular-three/dom' , namedImports : [ 'NgtCanvas' ] } ,
288- { moduleSpecifier : relative ( componentPath , sceneGraphPath ) , namedImports : [ 'SceneGraph' ] } ,
292+ { moduleSpecifier : relativeSceneGraphPath , namedImports : [ 'SceneGraph' ] } ,
289293 ] ) ;
290294
291295 // update imports array
292- const importsMetadata = componentMetadata . getFirstChild ( ( node ) : node is PropertyAssignment => {
296+ const importsMetadata = componentMetadata . getFirstDescendant ( ( node ) : node is PropertyAssignment => {
293297 return Node . isPropertyAssignment ( node ) && node . getName ( ) === 'imports' ;
294298 } ) ;
295299
0 commit comments