File tree Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ const getDependencyConfig = require('./getDependencyConfig');
30
30
const pollParams = require ( './pollParams' ) ;
31
31
const commandStub = require ( './commandStub' ) ;
32
32
const promisify = require ( './promisify' ) ;
33
+ const findReactNativeScripts = require ( '../util/findReactNativeScripts' ) ;
33
34
34
35
import type { RNConfig } from '../core' ;
35
36
@@ -147,6 +148,16 @@ function link(args: Array<string>, config: RNConfig) {
147
148
return Promise . reject ( err ) ;
148
149
}
149
150
151
+ if ( ! project . android && ! project . ios && ! project . windows && findReactNativeScripts ( ) ) {
152
+ throw new Error (
153
+ '`react-native link` can not be used in Create React Native App projects. ' +
154
+ 'If you need to include a library that relies on custom native code, ' +
155
+ 'you might have to eject first. ' +
156
+ 'See https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md ' +
157
+ 'for more information.'
158
+ ) ;
159
+ }
160
+
150
161
let packageName = args [ 0 ] ;
151
162
// Check if install package by specific version (eg. package@latest)
152
163
if ( packageName !== undefined ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const chalk = require('chalk');
13
13
const child_process = require ( 'child_process' ) ;
14
14
const fs = require ( 'fs' ) ;
15
15
const isPackagerRunning = require ( '../util/isPackagerRunning' ) ;
16
+ const findReactNativeScripts = require ( '../util/findReactNativeScripts' ) ;
16
17
const isString = require ( 'lodash/isString' ) ;
17
18
const path = require ( 'path' ) ;
18
19
const Promise = require ( 'promise' ) ;
@@ -27,7 +28,16 @@ function checkAndroid(root) {
27
28
*/
28
29
function runAndroid ( argv , config , args ) {
29
30
if ( ! checkAndroid ( args . root ) ) {
30
- console . log ( chalk . red ( 'Android project not found. Maybe run react-native android first?' ) ) ;
31
+ const reactNativeScriptsPath = findReactNativeScripts ( ) ;
32
+ if ( reactNativeScriptsPath ) {
33
+ child_process . spawnSync (
34
+ reactNativeScriptsPath ,
35
+ [ 'android' ] . concat ( process . argv . slice ( 1 ) ) ,
36
+ { stdio : 'inherit' }
37
+ ) ;
38
+ } else {
39
+ console . log ( chalk . red ( 'Android project not found. Maybe run react-native android first?' ) ) ;
40
+ }
31
41
return ;
32
42
}
33
43
Original file line number Diff line number Diff line change @@ -12,13 +12,27 @@ const child_process = require('child_process');
12
12
const fs = require ( 'fs' ) ;
13
13
const path = require ( 'path' ) ;
14
14
const findXcodeProject = require ( './findXcodeProject' ) ;
15
+ const findReactNativeScripts = require ( '../util/findReactNativeScripts' ) ;
15
16
const parseIOSDevicesList = require ( './parseIOSDevicesList' ) ;
16
17
const findMatchingSimulator = require ( './findMatchingSimulator' ) ;
17
18
const getBuildPath = function ( configuration = 'Debug' , appName , isDevice ) {
18
19
return `build/Build/Products/${ configuration } -${ isDevice ? 'iphoneos' : 'iphonesimulator' } /${ appName } .app` ;
19
20
} ;
20
21
21
22
function runIOS ( argv , config , args ) {
23
+ if ( ! fs . existsSync ( args . projectPath ) ) {
24
+ const reactNativeScriptsPath = findReactNativeScripts ( ) ;
25
+ if ( reactNativeScriptsPath ) {
26
+ child_process . spawnSync (
27
+ reactNativeScriptsPath ,
28
+ [ 'ios' ] . concat ( process . argv . slice ( 1 ) ) ,
29
+ { stdio : 'inherit' }
30
+ ) ;
31
+ return ;
32
+ } else {
33
+ throw new Error ( 'iOS project folder not found. Are you sure this is a React Native project?' ) ;
34
+ }
35
+ }
22
36
process . chdir ( args . projectPath ) ;
23
37
const xcodeProject = findXcodeProject ( fs . readdirSync ( '.' ) ) ;
24
38
if ( ! xcodeProject ) {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @flow
10
+ */
11
+ 'use strict' ;
12
+
13
+ const path = require ( 'path' ) ;
14
+ const fs = require ( 'fs' ) ;
15
+
16
+ function findReactNativeScripts ( ) : ?string {
17
+ const executablePath = path . resolve (
18
+ 'node_modules' ,
19
+ '.bin' ,
20
+ 'react-native-scripts'
21
+ ) ;
22
+ if ( fs . existsSync ( executablePath ) ) {
23
+ return executablePath ;
24
+ }
25
+ return null ;
26
+ }
27
+
28
+ module . exports = findReactNativeScripts ;
You can’t perform that action at this time.
0 commit comments