1
1
///<reference path="../.d.ts"/>
2
2
"use strict" ;
3
3
4
- import path = require( "path" ) ;
5
-
6
4
export class InstallCommand implements ICommand {
7
5
private _projectData : any ;
8
6
9
- constructor ( private $fs : IFileSystem ,
10
- private $errors : IErrors ,
11
- private $logger : ILogger ,
12
- private $options : IOptions ,
13
- private $injector : IInjector ,
14
- private $staticConfig : IStaticConfig ) { }
7
+ constructor ( private $platformsData : IPlatformsData ,
8
+ private $platformService : IPlatformService ,
9
+ private $projectData : IProjectData ,
10
+ private $projectDataService : IProjectDataService ) { }
15
11
16
12
public enableHooks = false ;
17
13
18
14
public allowedParameters : ICommandParameter [ ] = [ ] ;
19
15
20
16
public execute ( args : string [ ] ) : IFuture < void > {
21
17
return ( ( ) => {
22
- let projectFilePath = this . getProjectFilePath ( args [ 0 ] ) ;
23
- let projectData = this . getProjectData ( projectFilePath ) . wait ( ) ;
24
- let projectName = projectData . id . split ( "." ) [ 2 ] ;
25
-
26
- this . $injector . resolve ( "projectService" ) . createProject ( projectName ) . wait ( ) ;
27
-
28
- this . $options . path = path . join ( this . $options . path || path . resolve ( "." ) , projectName ) ;
18
+ this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
29
19
30
- this . $logger . info ( "Adding platforms..." ) ;
31
-
32
- let $platformsData = this . $injector . resolve ( "platformsData" ) ;
33
- let $platformService = this . $injector . resolve ( "platformService" ) ;
34
- _ . each ( $platformsData . platformsNames , platform => {
35
- let platformData = $platformsData . getPlatformData ( platform ) ;
36
- let frameworkPackageData = projectData [ platformData . frameworkPackageName ] ;
20
+ _ . each ( this . $platformsData . platformsNames , platform => {
21
+ let platformData = this . $platformsData . getPlatformData ( platform ) ;
22
+ let frameworkPackageData = this . $projectDataService . getValue ( platformData . frameworkPackageName ) . wait ( ) ;
37
23
if ( frameworkPackageData && frameworkPackageData . version ) {
38
- $platformService . addPlatforms ( [ `${ platform } @${ frameworkPackageData . version } ` ] ) . wait ( ) ;
24
+ this . $platformService . addPlatforms ( [ `${ platform } @${ frameworkPackageData . version } ` ] ) . wait ( ) ;
39
25
}
40
- } ) ;
41
-
26
+ } ) ;
42
27
} ) . future < void > ( ) ( ) ;
43
28
}
44
-
45
- public canExecute ( args : string [ ] ) : IFuture < boolean > {
46
- return ( ( ) => {
47
- let projectFilePath = this . getProjectFilePath ( args [ 0 ] ) ;
48
- let errorMessage = args [ 0 ] ? "The provided path doesn't contain package.json." :
49
- "The current directory doesn't contain package.json file. Execute the command in directory which contains package.json file or specify the path to package.json file." ;
50
-
51
- if ( ! this . $fs . exists ( projectFilePath ) . wait ( ) ) {
52
- this . $errors . failWithoutHelp ( errorMessage ) ;
53
- }
54
-
55
- let projectData = this . getProjectData ( projectFilePath ) . wait ( ) ;
56
- if ( ! projectData ) {
57
- this . $errors . failWithoutHelp ( "Invalid project file. Verify that the specified package.json file contains a nativescript key and try again." ) ;
58
- }
59
-
60
- if ( ! projectData . id ) {
61
- this . $errors . failWithoutHelp ( "Invalid project file. Verify that the specified package.json file contains an id and try again." ) ;
62
- }
63
-
64
- return true ;
65
- } ) . future < boolean > ( ) ( ) ;
66
- }
67
-
68
- private getProjectFilePath ( providedPath : string ) : string {
69
- let resolvedPath = path . resolve ( providedPath || "." ) ;
70
- return path . basename ( resolvedPath ) === "package.json" ? resolvedPath : path . join ( resolvedPath , "package.json" ) ;
71
- }
72
-
73
- private getProjectData ( projectFilePath : string ) : IFuture < any > {
74
- return ( ( ) => {
75
- if ( ! this . _projectData ) {
76
- let fileContent = this . $fs . readJson ( projectFilePath ) . wait ( ) ;
77
- this . _projectData = fileContent [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] ;
78
- }
79
-
80
- return this . _projectData ;
81
- } ) . future < any > ( ) ( ) ;
82
- }
83
29
}
84
30
$injector . registerCommand ( "install" , InstallCommand ) ;
0 commit comments