@@ -12,7 +12,6 @@ interface IMigrationDependency extends IDependency {
1212 mustRemove ?: boolean ;
1313 replaceWith ?: string ;
1414 verifiedVersion ?: string ;
15- isRequirement ?: boolean ;
1615 shouldAdd ?: boolean ;
1716}
1817
@@ -40,15 +39,15 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
4039 ] ;
4140
4241 static readonly migrationDependencies : IMigrationDependency [ ] = [
43- { packageName : constants . TNS_CORE_MODULES_NAME , isDev : false , isRequirement : true , verifiedVersion : "6.0.0-next-2019-06-10-092158-01" } ,
44- { packageName : constants . TNS_CORE_MODULES_WIDGETS_NAME , isDev : false , isRequirement : true , verifiedVersion : "6.0.0-next-2019-06-10-092158-01" } ,
42+ { packageName : constants . TNS_CORE_MODULES_NAME , isDev : false , verifiedVersion : "6.0.0-next-2019-06-10-092158-01" } ,
43+ { packageName : constants . TNS_CORE_MODULES_WIDGETS_NAME , isDev : false , verifiedVersion : "6.0.0-next-2019-06-10-092158-01" } ,
4544 { packageName : "node-sass" , isDev : true , verifiedVersion : "4.12.0" } ,
4645 { packageName : "typescript" , isDev : true , verifiedVersion : "3.4.1" } ,
4746 { packageName : "less" , isDev : true , verifiedVersion : "3.9.0" } ,
48- { packageName : "nativescript-dev-sass" , isDev : true , replaceWith : "node-sass" , isRequirement : true } ,
49- { packageName : "nativescript-dev-typescript" , isDev : true , replaceWith : "typescript" , isRequirement : true } ,
50- { packageName : "nativescript-dev-less" , isDev : true , replaceWith : "less" , isRequirement : true } ,
51- { packageName : constants . WEBPACK_PLUGIN_NAME , isDev : true , isRequirement : true , shouldAdd : true , verifiedVersion : "0.25.0-webpack-2019-06-11-105349-01" } ,
47+ { packageName : "nativescript-dev-sass" , isDev : true , replaceWith : "node-sass" } ,
48+ { packageName : "nativescript-dev-typescript" , isDev : true , replaceWith : "typescript" } ,
49+ { packageName : "nativescript-dev-less" , isDev : true , replaceWith : "less" } ,
50+ { packageName : constants . WEBPACK_PLUGIN_NAME , isDev : true , shouldAdd : true , verifiedVersion : "0.25.0-webpack-2019-06-11-105349-01" } ,
5251 { packageName : "nativescript-camera" , verifiedVersion : "4.5.0" } ,
5352 { packageName : "nativescript-geolocation" , verifiedVersion : "5.1.0" } ,
5453 { packageName : "nativescript-imagepicker" , verifiedVersion : "6.2.0" } ,
@@ -76,16 +75,18 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
7675 [ constants . DEVICE_PLATFORMS . iOS . toLowerCase ( ) ] : "6.0.0-2019-06-10-154118-03"
7776 } ;
7877
79- static readonly tempFolder : string = ".tmp_backup " ;
80- static readonly updateFailMessage : string = "Could not update the project!" ;
78+ static readonly tempFolder : string = ".migration_backup " ;
79+ static readonly updateFailMessage : string = "Could not migrate the project!" ;
8180 static readonly backupFailMessage : string = "Could not backup project folders!" ;
8281
8382 public async migrate ( { projectDir} : { projectDir : string } ) : Promise < void > {
8483 const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
8584 const tmpDir = path . join ( projectDir , MigrateController . tempFolder ) ;
8685
8786 try {
87+ this . $logger . info ( "Backup project configuration." ) ;
8888 this . backup ( MigrateController . folders , tmpDir , projectData ) ;
89+ this . $logger . info ( "Backup project configuration complete." ) ;
8990 } catch ( error ) {
9091 this . $logger . error ( MigrateController . backupFailMessage ) ;
9192 this . $fs . deleteDirectory ( tmpDir ) ;
@@ -105,29 +106,35 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
105106 const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
106107 for ( let i = 0 ; i < MigrateController . migrationDependencies . length ; i ++ ) {
107108 const dependency = MigrateController . migrationDependencies [ i ] ;
108- if ( dependency . isRequirement ) {
109- const collection = dependency . isDev ? projectData . devDependencies : projectData . dependencies ;
110- if ( dependency . replaceWith && collection && collection [ dependency . packageName ] ) {
111- return true ;
112- }
109+ const collection = dependency . isDev ? projectData . devDependencies : projectData . dependencies ;
110+ if ( dependency . replaceWith && collection && collection [ dependency . packageName ] ) {
111+ return true ;
112+ }
113113
114- if ( ! this . shouldSkipDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
115- return true ;
116- }
114+ if ( ! this . shouldSkipDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
115+ return true ;
116+ }
117+ }
118+ for ( const platform in constants . DEVICE_PLATFORMS ) {
119+ if ( await this . shouldMigrateRuntimeVersion ( platform , projectData ) ) {
120+ return true ;
117121 }
118122 }
119123 }
120124
121125 private async cleanUpProject ( projectData : IProjectData ) {
126+ this . $logger . info ( "Clean old project artefacts." ) ;
122127 this . $fs . deleteDirectory ( path . join ( projectData . projectDir , constants . HOOKS_DIR_NAME ) ) ;
123128 this . $fs . deleteDirectory ( path . join ( projectData . projectDir , constants . PLATFORMS_DIR_NAME ) ) ;
124129 this . $fs . deleteDirectory ( path . join ( projectData . projectDir , constants . NODE_MODULES_FOLDER_NAME ) ) ;
125130 this . $fs . deleteFile ( path . join ( projectData . projectDir , constants . WEBPACK_CONFIG_NAME ) ) ;
126131 this . $fs . deleteFile ( path . join ( projectData . projectDir , constants . PACKAGE_LOCK_JSON_FILE_NAME ) ) ;
127132 this . $fs . deleteFile ( path . join ( projectData . projectDir , constants . TSCCONFIG_TNS_JSON_NAME ) ) ;
133+ this . $logger . info ( "Clean old project artefacts complete." ) ;
128134 }
129135
130136 private async migrateDependencies ( projectData : IProjectData ) : Promise < void > {
137+ this . $logger . info ( "Start migrating dependencies." ) ;
131138 for ( let i = 0 ; i < MigrateController . migrationDependencies . length ; i ++ ) {
132139 const dependency = MigrateController . migrationDependencies [ i ] ;
133140 if ( this . shouldSkipDependency ( dependency , projectData ) ) {
@@ -137,33 +144,33 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
137144 if ( dependency . replaceWith ) {
138145 this . $pluginsService . removeFromPackageJson ( dependency . packageName , dependency . isDev , projectData . projectDir ) ;
139146 const replacementDep = _ . find ( MigrateController . migrationDependencies , migrationPackage => migrationPackage . packageName === dependency . replaceWith ) ;
147+ this . $logger . info ( `Replacing '${ dependency . packageName } ' with '${ replacementDep . packageName } '.` , ) ;
140148 this . $pluginsService . addToPackageJson ( replacementDep . packageName , replacementDep . verifiedVersion , replacementDep . isDev , projectData . projectDir ) ;
141149 } else if ( await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
150+ this . $logger . info ( `Updating '${ dependency . packageName } ' to compatible version '${ dependency . verifiedVersion } '` ) ;
142151 this . $pluginsService . addToPackageJson ( dependency . packageName , dependency . verifiedVersion , dependency . isDev , projectData . projectDir ) ;
143152 }
144153 }
145154
146- for ( let platform in constants . DEVICE_PLATFORMS ) {
147- platform = platform . toLowerCase ( ) ;
148- const currentPlatformVersion = this . $platformCommandHelper . getCurrentPlatformVersion ( platform , projectData ) ;
149- const verifiedPlatformVersion = MigrateController . verifiedPlatformVersions [ platform ] ;
150- const platformData = this . $platformsDataService . getPlatformData ( platform , projectData ) ;
151- if ( currentPlatformVersion ) {
152- const maxPlatformSatisfyingVersion = await this . $packageInstallationManager . maxSatisfyingVersion ( platformData . frameworkPackageName , currentPlatformVersion ) || currentPlatformVersion ;
153- if ( semver . gte ( maxPlatformSatisfyingVersion , verifiedPlatformVersion ) ) {
154- continue ;
155- }
155+ for ( const platform in constants . DEVICE_PLATFORMS ) {
156+ if ( await this . shouldMigrateRuntimeVersion ( platform , projectData ) ) {
157+ const lowercasePlatform = platform . toLowerCase ( ) ;
158+ const verifiedPlatformVersion = MigrateController . verifiedPlatformVersions [ lowercasePlatform ] ;
159+ const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
160+ this . $logger . info ( `Updating ${ platform } platform to version '${ verifiedPlatformVersion } '.` ) ;
161+ await this . $addPlatformService . setPlatformVersion ( platformData , projectData , verifiedPlatformVersion ) ;
156162 }
157-
158- await this . $addPlatformService . setPlatformVersion ( platformData , projectData , verifiedPlatformVersion ) ;
159163 }
160164
165+ this . $logger . info ( "Install packages." ) ;
161166 await this . $packageManager . install ( projectData . projectDir , projectData . projectDir , {
162167 disableNpmInstall : false ,
163168 frameworkPath : null ,
164169 ignoreScripts : false ,
165170 path : projectData . projectDir
166171 } ) ;
172+
173+ this . $logger . info ( "Migration complete." ) ;
167174 }
168175
169176 private async shouldMigrateDependencyVersion ( dependency : IMigrationDependency , projectData : IProjectData ) : Promise < boolean > {
@@ -195,6 +202,21 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
195202 return true ;
196203 }
197204
205+ private async shouldMigrateRuntimeVersion ( platform : string , projectData : IProjectData ) {
206+ const lowercasePlatform = platform . toLowerCase ( ) ;
207+ const currentPlatformVersion = this . $platformCommandHelper . getCurrentPlatformVersion ( lowercasePlatform , projectData ) ;
208+ const verifiedPlatformVersion = MigrateController . verifiedPlatformVersions [ lowercasePlatform ] ;
209+ const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
210+ if ( currentPlatformVersion ) {
211+ const maxPlatformSatisfyingVersion = await this . $packageInstallationManager . maxSatisfyingVersion ( platformData . frameworkPackageName , currentPlatformVersion ) || currentPlatformVersion ;
212+ if ( semver . gte ( maxPlatformSatisfyingVersion , verifiedPlatformVersion ) ) {
213+ return false ;
214+ }
215+ }
216+
217+ return true ;
218+ }
219+
198220 private shouldSkipDependency ( dependency : IMigrationDependency , projectData : IProjectData ) : boolean {
199221 if ( ! dependency . shouldAdd ) {
200222 const collection = dependency . isDev ? projectData . devDependencies : projectData . dependencies ;
0 commit comments