@@ -25,7 +25,7 @@ export class AddPlatformService implements IAddPlatformService {
2525 // private $projectDataService: IProjectDataService,
2626 private $packageManager : IPackageManager ,
2727 private $terminalSpinnerService : ITerminalSpinnerService ,
28- private $analyticsService : IAnalyticsService // private $tempService: ITempService
28+ private $analyticsService : IAnalyticsService , // private $tempService: ITempService
2929 ) { }
3030
3131 public async addProjectHost ( ) { }
@@ -34,7 +34,7 @@ export class AddPlatformService implements IAddPlatformService {
3434 projectData : IProjectData ,
3535 platformData : IPlatformData ,
3636 packageToInstall : string ,
37- addPlatformData : IAddPlatformData
37+ addPlatformData : IAddPlatformData ,
3838 ) : Promise < string > {
3939 const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
4040
@@ -46,11 +46,34 @@ export class AddPlatformService implements IAddPlatformService {
4646 // : await this.installPackage(projectData.projectDir, packageToInstall);
4747 const frameworkDirPath = await this . installPackage (
4848 projectData . projectDir ,
49- packageToInstall
49+ packageToInstall ,
5050 ) ;
51+
52+ const frameworkPackageJsonPath = path . join (
53+ frameworkDirPath || "" ,
54+ ".." ,
55+ "package.json" ,
56+ ) ;
57+
58+ if ( ! frameworkDirPath || ! this . $fs . exists ( frameworkPackageJsonPath ) ) {
59+ throw new Error (
60+ `Installed framework package.json not found at ${ frameworkPackageJsonPath } ` ,
61+ ) ;
62+ }
63+
5164 const frameworkPackageJsonContent = this . $fs . readJson (
52- path . join ( frameworkDirPath , ".." , "package.json" )
65+ frameworkPackageJsonPath ,
5366 ) ;
67+
68+ if (
69+ ! frameworkPackageJsonContent ||
70+ ! frameworkPackageJsonContent . version
71+ ) {
72+ throw new Error (
73+ `Installed framework package.json at ${ frameworkPackageJsonPath } does not contain a version` ,
74+ ) ;
75+ }
76+
5477 const frameworkVersion = frameworkPackageJsonContent . version ;
5578
5679 // await this.setPlatformVersion(platformData, projectData, frameworkVersion);
@@ -64,15 +87,15 @@ export class AddPlatformService implements IAddPlatformService {
6487 platformData ,
6588 projectData ,
6689 frameworkDirPath ,
67- frameworkVersion
90+ frameworkVersion ,
6891 ) ;
6992 }
7093
7194 return frameworkVersion ;
7295 } catch ( err ) {
7396 const platformPath = path . join (
7497 projectData . platformsDir ,
75- platformData . platformNameLowerCase
98+ platformData . platformNameLowerCase ,
7699 ) ;
77100 this . $fs . deleteDirectory ( platformPath ) ;
78101 throw err ;
@@ -84,11 +107,11 @@ export class AddPlatformService implements IAddPlatformService {
84107 public async setPlatformVersion (
85108 platformData : IPlatformData ,
86109 projectData : IProjectData ,
87- frameworkVersion : string
110+ frameworkVersion : string ,
88111 ) : Promise < void > {
89112 await this . installPackage (
90113 projectData . projectDir ,
91- `${ platformData . frameworkPackageName } @${ frameworkVersion } `
114+ `${ platformData . frameworkPackageName } @${ frameworkVersion } ` ,
92115 ) ;
93116 }
94117
@@ -106,7 +129,7 @@ export class AddPlatformService implements IAddPlatformService {
106129
107130 private async installPackage (
108131 projectDir : string ,
109- packageName : string
132+ packageName : string ,
110133 ) : Promise < string > {
111134 const frameworkDir = this . resolveFrameworkDir ( projectDir , packageName ) ;
112135 if ( frameworkDir && this . $fs . exists ( frameworkDir ) ) {
@@ -122,7 +145,7 @@ export class AddPlatformService implements IAddPlatformService {
122145 dev : true ,
123146 "save-dev" : true ,
124147 "save-exact" : true ,
125- } as any
148+ } as any ,
126149 ) ;
127150
128151 if ( ! installedPackage . name ) {
@@ -172,7 +195,7 @@ export class AddPlatformService implements IAddPlatformService {
172195 } catch ( err ) {
173196 this . $logger . trace (
174197 `Couldn't resolve installed framework. Continuing with install...` ,
175- err
198+ err ,
176199 ) ;
177200 }
178201 return null ;
@@ -183,36 +206,36 @@ export class AddPlatformService implements IAddPlatformService {
183206 platformData : IPlatformData ,
184207 projectData : IProjectData ,
185208 frameworkDirPath : string ,
186- frameworkVersion : string
209+ frameworkVersion : string ,
187210 ) : Promise < void > {
188211 // here we should use ios OR android
189212 const platformDir =
190213 this . $options . hostProjectPath ??
191214 path . join (
192215 projectData . platformsDir ,
193- platformData . normalizedPlatformName . toLowerCase ( )
216+ platformData . normalizedPlatformName . toLowerCase ( ) ,
194217 ) ;
195218
196219 this . $fs . deleteDirectory ( platformDir ) ;
197220 //if iosHost - dont create project
198221 await platformData . platformProjectService . createProject (
199222 path . resolve ( frameworkDirPath ) ,
200223 frameworkVersion ,
201- projectData
224+ projectData ,
202225 ) ;
203226 platformData . platformProjectService . ensureConfigurationFileInAppResources (
204- projectData
227+ projectData ,
205228 ) ;
206229 await platformData . platformProjectService . interpolateData ( projectData ) ;
207230 platformData . platformProjectService . afterCreateProject (
208231 platformData . projectRoot ,
209- projectData
232+ projectData ,
210233 ) ;
211234 }
212235
213236 private async trackPlatformVersion (
214237 frameworkVersion : string ,
215- platformData : IPlatformData
238+ platformData : IPlatformData ,
216239 ) : Promise < void > {
217240 await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
218241 action : TrackActionNames . AddPlatform ,
0 commit comments