File tree Expand file tree Collapse file tree 4 files changed +28
-18
lines changed
Expand file tree Collapse file tree 4 files changed +28
-18
lines changed Original file line number Diff line number Diff line change 3636 "chalk" : " ^2.4.2" ,
3737 "commander" : " ^2.20.0" ,
3838 "ora" : " ^3.4.0" ,
39- "prompt" : " ^1.0.0"
39+ "prompt" : " ^1.0.0" ,
40+ "semver-regex" : " ^3.1.0"
4041 }
4142}
Original file line number Diff line number Diff line change @@ -36,11 +36,16 @@ program
3636 ) ;
3737 }
3838 } else {
39- if ( ! validationObjects . getReactNativeCLIifAvailable ( ) ) {
39+ const reactNativeCLIVersion = validationObjects . getReactNativeCLIifAvailable ( ) ;
40+ if ( ! reactNativeCLIVersion ) {
4041 terminateTheProcess (
41- "Please globally install react-native-cli dependency "
42+ "Please globally install react-native-cli"
4243 ) ;
4344 return ;
45+ } else {
46+ console . log (
47+ chalk . cyan ( "Using globally installed react-native-cli " + reactNativeCLIVersion + "\n" ) ,
48+ ) ;
4449 }
4550 }
4651 const isProjectNameValidResponse = validationObjects . isProjectNameValid (
Original file line number Diff line number Diff line change 11const chalk = require ( "chalk" ) ;
22const execSync = require ( "child_process" ) . execSync ;
3+ const semverRegex = require ( 'semver-regex' ) ;
4+
35const constantObjects = require ( "./constants" ) ;
46
57function isProjectNameValidForCrna ( projectName ) {
@@ -73,26 +75,23 @@ function getCrnaVersionIfAvailable() {
7375}
7476
7577function getReactNativeCLIifAvailable ( ) {
76- let crnaVersion = null ;
77- try {
78+ // Get package version command and discard stderr on *nix systems
79+ const processCommand = process . platform . startsWith ( "win" )
80+ ? `${ constantObjects . rnPackageName } --version`
81+ : `${ constantObjects . rnPackageName } --version 2>/dev/null`
82+
83+ try {
7884 // execSync returns a Buffer -> convert to string
79- if ( process . platform . startsWith ( "win" ) ) {
80- crnaVersion = (
81- execSync ( `${ constantObjects . rnPackageName } --version` ) . toString ( ) ||
82- ""
83- ) . trim ( ) ;
84- } else {
85- crnaVersion = (
86- execSync (
87- `${ constantObjects . rnPackageName } --version 2>/dev/null`
88- ) . toString ( ) || ""
89- ) . trim ( ) ;
90- }
85+ const commandResult = ( execSync ( processCommand ) . toString ( ) || "" ) . trim ( ) ;
86+ const regexMatches = commandResult . match ( semverRegex ( ) ) ;
87+ const packageSemver = regexMatches . length > 0
88+ ? regexMatches [ 0 ] // longest first match
89+ : "" ;
90+ return packageSemver ;
9191 } catch ( error ) {
9292 console . log ( chalk . red ( "Error In Getting React Native Package Version" ) ) ;
9393 return null ;
9494 }
95- return crnaVersion ;
9695}
9796
9897module . exports = {
Original file line number Diff line number Diff line change @@ -288,6 +288,11 @@ rimraf@2.x.x:
288288 dependencies :
289289 glob "^7.1.3"
290290
291+ semver-regex@^3.1.0 :
292+ version "3.1.0"
293+ resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-3.1.0.tgz#23368cb577bf2668e78bf9c3e8e519fc029ca069"
294+ integrity sha512-xJqZonbAohJmpogzq1Mx7DB4DT3LO+sG5J4i/rcRyZ527dcUqsTVb5T0vM5gwOBf3KO0v7i94EpbdvwSukJyAQ==
295+
291296signal-exit@^3.0.2 :
292297 version "3.0.2"
293298 resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
You can’t perform that action at this time.
0 commit comments