7
7
* @flow
8
8
*/
9
9
10
- import { flatMap , values , difference } from 'lodash' ;
10
+ import { flatMap , values , difference , pick } from 'lodash' ;
11
11
import { logger , CLIError } from '@react-native-community/cli-tools' ;
12
12
import type { ConfigT } from 'types' ;
13
13
import getPlatformName from './getPlatformName' ;
14
14
import makeHook from './makeHook' ;
15
15
16
+ type Flags = {
17
+ platforms ?: Array < string > ,
18
+ } ;
19
+
16
20
const unlinkDependency = (
17
21
platforms ,
18
22
project ,
@@ -78,8 +82,20 @@ const unlinkDependency = (
78
82
* If optional argument [packageName] is provided, it's the only one
79
83
* that's checked
80
84
*/
81
- async function unlink ( args : Array < string > , ctx : ConfigT ) {
85
+ async function unlink ( args : Array < string > , ctx : ConfigT , opts : Flags ) {
82
86
const packageName = args [ 0 ] ;
87
+ let platforms = ctx . platforms ;
88
+
89
+ if ( opts . platforms ) {
90
+ platforms = pick ( platforms , opts . platforms ) ;
91
+ logger . debug ( 'Skipping selected platforms' ) ;
92
+ }
93
+
94
+ logger . debug (
95
+ `Available platforms: ${ Object . keys ( platforms )
96
+ . map ( getPlatformName )
97
+ . join ( ', ' ) } `,
98
+ ) ;
83
99
84
100
const { [ packageName ] : dependency , ...otherDependencies } = ctx . dependencies ;
85
101
@@ -95,7 +111,7 @@ async function unlink(args: Array<string>, ctx: ConfigT) {
95
111
await makeHook ( dependency . hooks . preulink ) ( ) ;
96
112
}
97
113
unlinkDependency (
98
- ctx . platforms ,
114
+ platforms ,
99
115
ctx . project ,
100
116
dependency ,
101
117
packageName ,
@@ -122,12 +138,12 @@ async function unlink(args: Array<string>, ctx: ConfigT) {
122
138
return ;
123
139
}
124
140
125
- Object . keys ( ctx . platforms || { } ) . forEach ( platform => {
141
+ Object . keys ( platforms || { } ) . forEach ( platform => {
126
142
const projectConfig = ctx . project [ platform ] ;
127
143
const linkConfig =
128
- ctx . platforms [ platform ] &&
129
- ctx . platforms [ platform ] . linkConfig &&
130
- ctx . platforms [ platform ] . linkConfig ( ) ;
144
+ platforms [ platform ] &&
145
+ platforms [ platform ] . linkConfig &&
146
+ platforms [ platform ] . linkConfig ( ) ;
131
147
if ( ! linkConfig || ! linkConfig . unlinkAssets || ! projectConfig ) {
132
148
return ;
133
149
}
@@ -146,4 +162,11 @@ export default {
146
162
func : unlink ,
147
163
description : 'unlink native dependency' ,
148
164
name : 'unlink <packageName>' ,
165
+ options : [
166
+ {
167
+ name : '--platforms [list]' ,
168
+ description : 'Scope unlinking to specified platforms' ,
169
+ parse : ( val : string ) => val . toLowerCase ( ) . split ( ',' ) ,
170
+ } ,
171
+ ] ,
149
172
} ;
0 commit comments