Remove 'react-native link'

Summary:
`react-native link` was an early experiment, [rnpm](https://github.com/rnpm/rnpm) does this much better. After merging this PR we should merge rnpm so that `react-native link` works again :)

grabbou Kureev Just making some space here :)

This reverts 4e5a2bc079.

**Test Plan**

e2e tests on Travis and CircleCI
Closes https://github.com/facebook/react-native/pull/7290

Differential Revision: D3240702

Pulled By: mkonicek

fb-gh-sync-id: 6aac83fac599ba3db0dd0a7ac48653ebabd93491
fbshipit-source-id: 6aac83fac599ba3db0dd0a7ac48653ebabd93491
This commit is contained in:
Martin Konicek 2016-04-29 05:26:19 -07:00 committed by Facebook Github Bot 5
parent 3d0d426d46
commit 12caa363a1
2 changed files with 0 additions and 139 deletions

View File

@ -21,7 +21,6 @@ var defaultConfig = require('./default.config');
var dependencies = require('./dependencies/dependencies');
var generate = require('./generate/generate');
var library = require('./library/library');
var link = require('./library/link');
var path = require('path');
var Promise = require('promise');
var runAndroid = require('./runAndroid/runAndroid');
@ -44,7 +43,6 @@ var documentedCommands = {
'bundle': [bundle, 'builds the javascript bundle for offline use'],
'unbundle': [unbundle, 'builds javascript as "unbundle" for offline use'],
'new-library': [library, 'generates a native library bridge'],
'link': [link, 'Adds a third-party library to your project. Example: react-native link awesome-camera'],
'android': [generateWrapper, 'generates an Android project for your app'],
'run-android': [runAndroid, 'builds your app and starts it on a connected Android emulator or device'],
'run-ios': [runIOS, 'builds your app and starts it on iOS simulator'],

View File

@ -1,137 +0,0 @@
/**
* 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.
*/
'use strict';
const execSync = require('child_process').execSync;
const eol = require('os').EOL;
const fs = require('fs');
const Promise = require('promise');
/**
* Adds a third-party library to the current project.
*
* Usage:
* react-native link awesome-camera
* react-native link awesome-camera@0.2.0
*
* Does the following:
* npm install --save awesome-camera
* If the library contains native Android code, adds it to the build.
*/
function link(argv, config) {
return new Promise((resolve, reject) => {
try {
_link(argv, config);
} catch (e) {
reject(e);
return;
}
resolve();
});
}
function _link(argv, config) {
// argv examples:
// ['link', 'awesome-camera']
// ['link', 'awesome-camera@0.2']
if (argv.length !== 2) {
throw 'Please provide one argument (library to install).\n' +
'Usage example: react-native link awesome-camera';
}
const libraryAndVersion = argv[1];
const library = libraryAndVersion.split('@')[0];
_npmInstall(libraryAndVersion);
_maybeLinkAndroid(library);
}
function _npmInstall(library) {
const command = 'npm install --save ' + library;
console.log('Running ' + command);
try {
execSync(command);
} catch (e) {
throw command + ' failed';
}
}
/**
* If this library contains Android native code, add it to the build.
*/
function _maybeLinkAndroid(library) {
if (!_pathExists(`node_modules/${library}/android`)) {
return;
}
if (
(!_pathExists('android/settings.gradle')) ||
(!_pathExists('android/app/build.gradle'))) {
console.log('The library contains native Android code but this is not an ' +
'Android project, skipping.'
);
return;
}
if (!_pathExists(`node_modules/${library}/android/build.gradle`)) {
console.log('Looks like the Android library has incorrect format: ' +
'android/build.gradle is missing.'
);
return;
}
// Update settings.gradle
if (fs.readFileSync('android/settings.gradle', 'utf8').indexOf(`include ':${library}'`) !== -1) {
console.log('The library is already present in android/settings.gradle.');
} else {
fs.appendFileSync('android/settings.gradle',
`${eol}// ${library} dependency${eol}` +
`include ':${library}'${eol}` +
`project(':${library}').projectDir = ` +
`new File(rootProject.projectDir, '../node_modules/${library}/android')${eol}`
);
console.log('Updated android/settings.gradle');
}
// Update android/app/build.gradle
const build = fs.readFileSync('android/app/build.gradle', 'utf8');
if (build.indexOf(`compile project(":${library}")`) !== -1) {
console.log('The library is already present in android/app/build.gradle.');
} else {
const append = (
// Include sources
` compile project(":${library}")${eol}` +
// Include libs/*.jar
` compile fileTree(dir: "node_modules/${library}/android/libs", include: ["*.jar"])`
);
const buildWithDeps = build.replace(
/dependencies {([^}]*)}/g,
`dependencies {$1${eol}${append}${eol}}`
);
fs.writeFileSync('android/app/build.gradle', buildWithDeps, 'utf8');
console.log('Updated android/app/build.gradle');
}
// We could try to automate this as well.
// E.g. by convention the package name would end with Package.java.
console.log('Next step: add the library to your MainActivity.java by calling addPackage().\n' +
`Look for the package name in node_modules/${library}/android/src/main/java`
);
}
function _pathExists(path) {
try {
const stats = fs.statSync(path);
return stats.isFile() || stats.isDirectory();
} catch (e) {
if (e.code === 'ENOENT') {
return false;
}
throw e;
}
}
module.exports = link;