1
- import { AngularComponentTemplateOptions } from '@bitdev/angular.dev-services.common' ;
1
+ import { AngularComponentTemplateOptions , getWorkspace } from '@bitdev/angular.dev-services.common' ;
2
2
import { confirm , group , select } from '@clack/prompts' ;
3
+ import { ComponentID } from '@teambit/component' ;
3
4
import { EnvContext , EnvHandler } from '@teambit/envs' ;
4
5
import { ComponentContext , ComponentTemplate } from '@teambit/generator' ;
5
6
import { Logger } from '@teambit/logger' ;
7
+ import { PkgAspect , PkgMain } from '@teambit/pkg' ;
8
+ import { Workspace } from '@teambit/workspace' ;
6
9
import { isCI } from 'std-env' ;
7
10
import { indexFile } from './template-files' ;
8
- import { docsFile } from './template-files/docs' ;
9
11
import { ngAppFile } from './template-files/bit-app' ;
12
+ import { docsFile } from './template-files/docs' ;
10
13
import { appComponentFile } from './template-files/src/app/app.component' ;
11
14
import { appComponentHtmlFile } from './template-files/src/app/app.component-html' ;
12
15
import { appComponentStyleSheetFile } from './template-files/src/app/app.component-scss' ;
@@ -33,7 +36,9 @@ export class NgAppTemplate implements ComponentTemplate {
33
36
readonly angularVersion : number ,
34
37
readonly name = 'ng-app' ,
35
38
readonly description = 'create an Angular application' ,
36
- readonly hidden = false
39
+ readonly hidden = false ,
40
+ private pkg : PkgMain ,
41
+ private workspace : Workspace | undefined
37
42
) {
38
43
}
39
44
@@ -86,10 +91,22 @@ export class NgAppTemplate implements ComponentTemplate {
86
91
params = await this . prompt ( context ) ;
87
92
}
88
93
94
+ const aspectId : ComponentID = typeof context . aspectId === 'string' ? ComponentID . fromString ( context . aspectId ) : context . aspectId ;
95
+ const envId = aspectId . toStringWithoutVersion ( ) ;
96
+ let envPkgName : string ;
97
+ if ( this . workspace ) {
98
+ const envComponent = await this . workspace ! . get ( aspectId ) ;
99
+ envPkgName = this . pkg . getPackageName ( envComponent ) ;
100
+ } else if ( envId === 'bitdev.angular/angular-env' ) { // mostly for ci / ripple
101
+ envPkgName = '@bitdev/angular.angular-env' ;
102
+ } else {
103
+ envPkgName = `@bitdev/angular.envs.angular-v${ this . angularVersion } -env` ;
104
+ }
105
+
89
106
const files = [
90
107
docsFile ( context ) ,
91
108
indexFile ( context ) ,
92
- ngAppFile ( context , params . styleSheet , params . ssr ) ,
109
+ ngAppFile ( context , params . styleSheet , params . ssr , envPkgName ) ,
93
110
tsconfigFile ( this . angularVersion , params . ssr ) ,
94
111
indexHtmlFile ( context ) ,
95
112
mainNgAppFile ( params . standalone ) ,
@@ -137,12 +154,16 @@ export class NgAppTemplate implements ComponentTemplate {
137
154
return ( context : EnvContext ) => {
138
155
const name = options . name || 'ng-app-template' ;
139
156
const logger = context . createLogger ( name ) ;
157
+ const pkg = context . getAspect < PkgMain > ( PkgAspect . id ) ;
158
+ const workspace = getWorkspace ( context ) ;
140
159
return new NgAppTemplate (
141
160
logger ,
142
161
options . angularVersion ,
143
162
options . name ,
144
163
options . description ,
145
- options . hidden
164
+ options . hidden ,
165
+ pkg ,
166
+ workspace
146
167
) ;
147
168
} ;
148
169
}
0 commit comments