Skip to content

Commit df0684e

Browse files
committed
Merge branch 'release/3.2.11'
2 parents a0822d9 + f3a4e91 commit df0684e

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-rename",
3-
"version": "3.2.10",
3+
"version": "3.2.11",
44
"description": "Rename react-native app with just one command",
55
"main": "lib/index.js",
66
"scripts": {

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ program
6666
}
6767

6868
if (newBundleID) {
69-
validateNewBundleID(newBundleID);
69+
validateNewBundleID(newBundleID, ['ios', 'android']);
7070
}
7171

7272
if (newIosBundleID) {
73-
validateNewBundleID(newIosBundleID);
73+
validateNewBundleID(newIosBundleID, ['ios']);
7474
}
7575

7676
if (newAndroidBundleID) {
77-
validateNewBundleID(newAndroidBundleID);
77+
validateNewBundleID(newAndroidBundleID, ['android']);
7878
}
7979

8080
const currentAndroidName = getAndroidCurrentName();

src/utils.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const PROMISE_DELAY = 200;
3333
const MAX_NAME_LENGTH = 30;
3434
const NON_LANGUAGE_ALPHANUMERIC_REGEX = /[^\p{L}\p{N}]+/gu;
3535
const MIN_LANGUAGE_ALPHANUMERIC_NAME_LENGTH = 4;
36-
const VALID_BUNDLE_ID_REGEX = /^([a-zA-Z]([a-zA-Z0-9_])*\.)+[a-zA-Z]([a-zA-Z0-9_])*$/u;
36+
const VALID_ANDROID_BUNDLE_ID_REGEX = /^[a-zA-Z]{1}[a-zA-Z0-9\.]{1,}$/;
37+
const VALID_IOS_BUNDLE_ID_REGEX = /^[a-zA-Z]{1}[a-zA-Z0-9\.\-]{1,}$/;
3738

3839
const pluralize = (count, noun, suffix = 'es') => `${count} ${noun}${count !== 1 ? suffix : ''}`;
3940
const 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

Comments
 (0)