1
1
import * as path from "path" ;
2
2
import * as fs from "fs" ;
3
3
4
- module . exports = function ( hookArgs , $platformsData , $testExecutionService ) {
5
- const bundle = hookArgs && hookArgs . appFilesUpdaterOptions && hookArgs . appFilesUpdaterOptions . bundle ;
6
- if ( $testExecutionService && $testExecutionService . platform && ! bundle ) {
7
- let platformData = $platformsData . getPlatformData ( $testExecutionService . platform ) ,
8
- projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , "app" ) ,
9
- packageJsonPath = path . join ( projectFilesPath , 'package.json' ) ,
10
- packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath ) . toString ( ) ) ;
4
+ function isCLIVersionLowerThan6 ( $injector ) {
5
+ try {
6
+ const $staticConfig = $injector . resolve ( '$staticConfig' ) ;
7
+ const version = $staticConfig && $staticConfig . version ;
8
+ const majorVersion = ( version || '' ) . split ( '.' ) [ 0 ] ;
9
+ return ! majorVersion || + majorVersion < 6 ;
10
+ } catch ( err ) {
11
+ return false ;
12
+ }
13
+ }
14
+
15
+ module . exports = function ( hookArgs , $injector , $testExecutionService ) {
16
+ if ( isCLIVersionLowerThan6 ( $injector ) ) {
17
+ const bundle = hookArgs && hookArgs . appFilesUpdaterOptions && hookArgs . appFilesUpdaterOptions . bundle ;
18
+ if ( $testExecutionService && $testExecutionService . platform && ! bundle ) {
19
+ const $platformsData = $injector . resolve ( "platformsData" ) ;
20
+ let platformData = $platformsData . getPlatformData ( $testExecutionService . platform ) ,
21
+ projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , "app" ) ,
22
+ packageJsonPath = path . join ( projectFilesPath , 'package.json' ) ,
23
+ packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath ) . toString ( ) ) ;
11
24
12
- // When test command is used in ns-cli, we should change the entry point of the application
13
- packageJson . main = "./tns_modules/nativescript-unit-test-runner/app.js" ;
14
- fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson ) ) ;
25
+ // When test command is used in ns-cli, we should change the entry point of the application
26
+ packageJson . main = "./tns_modules/nativescript-unit-test-runner/app.js" ;
27
+ fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson ) ) ;
28
+ }
15
29
}
16
- }
30
+ }
0 commit comments