@@ -6,6 +6,13 @@ import { UpdateControllerBase } from "./update-controller-base";
66import { fromWindowsRelativePathToUnix } from "../common/helpers" ;
77
88export 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+
916 constructor (
1017 protected $fs : IFileSystem ,
1118 protected $platformCommandHelper : IPlatformCommandHelper ,
@@ -68,10 +75,17 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
6875 { packageName : "nativescript-cardview" , verifiedVersion : "3.2.0" } ,
6976 {
7077 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+ } ,
7283 migrateAction : this . migrateUnitTestRunner . bind ( this )
7384 } ,
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" }
7589 ] ;
7690
7791 get verifiedPlatformVersions ( ) : IDictionary < string > {
@@ -112,6 +126,8 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
112126 this . restoreBackup ( MigrateController . folders , backupDir , projectData . projectDir ) ;
113127 this . $errors . failWithoutHelp ( `${ MigrateController . migrateFailMessage } The error is: ${ error } ` ) ;
114128 }
129+
130+ this . $logger . info ( MigrateController . MIGRATE_FINISH_MESSAGE ) ;
115131 }
116132
117133 public async shouldMigrate ( { projectDir } : IProjectDir ) : Promise < boolean > {
@@ -121,7 +137,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
121137 const dependency = this . migrationDependencies [ i ] ;
122138 const hasDependency = this . hasDependency ( dependency , projectData ) ;
123139
124- if ( hasDependency && dependency . shouldMigrateAction && dependency . shouldMigrateAction ( projectData ) ) {
140+ if ( hasDependency && dependency . shouldMigrateAction && await dependency . shouldMigrateAction ( projectData ) ) {
125141 return true ;
126142 }
127143
@@ -136,20 +152,27 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
136152 if ( ! hasDependency && dependency . shouldAddIfMissing ) {
137153 return true ;
138154 }
155+ }
139156
140- if ( ! this . $androidResourcesMigrationService . hasMigrated ( projectData . getAppResourcesDirectoryPath ( ) ) ) {
141- return true ;
142- }
157+ if ( ! this . $androidResourcesMigrationService . hasMigrated ( projectData . getAppResourcesDirectoryPath ( ) ) ) {
158+ return true ;
143159 }
144160
145161 for ( const platform in this . $devicePlatformsConstants ) {
146162 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 } ) ) {
148164 return true ;
149165 }
150166 }
151167 }
152168
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+
153176 private async getAngularTypeScriptVersion ( projectData : IProjectData ) : Promise < string > {
154177 let verifiedVersion = "3.4.1" ;
155178 try {
@@ -254,7 +277,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
254277 const dependency = this . migrationDependencies [ i ] ;
255278 const hasDependency = this . hasDependency ( dependency , projectData ) ;
256279
257- if ( hasDependency && dependency . migrateAction && dependency . shouldMigrateAction ( projectData ) ) {
280+ if ( hasDependency && dependency . migrateAction && await dependency . shouldMigrateAction ( projectData ) ) {
258281 const newDependencies = await dependency . migrateAction ( projectData , path . join ( projectData . projectDir , MigrateController . backupFolder ) ) ;
259282 for ( const newDependency of newDependencies ) {
260283 await this . migrateDependency ( newDependency , projectData ) ;
@@ -267,7 +290,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
267290 for ( const platform in this . $devicePlatformsConstants ) {
268291 const lowercasePlatform = platform . toLowerCase ( ) ;
269292 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 } ) ) {
271294 const verifiedPlatformVersion = this . verifiedPlatformVersions [ lowercasePlatform ] ;
272295 const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
273296 this . $logger . info ( `Updating ${ platform } platform to version '${ verifiedPlatformVersion } '.` ) ;
0 commit comments