Skip to content

Commit

Permalink
Adjust rnpm link to colorize skipped linking steps
Browse files Browse the repository at this point in the history
Summary:
Sometimes when working with a team of developers, someone adds a library but does not link it. To identify if this required linking, you have to type react-native link and then read a wall of text to see if rnpm handled the issue. This can be sped up with a friendly logging level for previously linked messages.

Continuation of #9507

![image](https://cloud.githubusercontent.com/assets/997157/17908676/119884a2-6947-11e6-8297-818fefed26a0.png)

![image](https://cloud.githubusercontent.com/assets/997157/17908687/1bad1b56-6947-11e6-9cf5-b8eec1f2d6ef.png)
Closes #9551

Differential Revision: D3821468

Pulled By: bestander

fbshipit-source-id: 3e83bf46454519debdd95cf3d5e8561e3c77364a
  • Loading branch information
GantMan authored and Facebook Github Bot committed Sep 12, 2016
1 parent 406a1b3 commit db870f8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
33 changes: 33 additions & 0 deletions local-cli/__mocks__/chalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* 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 mockColor = () => {
return {
bold: () => { return { }; },
};
};

mockColor.bold = function() {
return {};
};

module.exports = {
dim: s => s,
magenta: mockColor,
white: mockColor,
blue: mockColor,
yellow: mockColor,
green: mockColor,
bold: mockColor,
red: mockColor,
cyan: mockColor,
gray: mockColor,
black: mockColor,
};
13 changes: 13 additions & 0 deletions local-cli/link/__tests__/link.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/**
* Copyright (c) 2013-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';

jest.autoMockOff();

const sinon = require('sinon');
const log = require('npmlog');
const path = require('path');
jest.setMock(
'chalk',
{ grey: (str) => str, }
);

describe('link', () => {
beforeEach(() => {
Expand Down
20 changes: 15 additions & 5 deletions local-cli/link/link.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/**
* Copyright (c) 2013-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.
*/

const log = require('npmlog');
const path = require('path');
const uniq = require('lodash').uniq;
const flatten = require('lodash').flatten;
const chalk = require('chalk');

const isEmpty = require('lodash').isEmpty;
const promiseWaterfall = require('./promiseWaterfall');
Expand Down Expand Up @@ -30,7 +40,7 @@ const linkDependencyAndroid = (androidProject, dependency) => {
const isInstalled = isInstalledAndroid(androidProject, dependency.name);

if (isInstalled) {
log.info(`Android module ${dependency.name} is already linked`);
log.info(chalk.grey(`Android module ${dependency.name} is already linked`));
return null;
}

Expand All @@ -56,7 +66,7 @@ const linkDependencyIOS = (iOSProject, dependency) => {
const isInstalled = isInstalledIOS(iOSProject, dependency.config.ios);

if (isInstalled) {
log.info(`iOS module ${dependency.name} is already linked`);
log.info(chalk.grey(`iOS module ${dependency.name} is already linked`));
return;
}

Expand All @@ -82,7 +92,7 @@ const linkAssets = (project, assets) => {
copyAssetsAndroid(assets, project.android.assetsPath);
}

log.info(`Assets have been successfully linked to your project`);
log.info('Assets have been successfully linked to your project');
};

/**
Expand Down Expand Up @@ -126,11 +136,11 @@ function link(args, config) {
return promiseWaterfall(tasks).catch(err => {
log.error(
`It seems something went wrong while linking. Error: ${err.message} \n`
+ `Please file an issue here: https://github.com/facebook/react-native/issues`
+ 'Please file an issue here: https://github.com/facebook/react-native/issues'
);
throw err;
});
};
}

module.exports = {
func: link,
Expand Down

1 comment on commit db870f8

@GantMan
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Special thanks to the FB team who helped get this PR through internals. @grabbou et al.

Please sign in to comment.