@@ -3,33 +3,35 @@ const fs = require('fs/promises');
3
3
const path = require ( 'path' ) ;
4
4
const pc = require ( 'picocolors' ) ;
5
5
6
- // TODO: Improve wording (description, errors)
6
+ const log = {
7
+ error : ( text ) => console . log ( pc . red ( text ) ) ,
8
+ warning : ( text ) => console . log ( '⚠️ ' + pc . yellow ( text ) ) ,
9
+ } ;
7
10
8
11
module . exports = {
9
12
commands : [
10
13
{
11
14
name : 'setup-ios-permissions' ,
12
- description : 'No description ' ,
15
+ description : 'Update react-native-permissions to link additional permission handlers. ' ,
13
16
func : async ( ) => {
14
17
const explorer = await cosmiconfig ( 'iosPermissions' ) ;
15
18
const result = await explorer . search ( ) ;
16
19
17
20
if ( ! result ) {
18
- console . log ( pc . red ( 'No config detected' ) ) ;
21
+ log . error (
22
+ 'No config detected. In order to setup iOS permissions, you first need to add an "iosPermissions" array in your package.json.' ,
23
+ ) ;
24
+
19
25
process . exit ( 1 ) ;
20
26
}
21
27
22
28
const { config} = result ;
23
29
24
- if ( ! Array . isArray ( config ) ) {
25
- console . log ( pc . red ( 'Invalid config' ) ) ;
30
+ if ( ! Array . isArray ( config ) || config . length === 0 ) {
31
+ log . error ( 'Invalid "iosPermissions" config detected. It must be a non-empty array.' ) ;
26
32
process . exit ( 1 ) ;
27
33
}
28
34
29
- if ( config . length === 0 ) {
30
- console . log ( pc . yellow ( 'Empty config' ) ) ;
31
- }
32
-
33
35
const iosDirPath = path . join ( __dirname , 'ios' ) ;
34
36
const podspecPath = path . join ( __dirname , 'RNPermissions.podspec' ) ;
35
37
const iosDir = await fs . readdir ( iosDirPath , { withFileTypes : true } ) ;
@@ -45,7 +47,7 @@ module.exports = {
45
47
. map ( ( name ) => `"${ name } "` ) ;
46
48
47
49
if ( unknownPermissions . length > 0 ) {
48
- console . log ( pc . yellow ( `Unknown permissions: ${ unknownPermissions . join ( ', ' ) } ` ) ) ;
50
+ log . warning ( `Unknown iOS permissions: ${ unknownPermissions . join ( ', ' ) } ` ) ;
49
51
}
50
52
51
53
const sourceFiles = [
0 commit comments