@@ -11,7 +11,7 @@ import * as _ from "lodash";
1111export class AndroidToolsInfo implements NativeScriptDoctor . IAndroidToolsInfo {
1212 public readonly ANDROID_TARGET_PREFIX = "android" ;
1313 public getSupportedTargets ( projectDir : string ) {
14- const runtimeVersion = this . getRuntimeVersion ( { projectDir} ) ;
14+ const runtimeVersion = this . getRuntimeVersion ( { projectDir } ) ;
1515 let baseTargets = [
1616 "android-17" ,
1717 "android-18" ,
@@ -126,7 +126,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
126126 if ( semver . lt ( installedJavaCompilerSemverVersion , AndroidToolsInfo . MIN_JAVA_VERSION ) || semver . gte ( installedJavaCompilerSemverVersion , AndroidToolsInfo . MAX_JAVA_VERSION ) ) {
127127 warning = `Javac version ${ installedJavaCompilerVersion } is not supported. You have to install at least ${ AndroidToolsInfo . MIN_JAVA_VERSION } and below ${ AndroidToolsInfo . MAX_JAVA_VERSION } .` ;
128128 } else {
129- runtimeVersion = this . getRuntimeVersion ( { runtimeVersion, projectDir} ) ;
129+ runtimeVersion = this . getRuntimeVersion ( { runtimeVersion, projectDir } ) ;
130130 if ( runtimeVersion ) {
131131 // get the item from the dictionary that corresponds to our current Javac version:
132132 let runtimeMinVersion : string = null ;
@@ -200,7 +200,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
200200 return errors ;
201201 }
202202
203- public validateMinSupportedTargetSdk ( { targetSdk, projectDir} : NativeScriptDoctor . ITargetValidationOptions ) : NativeScriptDoctor . IWarning [ ] {
203+ public validateMinSupportedTargetSdk ( { targetSdk, projectDir } : NativeScriptDoctor . ITargetValidationOptions ) : NativeScriptDoctor . IWarning [ ] {
204204 const errors : NativeScriptDoctor . IWarning [ ] = [ ] ;
205205 const newTarget = `${ this . ANDROID_TARGET_PREFIX } -${ targetSdk } ` ;
206206 const supportedTargets = this . getSupportedTargets ( projectDir ) ;
@@ -212,7 +212,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
212212
213213 if ( ! targetSupported && targetSdk && ( targetSdk < minSupportedVersion ) ) {
214214 errors . push ( {
215- warning :`The selected Android target SDK ${ newTarget } is not supported. You must target ${ minSupportedVersion } or later.` ,
215+ warning : `The selected Android target SDK ${ newTarget } is not supported. You must target ${ minSupportedVersion } or later.` ,
216216 additionalInformation : "" ,
217217 platforms : [ Constants . ANDROID_PLATFORM_NAME ]
218218 } ) ;
@@ -222,14 +222,14 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
222222 return errors ;
223223 }
224224
225- public validataMaxSupportedTargetSdk ( { targetSdk, projectDir} : NativeScriptDoctor . ITargetValidationOptions ) : NativeScriptDoctor . IWarning [ ] {
225+ public validataMaxSupportedTargetSdk ( { targetSdk, projectDir } : NativeScriptDoctor . ITargetValidationOptions ) : NativeScriptDoctor . IWarning [ ] {
226226 const errors : NativeScriptDoctor . IWarning [ ] = [ ] ;
227227 const newTarget = `${ this . ANDROID_TARGET_PREFIX } -${ targetSdk } ` ;
228228 const targetSupported = _ . includes ( this . getSupportedTargets ( projectDir ) , newTarget ) ;
229229
230230 if ( ! targetSupported && ! targetSdk || targetSdk > this . getMaxSupportedVersion ( projectDir ) ) {
231231 errors . push ( {
232- warning :`Support for the selected Android target SDK ${ newTarget } is not verified. Your Android app might not work as expected.` ,
232+ warning : `Support for the selected Android target SDK ${ newTarget } is not verified. Your Android app might not work as expected.` ,
233233 additionalInformation : "" ,
234234 platforms : [ Constants . ANDROID_PLATFORM_NAME ]
235235 } ) ;
@@ -369,68 +369,68 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
369369
370370 private getAndroidRuntimePackageFromProjectDir ( projectDir : string ) : { name : string , version : string } {
371371 if ( ! projectDir || ! this . fs . exists ( projectDir ) ) {
372- return null
373- }
372+ return null ;
373+ }
374374 const pathToPackageJson = path . join ( projectDir , Constants . PACKAGE_JSON ) ;
375375
376- if ( ! this . fs . exists ( pathToPackageJson ) ) {
377- return null
378- }
376+ if ( ! this . fs . exists ( pathToPackageJson ) ) {
377+ return null ;
378+ }
379379
380- const content = this . fs . readJson < INativeScriptProjectPackageJson > ( pathToPackageJson ) ;
380+ const content = this . fs . readJson < INativeScriptProjectPackageJson > ( pathToPackageJson ) ;
381381
382- if ( ! content ) {
383- return null
384- }
382+ if ( ! content ) {
383+ return null ;
384+ }
385385
386386 // in case we have a nativescript key and a runtime with a version
387- // we are dealing with a legacy project and should respect the values
388- // in the nativescript key
389- if ( content && content . nativescript && content . nativescript [ 'tns-android' ] && content . nativescript [ 'tns-android' ] . version ) {
390- return {
391- name : Constants . ANDROID_OLD_RUNTIME ,
392- version : content . nativescript && content . nativescript [ 'tns-android' ] && content . nativescript [ 'tns-android' ] . version
393- } ;
394- }
395-
396- if ( content && content . devDependencies ) {
397- const foundRuntime = Object . keys ( content . devDependencies ) . find ( depName => {
398- return depName === Constants . ANDROID_SCOPED_RUNTIME || depName === Constants . ANDROID_OLD_RUNTIME
399- } )
400-
401- if ( foundRuntime ) {
402- let version = content . devDependencies [ foundRuntime ]
403-
404- if ( version . includes ( 'tgz' ) ) {
405- try {
406- const packagePath = require . resolve ( `${ foundRuntime } /package.json` , {
407- paths : [ projectDir ]
408- } )
409- version = require ( packagePath ) . version ;
410- } catch ( err ) {
411- version = '*' ;
412- }
413- }
414-
415- return {
416- name : foundRuntime ,
417- version
418- }
419- }
420- }
421-
422- return null
387+ // we are dealing with a legacy project and should respect the values
388+ // in the nativescript key
389+ if ( content && content . nativescript && content . nativescript [ 'tns-android' ] && content . nativescript [ 'tns-android' ] . version ) {
390+ return {
391+ name : Constants . ANDROID_OLD_RUNTIME ,
392+ version : content . nativescript && content . nativescript [ 'tns-android' ] && content . nativescript [ 'tns-android' ] . version
393+ } ;
394+ }
395+
396+ if ( content && content . devDependencies ) {
397+ const foundRuntime = Object . keys ( content . devDependencies ) . find ( depName => {
398+ return depName === Constants . ANDROID_SCOPED_RUNTIME || depName === Constants . ANDROID_OLD_RUNTIME ;
399+ } ) ;
400+
401+ if ( foundRuntime ) {
402+ let version = content . devDependencies [ foundRuntime ] ;
403+
404+ if ( version . includes ( 'tgz' ) ) {
405+ try {
406+ const packagePath = require . resolve ( `${ foundRuntime } /package.json` , {
407+ paths : [ projectDir ]
408+ } ) ;
409+ version = require ( packagePath ) . version ;
410+ } catch ( err ) {
411+ version = '*' ;
412+ }
413+ }
414+
415+ return {
416+ name : foundRuntime ,
417+ version
418+ } ;
419+ }
420+ }
421+
422+ return null ;
423423 }
424424
425- private getRuntimeVersion ( { runtimeVersion, projectDir } : { runtimeVersion ?: string , projectDir ?: string } ) : string {
426- let runtimePackage = {
427- name : Constants . ANDROID_SCOPED_RUNTIME ,
428- version : runtimeVersion
429- }
430- if ( ! runtimeVersion ) {
431- runtimePackage = this . getAndroidRuntimePackageFromProjectDir ( projectDir )
432- runtimeVersion = runtimePackage ? .version ;
433- }
425+ private getRuntimeVersion ( { runtimeVersion, projectDir } : { runtimeVersion ?: string , projectDir ?: string } ) : string {
426+ let runtimePackage = {
427+ name : Constants . ANDROID_SCOPED_RUNTIME ,
428+ version : runtimeVersion
429+ } ;
430+ if ( ! runtimeVersion ) {
431+ runtimePackage = this . getAndroidRuntimePackageFromProjectDir ( projectDir ) ;
432+ runtimeVersion = runtimePackage && runtimePackage . version ;
433+ }
434434
435435 if ( runtimeVersion ) {
436436 // Check if the version is not "next" or "rc", i.e. tag from npm
@@ -454,7 +454,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
454454 return runtimeVersion ;
455455 }
456456
457- private getMaxSupportedCompileVersion ( config : Partial < NativeScriptDoctor . IProjectDir > & { runtimeVersion ?: string } ) : number {
457+ private getMaxSupportedCompileVersion ( config : Partial < NativeScriptDoctor . IProjectDir > & { runtimeVersion ?: string } ) : number {
458458 if ( config . runtimeVersion && semver . lt ( semver . coerce ( config . runtimeVersion ) , "6.1.0" ) ) {
459459 return 28 ;
460460 }
0 commit comments