Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the CLI recognize CRNA projects #15139

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions local-cli/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const getDependencyConfig = require('./getDependencyConfig');
const pollParams = require('./pollParams');
const commandStub = require('./commandStub');
const promisify = require('./promisify');
const findReactNativeScripts = require('../util/findReactNativeScripts');

import type {RNConfig} from '../core';

Expand Down Expand Up @@ -147,6 +148,16 @@ function link(args: Array<string>, config: RNConfig) {
return Promise.reject(err);
}

if (!project.android && !project.ios && !project.windows && findReactNativeScripts()) {
throw new Error(
'`react-native link` can not be used in Create React Native App projects. ' +
'If you need to include a library that relies on custom native code, ' +
'you might have to eject first. ' +
'See https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md ' +
'for more information.'
);
}

let packageName = args[0];
// Check if install package by specific version (eg. package@latest)
if (packageName !== undefined) {
Expand Down
12 changes: 11 additions & 1 deletion local-cli/runAndroid/runAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const chalk = require('chalk');
const child_process = require('child_process');
const fs = require('fs');
const isPackagerRunning = require('../util/isPackagerRunning');
const findReactNativeScripts = require('../util/findReactNativeScripts');
const isString = require('lodash/isString');
const path = require('path');
const Promise = require('promise');
Expand All @@ -27,7 +28,16 @@ function checkAndroid(root) {
*/
function runAndroid(argv, config, args) {
if (!checkAndroid(args.root)) {
console.log(chalk.red('Android project not found. Maybe run react-native android first?'));
const reactNativeScriptsPath = findReactNativeScripts();
if (reactNativeScriptsPath) {
child_process.spawnSync(
reactNativeScriptsPath,
['android'].concat(process.argv.slice(1)),
{stdio: 'inherit'}
);
} else {
console.log(chalk.red('Android project not found. Maybe run react-native android first?'));
}
return;
}

Expand Down
14 changes: 14 additions & 0 deletions local-cli/runIOS/runIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ const child_process = require('child_process');
const fs = require('fs');
const path = require('path');
const findXcodeProject = require('./findXcodeProject');
const findReactNativeScripts = require('../util/findReactNativeScripts');
const parseIOSDevicesList = require('./parseIOSDevicesList');
const findMatchingSimulator = require('./findMatchingSimulator');
const getBuildPath = function(configuration = 'Debug', appName, isDevice) {
return `build/Build/Products/${configuration}-${isDevice ? 'iphoneos' : 'iphonesimulator'}/${appName}.app`;
};

function runIOS(argv, config, args) {
if (!fs.existsSync(args.projectPath)) {
const reactNativeScriptsPath = findReactNativeScripts();
if (reactNativeScriptsPath) {
child_process.spawnSync(
reactNativeScriptsPath,
['ios'].concat(process.argv.slice(1)),
{stdio: 'inherit'}
);
return;
} else {
throw new Error('iOS project folder not found. Are you sure this is a React Native project?');
}
}
process.chdir(args.projectPath);
const xcodeProject = findXcodeProject(fs.readdirSync('.'));
if (!xcodeProject) {
Expand Down
28 changes: 28 additions & 0 deletions local-cli/util/findReactNativeScripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';

const path = require('path');
const fs = require('fs');

function findReactNativeScripts(): ?string {
const executablePath = path.resolve(
'node_modules',
'.bin',
'react-native-scripts'
);
if (fs.existsSync(executablePath)) {
return executablePath;
}
return null;
}

module.exports = findReactNativeScripts;