@@ -3,9 +3,14 @@ import { join, dirname, basename } from 'path';
3
3
import { Tree , SchematicsException } from '@angular-devkit/schematics' ;
4
4
import { getWorkspace } from '@schematics/angular/utility/config' ;
5
5
import { getProjectTargets } from '@schematics/angular/utility/project-targets' ;
6
+ import {
7
+ getAppModulePath ,
8
+ findBootstrapModuleCall ,
9
+ findBootstrapModulePath ,
10
+ } from '@schematics/angular/utility/ng-ast-utils' ;
6
11
7
12
import { getSourceFile , safeGet } from './utils' ;
8
- import { findNode , getFunctionParams , findImportPath } from './ast-utils' ;
13
+ import { findNode , findImportPath } from './ast-utils' ;
9
14
10
15
export interface AngularProjectSettings {
11
16
/** default: '' */
@@ -106,7 +111,7 @@ export function getAngularProjectSettings(tree: Tree, projectName: string): Angu
106
111
} ;
107
112
}
108
113
109
- export function getCoreProjectSettings ( tree : Tree , projectName : string ) : CoreProjectSettings {
114
+ function getCoreProjectSettings ( tree : Tree , projectName : string ) : CoreProjectSettings {
110
115
const project = getProjectObject ( tree , projectName ) ;
111
116
const targets = getProjectTargets ( project ) ;
112
117
if ( ! targets ) {
@@ -149,28 +154,24 @@ function getProjectObject(tree: Tree, projectName: string) {
149
154
return project ;
150
155
}
151
156
152
- // Step 2 - get entryModule and entryModulePath => open ${sourceRoot}/${main}.ts
153
- // - get entryModule from .bootstrapModule(__value__)
154
- // - get entryModulePath from import { ${entryModule} } from '__value__' -- might need to remove ./
155
157
function getEntryModuleMetadata ( tree : Tree , mainPath : string ) : ClassMetadata {
156
- const source = getSourceFile ( tree , mainPath ) ;
157
-
158
- const params = getFunctionParams ( source , 'bootstrapModule' ) ;
159
- const className = params [ 0 ] ;
160
-
161
- const name = className . replace ( 'Module' , '' ) ;
162
-
163
- const importPath : string = findImportPath ( source , className ) ;
164
-
165
- const mainDir = dirname ( mainPath ) ;
166
- const path = join ( mainDir , importPath ) + '.ts' ;
158
+ const bootstrapCall = findBootstrapModuleCall ( tree , mainPath ) ;
159
+ if ( ! bootstrapCall ) {
160
+ throw new SchematicsException ( 'Bootstrap call not found! Cannot build project data!' ) ;
161
+ }
162
+ const className = bootstrapCall . arguments [ 0 ] . getText ( ) ;
163
+ const name = className . replace ( / M o d u l e $ / , '' ) ;
164
+ const importPath = findBootstrapModulePath ( tree , mainPath ) ;
165
+ const path = getAppModulePath ( tree , mainPath ) ;
167
166
168
- return {
167
+ const metadata = {
169
168
className,
170
169
name,
171
170
importPath,
172
- path
173
- }
171
+ path,
172
+ } ;
173
+
174
+ return metadata ;
174
175
}
175
176
176
177
// Step 3 - get appComponent and appComponentPath => open ${appRoot}/${entryModulePath}
0 commit comments