@@ -12,7 +12,6 @@ interface IMigrationDependency extends IDependency {
12
12
mustRemove ?: boolean ;
13
13
replaceWith ?: string ;
14
14
verifiedVersion ?: string ;
15
- isRequirement ?: boolean ;
16
15
shouldAdd ?: boolean ;
17
16
}
18
17
@@ -40,15 +39,15 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
40
39
] ;
41
40
42
41
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" } ,
45
44
{ packageName : "node-sass" , isDev : true , verifiedVersion : "4.12.0" } ,
46
45
{ packageName : "typescript" , isDev : true , verifiedVersion : "3.4.1" } ,
47
46
{ 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" } ,
52
51
{ packageName : "nativescript-camera" , verifiedVersion : "4.5.0" } ,
53
52
{ packageName : "nativescript-geolocation" , verifiedVersion : "5.1.0" } ,
54
53
{ packageName : "nativescript-imagepicker" , verifiedVersion : "6.2.0" } ,
@@ -76,16 +75,18 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
76
75
[ constants . DEVICE_PLATFORMS . iOS . toLowerCase ( ) ] : "6.0.0-2019-06-10-154118-03"
77
76
} ;
78
77
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!" ;
81
80
static readonly backupFailMessage : string = "Could not backup project folders!" ;
82
81
83
82
public async migrate ( { projectDir} : { projectDir : string } ) : Promise < void > {
84
83
const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
85
84
const tmpDir = path . join ( projectDir , MigrateController . tempFolder ) ;
86
85
87
86
try {
87
+ this . $logger . info ( "Backup project configuration." ) ;
88
88
this . backup ( MigrateController . folders , tmpDir , projectData ) ;
89
+ this . $logger . info ( "Backup project configuration complete." ) ;
89
90
} catch ( error ) {
90
91
this . $logger . error ( MigrateController . backupFailMessage ) ;
91
92
this . $fs . deleteDirectory ( tmpDir ) ;
@@ -105,29 +106,35 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
105
106
const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
106
107
for ( let i = 0 ; i < MigrateController . migrationDependencies . length ; i ++ ) {
107
108
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
+ }
113
113
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 ;
117
121
}
118
122
}
119
123
}
120
124
121
125
private async cleanUpProject ( projectData : IProjectData ) {
126
+ this . $logger . info ( "Clean old project artefacts." ) ;
122
127
this . $fs . deleteDirectory ( path . join ( projectData . projectDir , constants . HOOKS_DIR_NAME ) ) ;
123
128
this . $fs . deleteDirectory ( path . join ( projectData . projectDir , constants . PLATFORMS_DIR_NAME ) ) ;
124
129
this . $fs . deleteDirectory ( path . join ( projectData . projectDir , constants . NODE_MODULES_FOLDER_NAME ) ) ;
125
130
this . $fs . deleteFile ( path . join ( projectData . projectDir , constants . WEBPACK_CONFIG_NAME ) ) ;
126
131
this . $fs . deleteFile ( path . join ( projectData . projectDir , constants . PACKAGE_LOCK_JSON_FILE_NAME ) ) ;
127
132
this . $fs . deleteFile ( path . join ( projectData . projectDir , constants . TSCCONFIG_TNS_JSON_NAME ) ) ;
133
+ this . $logger . info ( "Clean old project artefacts complete." ) ;
128
134
}
129
135
130
136
private async migrateDependencies ( projectData : IProjectData ) : Promise < void > {
137
+ this . $logger . info ( "Start migrating dependencies." ) ;
131
138
for ( let i = 0 ; i < MigrateController . migrationDependencies . length ; i ++ ) {
132
139
const dependency = MigrateController . migrationDependencies [ i ] ;
133
140
if ( this . shouldSkipDependency ( dependency , projectData ) ) {
@@ -137,33 +144,33 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
137
144
if ( dependency . replaceWith ) {
138
145
this . $pluginsService . removeFromPackageJson ( dependency . packageName , dependency . isDev , projectData . projectDir ) ;
139
146
const replacementDep = _ . find ( MigrateController . migrationDependencies , migrationPackage => migrationPackage . packageName === dependency . replaceWith ) ;
147
+ this . $logger . info ( `Replacing '${ dependency . packageName } ' with '${ replacementDep . packageName } '.` , ) ;
140
148
this . $pluginsService . addToPackageJson ( replacementDep . packageName , replacementDep . verifiedVersion , replacementDep . isDev , projectData . projectDir ) ;
141
149
} else if ( await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
150
+ this . $logger . info ( `Updating '${ dependency . packageName } ' to compatible version '${ dependency . verifiedVersion } '` ) ;
142
151
this . $pluginsService . addToPackageJson ( dependency . packageName , dependency . verifiedVersion , dependency . isDev , projectData . projectDir ) ;
143
152
}
144
153
}
145
154
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 ) ;
156
162
}
157
-
158
- await this . $addPlatformService . setPlatformVersion ( platformData , projectData , verifiedPlatformVersion ) ;
159
163
}
160
164
165
+ this . $logger . info ( "Install packages." ) ;
161
166
await this . $packageManager . install ( projectData . projectDir , projectData . projectDir , {
162
167
disableNpmInstall : false ,
163
168
frameworkPath : null ,
164
169
ignoreScripts : false ,
165
170
path : projectData . projectDir
166
171
} ) ;
172
+
173
+ this . $logger . info ( "Migration complete." ) ;
167
174
}
168
175
169
176
private async shouldMigrateDependencyVersion ( dependency : IMigrationDependency , projectData : IProjectData ) : Promise < boolean > {
@@ -195,6 +202,21 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
195
202
return true ;
196
203
}
197
204
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
+
198
220
private shouldSkipDependency ( dependency : IMigrationDependency , projectData : IProjectData ) : boolean {
199
221
if ( ! dependency . shouldAdd ) {
200
222
const collection = dependency . isDev ? projectData . devDependencies : projectData . dependencies ;
0 commit comments