Skip to content

Commit

Permalink
feat: add logger to link command (#118)
Browse files Browse the repository at this point in the history
* feat: add logger to link command

* chore: simplify jest config

* fix: lint
  • Loading branch information
thymikee authored and Esemesek committed Jan 24, 2019
1 parent 1c18109 commit ec1e97d
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 45 deletions.
8 changes: 0 additions & 8 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
"url": "https://github.com/react-native-community/react-native-cli.git"
},
"jest": {
"displayName": "cli",
"testPathIgnorePatterns": [
"/node_modules/",
"/templates/"
],
"unmockedModulePathPatterns": [
"promise"
],
"testEnvironment": "node"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/link/__tests__/link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

jest.mock('chalk', () => ({ grey: str => str }));
jest.mock('npmlog');
jest.mock('../../util/logger');

const context = {
root: process.cwd(),
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/link/ios/createGroupWithMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* @format
*/

const log = require('npmlog');

const log = require('../../util/logger');
const createGroup = require('./createGroup');
const getGroup = require('./getGroup');

Expand All @@ -25,7 +24,6 @@ module.exports = function createGroupWithMessage(project, path) {
group = createGroup(project, path);

log.warn(
'ERRGROUP',
`Group '${path}' does not exist in your Xcode project. We have created it automatically for you.`
);
}
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/link/ios/unlinkAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
const fs = require('fs-extra');
const path = require('path');
const xcode = require('xcode');
const log = require('npmlog');
const { difference } = require('lodash');
const log = require('../../util/logger');

const groupFilesByType = require('../groupFilesByType');
const getPlist = require('./getPlist');
Expand All @@ -27,16 +27,14 @@ module.exports = function unlinkAssetsIOS(files, projectConfig) {

if (!plist) {
log.error(
'ERRPLIST',
"Could not locate Info.plist file. Check if your project has 'INFOPLIST_FILE' set properly"
'Could not locate "Info.plist" file. Check if your project has "INFOPLIST_FILE" set properly'
);
return;
}

if (!project.pbxGroupByName('Resources')) {
log.error(
'ERRGROUP',
"Group 'Resources' does not exist in your Xcode project. There is nothing to unlink."
'Group "Resources" does not exist in your Xcode project. There is nothing to unlink.'
);
return;
}
Expand Down
11 changes: 2 additions & 9 deletions packages/cli/src/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@

import type { ContextT } from '../core/types.flow';

const log = require('npmlog');
const { pick } = require('lodash');
const promiseWaterfall = require('./promiseWaterfall');
const log = require('../util/logger');
const getDependencyConfig = require('./getDependencyConfig');
const commandStub = require('./commandStub');
const promisify = require('./promisify');
const getProjectConfig = require('./getProjectConfig');
const linkDependency = require('./linkDependency');
const linkAssets = require('./linkAssets');
const linkAll = require('./linkAll');

const findReactNativeScripts = require('../util/findReactNativeScripts');

const getPlatforms = require('../core/getPlatforms');

log.heading = 'rnpm-link';

type FlagsType = {
platforms: Array<string>,
};
Expand All @@ -47,10 +43,7 @@ function link([rawPackageName]: Array<string>, ctx: ContextT, opts: FlagsType) {
}
project = getProjectConfig(ctx, platforms);
} catch (err) {
log.error(
'ERRPACKAGEJSON',
'No package found. Are you sure this is a React Native project?'
);
log.error('No package found. Are you sure this is a React Native project?');
return Promise.reject(err);
}
const hasProjectConfig = Object.keys(platforms).reduce(
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/link/linkAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import type { ContextT, PlatformsT, ProjectConfigT } from '../core/types.flow';

const log = require('npmlog');
const { uniqBy, flatten } = require('lodash');
const path = require('path');
const log = require('../util/logger');
const getAssets = require('../core/getAssets');
const getProjectDependencies = require('./getProjectDependencies');
const getDependencyConfig = require('./getDependencyConfig');
Expand All @@ -14,8 +14,6 @@ const promisify = require('./promisify');
const linkAssets = require('./linkAssets');
const linkDependency = require('./linkDependency');

log.heading = 'rnpm-link';

const dedupeAssets = assets => uniqBy(assets, asset => path.basename(asset));

function linkAll(
Expand All @@ -25,8 +23,8 @@ function linkAll(
) {
log.warn(
'Running `react-native link` without package name is deprecated and will be removed ' +
'in next release. If you are using `react-native link` to link your project assets, ' +
' let us know about your use case here: https://goo.gl/RKTeoc'
'in next release. If you use this command to link your project assets, ' +
'please let us know about your use case here: https://goo.gl/RKTeoc'
);

const projectAssets = getAssets(context.root);
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/link/linkAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import type { PlatformsT, ProjectConfigT } from '../core/types.flow';

const log = require('npmlog');
const { isEmpty } = require('lodash');

log.heading = 'rnpm-link';
const log = require('../util/logger');

const linkAssets = (
platforms: PlatformsT,
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/link/linkDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import type { PlatformsT, ProjectConfigT } from '../core/types.flow';

const log = require('npmlog');
const chalk = require('chalk');
const log = require('../util/logger');
const pollParams = require('./pollParams');

log.heading = 'rnpm-link';

const linkDependency = async (
platforms: PlatformsT,
project: ProjectConfigT,
Expand Down
12 changes: 4 additions & 8 deletions packages/cli/src/link/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

import type { ContextT } from '../core/types.flow';

const log = require('npmlog');

const { flatten, isEmpty, difference } = require('lodash');
const log = require('../util/logger');
const getProjectConfig = require('./getProjectConfig');
const getDependencyConfig = require('./getDependencyConfig');
const getProjectDependencies = require('./getProjectDependencies');
Expand All @@ -21,8 +20,6 @@ const promisify = require('./promisify');

const getPlatforms = require('../core/getPlatforms');

log.heading = 'rnpm-link';

const unlinkDependency = (
platforms,
project,
Expand Down Expand Up @@ -88,8 +85,7 @@ function unlink(args: Array<string>, ctx: ContextT) {
platforms = getPlatforms(ctx.root);
} catch (err) {
log.error(
'ERRPACKAGEJSON',
"No package found. Are you sure it's a React Native project?"
"No package.json found. Are you sure it's a React Native project?"
);
return Promise.reject(err);
}
Expand All @@ -110,7 +106,7 @@ function unlink(args: Array<string>, ctx: ContextT) {
otherDependencies = [...allDependencies];
dependency = otherDependencies.splice(idx, 1)[0]; // eslint-disable-line prefer-destructuring
} catch (err) {
log.warn('ERRINVALIDPROJ', err.message);
log.warn(err.message);
return Promise.reject(err);
}

Expand Down Expand Up @@ -162,7 +158,7 @@ function unlink(args: Array<string>, ctx: ContextT) {
})
.catch(err => {
log.error(
`It seems something went wrong while unlinking. Error: ${err.message}`
`It seems something went wrong while unlinking. Error:\n${err.message}`
);
throw err;
});
Expand Down

0 comments on commit ec1e97d

Please sign in to comment.