Skip to content

Commit

Permalink
feat: support unlink --platforms (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored Jul 9, 2019
1 parent a3d468e commit f5d64fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/commands/install/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import type {ConfigT} from 'types';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import link from '../link/unlink';
import unlink from '../link/unlink';

async function uninstall(args: Array<string>, ctx: ConfigT) {
const name = args[0];

logger.info(`Unlinking "${name}"...`);
await link.func([name], ctx);
await unlink.func([name], ctx, {});

logger.info(`Uninstalling "${name}"...`);
await PackageManager.uninstall([name]);
Expand Down
37 changes: 30 additions & 7 deletions packages/cli/src/commands/link/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
* @flow
*/

import {flatMap, values, difference} from 'lodash';
import {flatMap, values, difference, pick} from 'lodash';
import {logger, CLIError} from '@react-native-community/cli-tools';
import type {ConfigT} from 'types';
import getPlatformName from './getPlatformName';
import makeHook from './makeHook';

type Flags = {
platforms?: Array<string>,
};

const unlinkDependency = (
platforms,
project,
Expand Down Expand Up @@ -78,8 +82,20 @@ const unlinkDependency = (
* If optional argument [packageName] is provided, it's the only one
* that's checked
*/
async function unlink(args: Array<string>, ctx: ConfigT) {
async function unlink(args: Array<string>, ctx: ConfigT, opts: Flags) {
const packageName = args[0];
let platforms = ctx.platforms;

if (opts.platforms) {
platforms = pick(platforms, opts.platforms);
logger.debug('Skipping selected platforms');
}

logger.debug(
`Available platforms: ${Object.keys(platforms)
.map(getPlatformName)
.join(', ')}`,
);

const {[packageName]: dependency, ...otherDependencies} = ctx.dependencies;

Expand All @@ -95,7 +111,7 @@ async function unlink(args: Array<string>, ctx: ConfigT) {
await makeHook(dependency.hooks.preulink)();
}
unlinkDependency(
ctx.platforms,
platforms,
ctx.project,
dependency,
packageName,
Expand All @@ -122,12 +138,12 @@ async function unlink(args: Array<string>, ctx: ConfigT) {
return;
}

Object.keys(ctx.platforms || {}).forEach(platform => {
Object.keys(platforms || {}).forEach(platform => {
const projectConfig = ctx.project[platform];
const linkConfig =
ctx.platforms[platform] &&
ctx.platforms[platform].linkConfig &&
ctx.platforms[platform].linkConfig();
platforms[platform] &&
platforms[platform].linkConfig &&
platforms[platform].linkConfig();
if (!linkConfig || !linkConfig.unlinkAssets || !projectConfig) {
return;
}
Expand All @@ -146,4 +162,11 @@ export default {
func: unlink,
description: 'unlink native dependency',
name: 'unlink <packageName>',
options: [
{
name: '--platforms [list]',
description: 'Scope unlinking to specified platforms',
parse: (val: string) => val.toLowerCase().split(','),
},
],
};

0 comments on commit f5d64fb

Please sign in to comment.