@@ -13,6 +13,8 @@ export class InitService implements IInitService {
13
13
"tns-core-modules" : "1.2.0"
14
14
} ;
15
15
16
+ private static VERSION_KEY_NAME = "version" ;
17
+
16
18
private _projectFilePath : string ;
17
19
18
20
constructor ( private $fs : IFileSystem ,
@@ -27,45 +29,47 @@ export class InitService implements IInitService {
27
29
28
30
public initialize ( ) : IFuture < void > {
29
31
return ( ( ) => {
30
- let projectData : any = { } ;
32
+ let projectData : any = { } ;
31
33
32
- if ( this . $fs . exists ( this . projectFilePath ) . wait ( ) ) {
34
+ if ( this . $fs . exists ( this . projectFilePath ) . wait ( ) ) {
33
35
projectData = this . $fs . readJson ( this . projectFilePath ) . wait ( ) ;
34
36
}
35
37
36
38
let projectDataBackup = _ . extend ( { } , projectData ) ;
37
39
38
- if ( ! projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] ) {
39
- projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] = { } ;
40
+ if ( ! projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] ) {
41
+ projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] = { } ;
40
42
this . $fs . writeJson ( this . projectFilePath , projectData ) . wait ( ) ; // We need to create package.json file here in order to prevent "No project found at or above and neither was a --path specified." when resolving platformsData
41
43
}
42
44
43
45
try {
44
46
45
47
projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] [ "id" ] = this . getProjectId ( ) . wait ( ) ;
46
48
47
- if ( this . $options . frameworkName && this . $options . frameworkVersion ) {
49
+ if ( this . $options . frameworkName && this . $options . frameworkVersion ) {
48
50
projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] [ this . $options . frameworkName ] = this . buildVersionData ( this . $options . frameworkVersion ) ;
49
51
} else {
50
52
let $platformsData = this . $injector . resolve ( "platformsData" ) ;
51
53
_ . each ( $platformsData . platformsNames , platform => {
52
54
let platformData : IPlatformData = $platformsData . getPlatformData ( platform ) ;
53
- if ( ! platformData . targetedOS || ( platformData . targetedOS && _ . contains ( platformData . targetedOS , process . platform ) ) ) {
54
- projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] [ platformData . frameworkPackageName ] = this . getVersionData ( platformData . frameworkPackageName ) . wait ( ) ;
55
+ if ( ! platformData . targetedOS || ( platformData . targetedOS && _ . contains ( platformData . targetedOS , process . platform ) ) ) {
56
+ let currentPlatformData = projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] [ platformData . frameworkPackageName ] || { } ;
57
+
58
+ projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] [ platformData . frameworkPackageName ] = _ . extend ( currentPlatformData , this . getVersionData ( platformData . frameworkPackageName ) . wait ( ) ) ;
55
59
}
56
60
} ) ;
57
61
}
58
62
59
63
let dependencies = projectData . dependencies ;
60
- if ( ! dependencies ) {
64
+ if ( ! dependencies ) {
61
65
projectData . dependencies = Object . create ( null ) ;
62
66
}
63
67
// In case console is interactive and --force is not specified, do not read the version from package.json, show all available versions to the user.
64
68
let tnsCoreModulesVersionInPackageJson = this . useDefaultValue ? projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] : null ;
65
69
projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] = this . $options . tnsModulesVersion || tnsCoreModulesVersionInPackageJson || this . getVersionData ( constants . TNS_CORE_MODULES_NAME ) . wait ( ) [ "version" ] ;
66
70
67
71
this . $fs . writeJson ( this . projectFilePath , projectData ) . wait ( ) ;
68
- } catch ( err ) {
72
+ } catch ( err ) {
69
73
this . $fs . writeJson ( this . projectFilePath , projectDataBackup ) . wait ( ) ;
70
74
throw err ;
71
75
}
@@ -75,7 +79,7 @@ export class InitService implements IInitService {
75
79
}
76
80
77
81
private get projectFilePath ( ) : string {
78
- if ( ! this . _projectFilePath ) {
82
+ if ( ! this . _projectFilePath ) {
79
83
let projectDir = path . resolve ( this . $options . path || "." ) ;
80
84
this . _projectFilePath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
81
85
}
@@ -85,12 +89,12 @@ export class InitService implements IInitService {
85
89
86
90
private getProjectId ( ) : IFuture < string > {
87
91
return ( ( ) => {
88
- if ( this . $options . appid ) {
92
+ if ( this . $options . appid ) {
89
93
return this . $options . appid ;
90
94
}
91
95
92
96
let defaultAppId = this . $projectHelper . generateDefaultAppId ( path . basename ( path . dirname ( this . projectFilePath ) ) , constants . DEFAULT_APP_IDENTIFIER_PREFIX ) ;
93
- if ( this . useDefaultValue ) {
97
+ if ( this . useDefaultValue ) {
94
98
return defaultAppId ;
95
99
}
96
100
@@ -101,13 +105,14 @@ export class InitService implements IInitService {
101
105
private getVersionData ( packageName : string ) : IFuture < IStringDictionary > {
102
106
return ( ( ) => {
103
107
let latestVersion = this . $npmInstallationManager . getLatestCompatibleVersion ( packageName ) . wait ( ) ;
104
- if ( this . useDefaultValue ) {
108
+
109
+ if ( this . useDefaultValue ) {
105
110
return this . buildVersionData ( latestVersion ) ;
106
111
}
107
112
108
113
let data = this . $npm . view ( packageName , "versions" ) . wait ( ) ;
109
114
let versions = _ . filter ( data [ latestVersion ] . versions , ( version : string ) => semver . gte ( version , InitService . MIN_SUPPORTED_FRAMEWORK_VERSIONS [ packageName ] ) ) ;
110
- if ( versions . length === 1 ) {
115
+ if ( versions . length === 1 ) {
111
116
this . $logger . info ( `Only ${ versions [ 0 ] } version is available for ${ packageName } .` ) ;
112
117
return this . buildVersionData ( versions [ 0 ] ) ;
113
118
}
@@ -118,7 +123,11 @@ export class InitService implements IInitService {
118
123
}
119
124
120
125
private buildVersionData ( version : string ) : IStringDictionary {
121
- return { "version" : version } ;
126
+ let result : IStringDictionary = { } ;
127
+
128
+ result [ InitService . VERSION_KEY_NAME ] = version ;
129
+
130
+ return result ;
122
131
}
123
132
124
133
private get useDefaultValue ( ) : boolean {
0 commit comments