@@ -6,6 +6,13 @@ import { UpdateControllerBase } from "./update-controller-base";
6
6
import { fromWindowsRelativePathToUnix } from "../common/helpers" ;
7
7
8
8
export class MigrateController extends UpdateControllerBase implements IMigrateController {
9
+ // TODO: Update the links to blog post when it is available
10
+ private static COMMON_MIGRATE_MESSAGE = "not affect the codebase of the application and you might need to do additional changes manually – for more information, refer to the instructions in the following blog post: <link to blog post>." ;
11
+ private static UNABLE_TO_MIGRATE_APP_ERROR = `The current application is not compatible with NativeScript CLI 6.0.
12
+ Use the \`tns migrate\` command to migrate the app dependencies to a form compatible with NativeScript 6.0.
13
+ Running this command will ${ MigrateController . COMMON_MIGRATE_MESSAGE } ` ;
14
+ private static MIGRATE_FINISH_MESSAGE = `The \`tns migrate\` command does ${ MigrateController . COMMON_MIGRATE_MESSAGE } ` ;
15
+
9
16
constructor (
10
17
protected $fs : IFileSystem ,
11
18
protected $platformCommandHelper : IPlatformCommandHelper ,
@@ -68,10 +75,17 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
68
75
{ packageName : "nativescript-cardview" , verifiedVersion : "3.2.0" } ,
69
76
{
70
77
packageName : "nativescript-unit-test-runner" , verifiedVersion : "0.6.4" ,
71
- shouldMigrateAction : ( projectData : IProjectData ) => this . hasDependency ( { packageName : "nativescript-unit-test-runner" , isDev : false } , projectData ) ,
78
+ shouldMigrateAction : async ( projectData : IProjectData ) => {
79
+ const dependency = { packageName : "nativescript-unit-test-runner" , verifiedVersion : "0.6.4" , isDev : false } ;
80
+ const result = this . hasDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ;
81
+ return result ;
82
+ } ,
72
83
migrateAction : this . migrateUnitTestRunner . bind ( this )
73
84
} ,
74
- { packageName : MigrateController . typescriptPackageName , isDev : true , getVerifiedVersion : this . getAngularTypeScriptVersion . bind ( this ) }
85
+ { packageName : MigrateController . typescriptPackageName , isDev : true , getVerifiedVersion : this . getAngularTypeScriptVersion . bind ( this ) } ,
86
+ { packageName : "nativescript-localize" , verifiedVersion : "4.2.0" } ,
87
+ { packageName : "nativescript-dev-babel" , verifiedVersion : "0.2.1" } ,
88
+ { packageName : "nativescript-nfc" , verifiedVersion : "4.0.1" }
75
89
] ;
76
90
77
91
get verifiedPlatformVersions ( ) : IDictionary < string > {
@@ -112,6 +126,8 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
112
126
this . restoreBackup ( MigrateController . folders , backupDir , projectData . projectDir ) ;
113
127
this . $errors . failWithoutHelp ( `${ MigrateController . migrateFailMessage } The error is: ${ error } ` ) ;
114
128
}
129
+
130
+ this . $logger . info ( MigrateController . MIGRATE_FINISH_MESSAGE ) ;
115
131
}
116
132
117
133
public async shouldMigrate ( { projectDir } : IProjectDir ) : Promise < boolean > {
@@ -121,7 +137,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
121
137
const dependency = this . migrationDependencies [ i ] ;
122
138
const hasDependency = this . hasDependency ( dependency , projectData ) ;
123
139
124
- if ( hasDependency && dependency . shouldMigrateAction && dependency . shouldMigrateAction ( projectData ) ) {
140
+ if ( hasDependency && dependency . shouldMigrateAction && await dependency . shouldMigrateAction ( projectData ) ) {
125
141
return true ;
126
142
}
127
143
@@ -136,20 +152,27 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
136
152
if ( ! hasDependency && dependency . shouldAddIfMissing ) {
137
153
return true ;
138
154
}
155
+ }
139
156
140
- if ( ! this . $androidResourcesMigrationService . hasMigrated ( projectData . getAppResourcesDirectoryPath ( ) ) ) {
141
- return true ;
142
- }
157
+ if ( ! this . $androidResourcesMigrationService . hasMigrated ( projectData . getAppResourcesDirectoryPath ( ) ) ) {
158
+ return true ;
143
159
}
144
160
145
161
for ( const platform in this . $devicePlatformsConstants ) {
146
162
const hasRuntimeDependency = this . hasRuntimeDependency ( { platform, projectData } ) ;
147
- if ( ! hasRuntimeDependency || await this . shouldUpdateRuntimeVersion ( { targetVersion : this . verifiedPlatformVersions [ platform . toLowerCase ( ) ] , platform, projectData } ) ) {
163
+ if ( hasRuntimeDependency && await this . shouldUpdateRuntimeVersion ( { targetVersion : this . verifiedPlatformVersions [ platform . toLowerCase ( ) ] , platform, projectData } ) ) {
148
164
return true ;
149
165
}
150
166
}
151
167
}
152
168
169
+ public async validate ( { projectDir } : IProjectDir ) : Promise < void > {
170
+ const shouldMigrate = await this . shouldMigrate ( { projectDir } ) ;
171
+ if ( shouldMigrate ) {
172
+ this . $errors . failWithoutHelp ( MigrateController . UNABLE_TO_MIGRATE_APP_ERROR ) ;
173
+ }
174
+ }
175
+
153
176
private async getAngularTypeScriptVersion ( projectData : IProjectData ) : Promise < string > {
154
177
let verifiedVersion = "3.4.1" ;
155
178
try {
@@ -254,7 +277,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
254
277
const dependency = this . migrationDependencies [ i ] ;
255
278
const hasDependency = this . hasDependency ( dependency , projectData ) ;
256
279
257
- if ( hasDependency && dependency . migrateAction && dependency . shouldMigrateAction ( projectData ) ) {
280
+ if ( hasDependency && dependency . migrateAction && await dependency . shouldMigrateAction ( projectData ) ) {
258
281
const newDependencies = await dependency . migrateAction ( projectData , path . join ( projectData . projectDir , MigrateController . backupFolder ) ) ;
259
282
for ( const newDependency of newDependencies ) {
260
283
await this . migrateDependency ( newDependency , projectData ) ;
@@ -267,7 +290,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
267
290
for ( const platform in this . $devicePlatformsConstants ) {
268
291
const lowercasePlatform = platform . toLowerCase ( ) ;
269
292
const hasRuntimeDependency = this . hasRuntimeDependency ( { platform, projectData } ) ;
270
- if ( ! hasRuntimeDependency || await this . shouldUpdateRuntimeVersion ( { targetVersion : this . verifiedPlatformVersions [ lowercasePlatform ] , platform, projectData } ) ) {
293
+ if ( hasRuntimeDependency && await this . shouldUpdateRuntimeVersion ( { targetVersion : this . verifiedPlatformVersions [ lowercasePlatform ] , platform, projectData } ) ) {
271
294
const verifiedPlatformVersion = this . verifiedPlatformVersions [ lowercasePlatform ] ;
272
295
const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
273
296
this . $logger . info ( `Updating ${ platform } platform to version '${ verifiedPlatformVersion } '.` ) ;
0 commit comments