@@ -74,9 +74,12 @@ export async function initGenerator(
74
74
75
75
if ( generateExperience !== 'none' ) {
76
76
const projects = getProjects ( tree ) ;
77
- const applicationProjects = Array . from ( projects . values ( ) ) . filter (
78
- ( project ) => project . projectType === 'application' ,
79
- ) ;
77
+ const applicationProjects = Array . from ( projects . entries ( ) ) . reduce ( ( acc , [ projectName , project ] ) => {
78
+ if ( project . projectType === 'application' ) {
79
+ acc . push ( { name : projectName , ...project } ) ;
80
+ }
81
+ return acc ;
82
+ } , [ ] ) ;
80
83
let selectedProject : string ;
81
84
if ( applicationProjects . length === 1 ) {
82
85
selectedProject = applicationProjects [ 0 ] . name ;
@@ -130,7 +133,7 @@ export async function initGenerator(
130
133
131
134
let updatedContent = tsquery . replace (
132
135
appComponentContent ,
133
- 'Identifier[name="imports"] ~ ArrayLiteralExpression' ,
136
+ 'PropertyAssignment:has( Identifier[name="imports"]) ArrayLiteralExpression' ,
134
137
( node : ArrayLiteralExpression ) => {
135
138
return `[${ node . elements . map ( ( element ) => element [ 'escapedText' ] ) . join ( ', ' ) } , NgtCanvas]` ;
136
139
} ,
@@ -149,7 +152,7 @@ ${node.getFullText()}
149
152
const classMembersQuery = 'ClassDeclaration > :matches(PropertyDeclaration,MethodDeclaration)' ;
150
153
const members = tsquery . match ( appComponentContentAst , classMembersQuery ) ;
151
154
152
- if ( members . length === 0 ) {
155
+ if ( members . length === 0 || generateExperience === 'replace' ) {
153
156
updatedContent = tsquery . replace ( updatedContent , 'ClassDeclaration' , ( node ) => {
154
157
const withoutBraces = node . getFullText ( ) . slice ( 0 , - 1 ) ;
155
158
return `
@@ -160,7 +163,7 @@ ${withoutBraces}
160
163
} else {
161
164
updatedContent = tsquery . replace ( updatedContent , classMembersQuery , ( node ) => {
162
165
return `
163
- scene = Experience;
166
+ sceneGraph = Experience;
164
167
${ node . getFullText ( ) } `;
165
168
} ) ;
166
169
}
@@ -170,19 +173,19 @@ ${node.getFullText()}`;
170
173
generateExperience === 'append'
171
174
? `
172
175
${ appComponentTemplateContent }
173
- <ngt-canvas [sceneGraph]="scene " />`
174
- : `<ngt-canvas [sceneGraph]="scene " />` ;
176
+ <ngt-canvas [sceneGraph]="sceneGraph " />`
177
+ : `<ngt-canvas [sceneGraph]="sceneGraph " />` ;
175
178
tree . write ( appComponentTemplatePath , updatedTemplateContent ) ;
176
179
} else {
177
180
updatedContent = tsquery . replace (
178
181
updatedContent ,
179
- 'Identifier[name="template"] ~ NoSubstitutionTemplateLiteral' ,
182
+ 'PropertyAssignment:has( Identifier[name="template"]) NoSubstitutionTemplateLiteral' ,
180
183
( node : NoSubstitutionTemplateLiteral ) => {
181
184
return generateExperience === 'append'
182
185
? `\`
183
186
${ node . getFullText ( ) }
184
- <ngt-canvas [sceneGraph]="scene " />\``
185
- : `\`<ngt-canvas [sceneGraph]="scene " />\`` ;
187
+ <ngt-canvas [sceneGraph]="sceneGraph " />\``
188
+ : `\`<ngt-canvas [sceneGraph]="sceneGraph " />\`` ;
186
189
} ,
187
190
) ;
188
191
}
0 commit comments