1
1
#!/usr/bin/env node
2
2
3
3
const spawn = require ( "child_process" ) . spawn ;
4
- const path = require ( "path" ) ;
4
+ const resolve = require ( "path" ) . resolve ;
5
5
6
- const PROJECT_DIR = path . resolve ( __dirname , "../../../" ) ;
6
+ const getPackageJson = require ( "../projectHelpers" ) . getPackageJson ;
7
+
8
+ const PROJECT_DIR = resolve ( __dirname , "../../../" ) ;
9
+ const packageJson = getPackageJson ( PROJECT_DIR ) ;
7
10
8
11
if ( ! process . env . npm_config_argv ) {
9
12
throwError ( { message : "No flags provided." } ) ;
@@ -14,6 +17,11 @@ const tnsArgs = getTnsArgs(npmArgs).map(escape);
14
17
const flags = npmArgs . filter ( a => a . startsWith ( "--" ) ) . map ( a => a . substring ( 2 ) ) ;
15
18
const options = getOptions ( flags ) ;
16
19
20
+ let platformVersion ;
21
+ try {
22
+ platformVersion = packageJson . nativescript [ `tns-${ options . platform } ` ] . version ;
23
+ } catch ( e ) { }
24
+
17
25
function getTnsArgs ( args ) {
18
26
const other = [
19
27
"run" ,
@@ -82,9 +90,10 @@ function removePlatform(platform) {
82
90
83
91
function addPlatform ( platform ) {
84
92
return new Promise ( function ( resolve , reject ) {
85
- console . log ( `Adding platform ${ platform } ...` ) ;
93
+ const platformToAdd = platformVersion ? `${ platform } @${ platformVersion } ` : platform ;
94
+ console . log ( `Adding platform ${ platformToAdd } ...` ) ;
86
95
87
- spawnChildProcess ( false , "tns" , "platform" , "add" , platform )
96
+ spawnChildProcess ( false , "tns" , "platform" , "add" , platformToAdd )
88
97
. then ( resolve )
89
98
. catch ( resolve ) ;
90
99
} ) ;
0 commit comments