@@ -9,17 +9,17 @@ import {
9
9
updateJson ,
10
10
} from '@nx/devkit' ;
11
11
import { prompt } from 'enquirer' ;
12
- import { join , relative } from 'node:path' ;
12
+ import { dirname , join , relative } from 'node:path' ;
13
13
import {
14
14
ArrayLiteralExpression ,
15
15
CallExpression ,
16
16
Node ,
17
+ NoSubstitutionTemplateLiteral ,
17
18
ObjectLiteralExpression ,
18
19
Project ,
19
20
PropertyAssignment ,
20
21
ScriptKind ,
21
22
SyntaxKind ,
22
- TemplateLiteral ,
23
23
} from 'ts-morph' ;
24
24
import { addMetadataJson } from '../../utils' ;
25
25
import { ANGULAR_THREE_VERSION , NGXTENSION_VERSION , THREE_TYPE_VERSION , THREE_VERSION } from '../../versions' ;
@@ -275,21 +275,25 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
275
275
return Node . isPropertyAssignment ( node ) && node . getName ( ) === 'template' ;
276
276
} ) ;
277
277
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 ( ) : '' }
280
280
<ngt-canvas>
281
281
<app-scene-graph *canvasContent />
282
282
</ngt-canvas>` ) ;
283
283
}
284
284
285
285
// update import statements
286
+ let relativeSceneGraphPath = relative ( dirname ( componentPath ) , join ( sceneGraphPath , 'scene-graph' ) ) ;
287
+ if ( ! relativeSceneGraphPath . startsWith ( '.' ) ) {
288
+ relativeSceneGraphPath = `./${ relativeSceneGraphPath } ` ;
289
+ }
286
290
componentSourceFile . addImportDeclarations ( [
287
291
{ moduleSpecifier : 'angular-three/dom' , namedImports : [ 'NgtCanvas' ] } ,
288
- { moduleSpecifier : relative ( componentPath , sceneGraphPath ) , namedImports : [ 'SceneGraph' ] } ,
292
+ { moduleSpecifier : relativeSceneGraphPath , namedImports : [ 'SceneGraph' ] } ,
289
293
] ) ;
290
294
291
295
// update imports array
292
- const importsMetadata = componentMetadata . getFirstChild ( ( node ) : node is PropertyAssignment => {
296
+ const importsMetadata = componentMetadata . getFirstDescendant ( ( node ) : node is PropertyAssignment => {
293
297
return Node . isPropertyAssignment ( node ) && node . getName ( ) === 'imports' ;
294
298
} ) ;
295
299
0 commit comments