@@ -33,7 +33,8 @@ const PROMISE_DELAY = 200;
3333const MAX_NAME_LENGTH = 30 ;
3434const NON_LANGUAGE_ALPHANUMERIC_REGEX = / [ ^ \p{ L} \p{ N} ] + / gu;
3535const MIN_LANGUAGE_ALPHANUMERIC_NAME_LENGTH = 4 ;
36- const VALID_BUNDLE_ID_REGEX = / ^ ( [ a - z A - Z ] ( [ a - z A - Z 0 - 9 _ ] ) * \. ) + [ a - z A - Z ] ( [ a - z A - Z 0 - 9 _ ] ) * $ / u;
36+ const VALID_ANDROID_BUNDLE_ID_REGEX = / ^ [ a - z A - Z ] { 1 } [ a - z A - Z 0 - 9 \. ] { 1 , } $ / ;
37+ const VALID_IOS_BUNDLE_ID_REGEX = / ^ [ a - z A - Z ] { 1 } [ a - z A - Z 0 - 9 \. \- ] { 1 , } $ / ;
3738
3839const pluralize = ( count , noun , suffix = 'es' ) => `${ count } ${ noun } ${ count !== 1 ? suffix : '' } ` ;
3940const delay = ms => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
@@ -114,11 +115,39 @@ export const validateNewPathContentStr = value => {
114115 }
115116} ;
116117
117- export const validateNewBundleID = newBundleID => {
118- if ( ! VALID_BUNDLE_ID_REGEX . test ( newBundleID ) ) {
119- console . log (
120- `The bundle identifier "${ newBundleID } " is not valid. It should contain only alphanumeric characters and dots, e.g. com.example.app or com.example`
121- ) ;
118+ export const validateNewBundleID = ( newBundleID , platforms = [ ] ) => {
119+ const isIosBundleIdValid = VALID_IOS_BUNDLE_ID_REGEX . test ( newBundleID ) ;
120+ const isAndroidBundleIdValid = VALID_ANDROID_BUNDLE_ID_REGEX . test ( newBundleID ) ;
121+ const androidErrorMessage = `The bundle identifier "${ newBundleID } " for ${ chalk . bold (
122+ 'Android'
123+ ) } is not valid. It should contain only alphanumeric characters and dots.`;
124+ const iosErrorMessage = `The bundle identifier "${ newBundleID } " for ${ chalk . bold (
125+ 'iOS'
126+ ) } is not valid. It should contain only alphanumeric characters, dots and dashes.`;
127+ const additionalMessage =
128+ '\nNote: You can also specify a custom bundle identifier for each platform using "--iosBundleID [value]" and "--androidBundleID [value]" options.' ;
129+ const errorMessage = `${ androidErrorMessage } \n${ iosErrorMessage } ` ;
130+
131+ if (
132+ platforms . includes ( 'ios' ) &&
133+ platforms . includes ( 'android' ) &&
134+ ! isIosBundleIdValid &&
135+ ! isAndroidBundleIdValid
136+ ) {
137+ console . log ( errorMessage ) ;
138+ console . log ( chalk . yellow ( additionalMessage ) ) ;
139+ process . exit ( ) ;
140+ }
141+
142+ if ( platforms . includes ( 'ios' ) && ! isIosBundleIdValid ) {
143+ console . log ( iosErrorMessage ) ;
144+ console . log ( chalk . yellow ( additionalMessage ) ) ;
145+ process . exit ( ) ;
146+ }
147+
148+ if ( platforms . includes ( 'android' ) && ! isAndroidBundleIdValid ) {
149+ console . log ( androidErrorMessage ) ;
150+ console . log ( chalk . yellow ( additionalMessage ) ) ;
122151 process . exit ( ) ;
123152 }
124153
0 commit comments