@@ -2,15 +2,18 @@ import * as path from "path";
22import { PROJECT_FRAMEWORK_FOLDER_NAME , TrackActionNames , AnalyticsEventLabelDelimiter } from "../../constants" ;
33import { performanceLog } from "../../common/decorators" ;
44import { IAddPlatformService , IPlatformData } from "../../definitions/platform" ;
5- import { IProjectDataService , IProjectData , INativePrepare } from "../../definitions/project" ;
5+ import { IProjectData , INativePrepare } from "../../definitions/project" ; //IProjectDataService
66import { IFileSystem , IAnalyticsService } from "../../common/declarations" ;
77import { injector } from "../../common/yok" ;
8+ import { IPackageManager , IOptions } from "../../declarations" ;
89
910export class AddPlatformService implements IAddPlatformService {
1011 constructor (
1112 private $fs : IFileSystem ,
1213 private $pacoteService : IPacoteService ,
13- private $projectDataService : IProjectDataService ,
14+ // private $projectDataService: IProjectDataService,
15+ private $options : IOptions ,
16+ private $packageManager : IPackageManager ,
1417 private $terminalSpinnerService : ITerminalSpinnerService ,
1518 private $analyticsService : IAnalyticsService ,
1619 private $tempService : ITempService
@@ -20,15 +23,27 @@ export class AddPlatformService implements IAddPlatformService {
2023 const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
2124
2225 try {
23- spinner . start ( ) ;
26+ spinner . start ( ) ;
2427
25- const frameworkDirPath = await this . extractPackage ( packageToInstall ) ;
26- const frameworkPackageJsonContent = this . $fs . readJson ( path . join ( frameworkDirPath , ".." , "package.json" ) ) ;
27- const frameworkVersion = frameworkPackageJsonContent . version ;
28-
29- await this . setPlatformVersion ( platformData , projectData , frameworkVersion ) ;
30- await this . trackPlatformVersion ( frameworkVersion , platformData ) ;
28+ let frameworkDirPath : string ;
29+ let frameworkVersion : string ;
30+ if ( this . $options . frameworkPath ) {
31+ frameworkDirPath = await this . extractPackage ( packageToInstall ) ;
32+ const frameworkPackageJsonContent = this . $fs . readJson ( path . join ( frameworkDirPath , ".." , "package.json" ) ) ;
33+ frameworkVersion = frameworkPackageJsonContent . version ;
3134
35+ await this . setPlatformVersion ( platformData , projectData , frameworkVersion ) ;
36+ await this . trackPlatformVersion ( frameworkVersion , platformData ) ;
37+ } else {
38+ const [ name , version ] = packageToInstall . split ( '@' ) ;
39+ frameworkDirPath = path . join ( projectData . projectDir , 'node_modules' , name , PROJECT_FRAMEWORK_FOLDER_NAME ) ;
40+ frameworkVersion = version ;
41+ if ( ! projectData . devDependencies [ name ] ) {
42+ await this . setPlatformVersion ( platformData , projectData , version ) ;
43+ }
44+ await this . trackPlatformVersion ( version , platformData ) ;
45+ }
46+
3247 if ( ! nativePrepare || ! nativePrepare . skipNativePrepare ) {
3348 await this . addNativePlatform ( platformData , projectData , frameworkDirPath , frameworkVersion ) ;
3449 }
@@ -44,8 +59,14 @@ export class AddPlatformService implements IAddPlatformService {
4459 }
4560
4661 public async setPlatformVersion ( platformData : IPlatformData , projectData : IProjectData , frameworkVersion : string ) : Promise < void > {
47- const frameworkPackageNameData = { version : frameworkVersion } ;
48- this . $projectDataService . setNSValue ( projectData . projectDir , platformData . frameworkPackageName , frameworkPackageNameData ) ;
62+ // const frameworkPackageNameData = { version: frameworkVersion };
63+ // this.$projectDataService.setNSValue(projectData.projectDir, platformData.frameworkPackageName, frameworkPackageNameData);
64+ await this . $packageManager . install ( `${ platformData . frameworkPackageName } @${ frameworkVersion } ` , projectData . projectDir , {
65+ 'save-dev' : true ,
66+ disableNpmInstall : true ,
67+ frameworkPath : null ,
68+ ignoreScripts : false
69+ } ) ;
4970 }
5071
5172 private async extractPackage ( pkg : string ) : Promise < string > {
0 commit comments