11import * as path from "path" ;
22import { PROJECT_FRAMEWORK_FOLDER_NAME , TrackActionNames , AnalyticsEventLabelDelimiter } from "../../constants" ;
33import { performanceLog } from "../../common/decorators" ;
4- import { IAddPlatformService , IPlatformData } from "../../definitions/platform" ;
5- import { IProjectData , INativePrepare } from "../../definitions/project" ; //IProjectDataService
4+ import { IAddPlatformService , IPlatformData , IAddPlatformData } from "../../definitions/platform" ;
5+ import { IProjectData } from "../../definitions/project" ; //IProjectDataService
66import { IFileSystem , IAnalyticsService } from "../../common/declarations" ;
77import { injector } from "../../common/yok" ;
8- import { IPackageManager , IOptions } from "../../declarations" ;
8+ import { IPackageManager } from "../../declarations" ;
99
1010export class AddPlatformService implements IAddPlatformService {
1111 constructor (
1212 private $fs : IFileSystem ,
1313 private $pacoteService : IPacoteService ,
1414 // private $projectDataService: IProjectDataService,
15- private $options : IOptions ,
1615 private $packageManager : IPackageManager ,
1716 private $terminalSpinnerService : ITerminalSpinnerService ,
1817 private $analyticsService : IAnalyticsService ,
1918 private $tempService : ITempService
2019 ) { }
2120
22- public async addPlatformSafe ( projectData : IProjectData , platformData : IPlatformData , packageToInstall : string , nativePrepare : INativePrepare ) : Promise < string > {
21+ public async addPlatformSafe ( projectData : IProjectData , platformData : IPlatformData , packageToInstall : string , addPlatformData : IAddPlatformData ) : Promise < string > {
2322 const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
2423
2524 try {
2625 spinner . start ( ) ;
2726
2827 let frameworkDirPath : string ;
2928 let frameworkVersion : string ;
30- if ( this . $options . frameworkPath ) {
29+ if ( addPlatformData . frameworkPath ) {
3130 frameworkDirPath = await this . extractPackage ( packageToInstall ) ;
3231 const frameworkPackageJsonContent = this . $fs . readJson ( path . join ( frameworkDirPath , ".." , "package.json" ) ) ;
3332 frameworkVersion = frameworkPackageJsonContent . version ;
@@ -38,13 +37,16 @@ export class AddPlatformService implements IAddPlatformService {
3837 const [ name , version ] = packageToInstall . split ( '@' ) ;
3938 frameworkDirPath = path . join ( projectData . projectDir , 'node_modules' , name , PROJECT_FRAMEWORK_FOLDER_NAME ) ;
4039 frameworkVersion = version ;
40+ if ( ! projectData . devDependencies ) {
41+ projectData . devDependencies = { } ;
42+ }
4143 if ( ! projectData . devDependencies [ name ] ) {
4244 await this . setPlatformVersion ( platformData , projectData , version ) ;
4345 }
4446 await this . trackPlatformVersion ( version , platformData ) ;
4547 }
4648
47- if ( ! nativePrepare || ! nativePrepare . skipNativePrepare ) {
49+ if ( ! addPlatformData . nativePrepare || ! addPlatformData . nativePrepare . skipNativePrepare ) {
4850 await this . addNativePlatform ( platformData , projectData , frameworkDirPath , frameworkVersion ) ;
4951 }
5052
@@ -59,6 +61,7 @@ export class AddPlatformService implements IAddPlatformService {
5961 }
6062
6163 public async setPlatformVersion ( platformData : IPlatformData , projectData : IProjectData , frameworkVersion : string ) : Promise < void > {
64+ // TODO: We may want to write the version to nativescript.config.js here
6265 // const frameworkPackageNameData = { version: frameworkVersion };
6366 // this.$projectDataService.setNSValue(projectData.projectDir, platformData.frameworkPackageName, frameworkPackageNameData);
6467 await this . $packageManager . install ( `${ platformData . frameworkPackageName } @${ frameworkVersion } ` , projectData . projectDir , {
0 commit comments