@@ -13,6 +13,8 @@ export class InitService implements IInitService {
1313 "tns-core-modules" : "1.2.0"
1414 } ;
1515
16+ private static VERSION_KEY_NAME = "version" ;
17+
1618 private _projectFilePath : string ;
1719
1820 constructor ( private $fs : IFileSystem ,
@@ -27,45 +29,47 @@ export class InitService implements IInitService {
2729
2830 public initialize ( ) : IFuture < void > {
2931 return ( ( ) => {
30- let projectData : any = { } ;
32+ let projectData : any = { } ;
3133
32- if ( this . $fs . exists ( this . projectFilePath ) . wait ( ) ) {
34+ if ( this . $fs . exists ( this . projectFilePath ) . wait ( ) ) {
3335 projectData = this . $fs . readJson ( this . projectFilePath ) . wait ( ) ;
3436 }
3537
3638 let projectDataBackup = _ . extend ( { } , projectData ) ;
3739
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 ] = { } ;
4042 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
4143 }
4244
4345 try {
4446
4547 projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] [ "id" ] = this . getProjectId ( ) . wait ( ) ;
4648
47- if ( this . $options . frameworkName && this . $options . frameworkVersion ) {
49+ if ( this . $options . frameworkName && this . $options . frameworkVersion ) {
4850 projectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] [ this . $options . frameworkName ] = this . buildVersionData ( this . $options . frameworkVersion ) ;
4951 } else {
5052 let $platformsData = this . $injector . resolve ( "platformsData" ) ;
5153 _ . each ( $platformsData . platformsNames , platform => {
5254 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 ( ) ) ;
5559 }
5660 } ) ;
5761 }
5862
5963 let dependencies = projectData . dependencies ;
60- if ( ! dependencies ) {
64+ if ( ! dependencies ) {
6165 projectData . dependencies = Object . create ( null ) ;
6266 }
6367 // 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.
6468 let tnsCoreModulesVersionInPackageJson = this . useDefaultValue ? projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] : null ;
6569 projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] = this . $options . tnsModulesVersion || tnsCoreModulesVersionInPackageJson || this . getVersionData ( constants . TNS_CORE_MODULES_NAME ) . wait ( ) [ "version" ] ;
6670
6771 this . $fs . writeJson ( this . projectFilePath , projectData ) . wait ( ) ;
68- } catch ( err ) {
72+ } catch ( err ) {
6973 this . $fs . writeJson ( this . projectFilePath , projectDataBackup ) . wait ( ) ;
7074 throw err ;
7175 }
@@ -75,7 +79,7 @@ export class InitService implements IInitService {
7579 }
7680
7781 private get projectFilePath ( ) : string {
78- if ( ! this . _projectFilePath ) {
82+ if ( ! this . _projectFilePath ) {
7983 let projectDir = path . resolve ( this . $options . path || "." ) ;
8084 this . _projectFilePath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
8185 }
@@ -85,12 +89,12 @@ export class InitService implements IInitService {
8589
8690 private getProjectId ( ) : IFuture < string > {
8791 return ( ( ) => {
88- if ( this . $options . appid ) {
92+ if ( this . $options . appid ) {
8993 return this . $options . appid ;
9094 }
9195
9296 let defaultAppId = this . $projectHelper . generateDefaultAppId ( path . basename ( path . dirname ( this . projectFilePath ) ) , constants . DEFAULT_APP_IDENTIFIER_PREFIX ) ;
93- if ( this . useDefaultValue ) {
97+ if ( this . useDefaultValue ) {
9498 return defaultAppId ;
9599 }
96100
@@ -101,13 +105,14 @@ export class InitService implements IInitService {
101105 private getVersionData ( packageName : string ) : IFuture < IStringDictionary > {
102106 return ( ( ) => {
103107 let latestVersion = this . $npmInstallationManager . getLatestCompatibleVersion ( packageName ) . wait ( ) ;
104- if ( this . useDefaultValue ) {
108+
109+ if ( this . useDefaultValue ) {
105110 return this . buildVersionData ( latestVersion ) ;
106111 }
107112
108113 let data = this . $npm . view ( packageName , "versions" ) . wait ( ) ;
109114 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 ) {
111116 this . $logger . info ( `Only ${ versions [ 0 ] } version is available for ${ packageName } .` ) ;
112117 return this . buildVersionData ( versions [ 0 ] ) ;
113118 }
@@ -118,7 +123,11 @@ export class InitService implements IInitService {
118123 }
119124
120125 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 ;
122131 }
123132
124133 private get useDefaultValue ( ) : boolean {
0 commit comments