@@ -2,15 +2,18 @@ import * as path from "path";
2
2
import { PROJECT_FRAMEWORK_FOLDER_NAME , TrackActionNames , AnalyticsEventLabelDelimiter } from "../../constants" ;
3
3
import { performanceLog } from "../../common/decorators" ;
4
4
import { IAddPlatformService , IPlatformData } from "../../definitions/platform" ;
5
- import { IProjectDataService , IProjectData , INativePrepare } from "../../definitions/project" ;
5
+ import { IProjectData , INativePrepare } from "../../definitions/project" ; //IProjectDataService
6
6
import { IFileSystem , IAnalyticsService } from "../../common/declarations" ;
7
7
import { injector } from "../../common/yok" ;
8
+ import { IPackageManager , IOptions } from "../../declarations" ;
8
9
9
10
export class AddPlatformService implements IAddPlatformService {
10
11
constructor (
11
12
private $fs : IFileSystem ,
12
13
private $pacoteService : IPacoteService ,
13
- private $projectDataService : IProjectDataService ,
14
+ // private $projectDataService: IProjectDataService,
15
+ private $options : IOptions ,
16
+ private $packageManager : IPackageManager ,
14
17
private $terminalSpinnerService : ITerminalSpinnerService ,
15
18
private $analyticsService : IAnalyticsService ,
16
19
private $tempService : ITempService
@@ -20,15 +23,27 @@ export class AddPlatformService implements IAddPlatformService {
20
23
const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
21
24
22
25
try {
23
- spinner . start ( ) ;
26
+ spinner . start ( ) ;
24
27
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 ;
31
34
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
+
32
47
if ( ! nativePrepare || ! nativePrepare . skipNativePrepare ) {
33
48
await this . addNativePlatform ( platformData , projectData , frameworkDirPath , frameworkVersion ) ;
34
49
}
@@ -44,8 +59,14 @@ export class AddPlatformService implements IAddPlatformService {
44
59
}
45
60
46
61
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
+ } ) ;
49
70
}
50
71
51
72
private async extractPackage ( pkg : string ) : Promise < string > {
0 commit comments