Skip to content

Commit

Permalink
Merge branch 'release/3.2.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
junedomingo committed Jan 26, 2023
2 parents a0822d9 + f3a4e91 commit df0684e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-rename",
"version": "3.2.10",
"version": "3.2.11",
"description": "Rename react-native app with just one command",
"main": "lib/index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ program
}

if (newBundleID) {
validateNewBundleID(newBundleID);
validateNewBundleID(newBundleID, ['ios', 'android']);
}

if (newIosBundleID) {
validateNewBundleID(newIosBundleID);
validateNewBundleID(newIosBundleID, ['ios']);
}

if (newAndroidBundleID) {
validateNewBundleID(newAndroidBundleID);
validateNewBundleID(newAndroidBundleID, ['android']);
}

const currentAndroidName = getAndroidCurrentName();
Expand Down
41 changes: 35 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const PROMISE_DELAY = 200;
const MAX_NAME_LENGTH = 30;
const NON_LANGUAGE_ALPHANUMERIC_REGEX = /[^\p{L}\p{N}]+/gu;
const MIN_LANGUAGE_ALPHANUMERIC_NAME_LENGTH = 4;
const VALID_BUNDLE_ID_REGEX = /^([a-zA-Z]([a-zA-Z0-9_])*\.)+[a-zA-Z]([a-zA-Z0-9_])*$/u;
const VALID_ANDROID_BUNDLE_ID_REGEX = /^[a-zA-Z]{1}[a-zA-Z0-9\.]{1,}$/;
const VALID_IOS_BUNDLE_ID_REGEX = /^[a-zA-Z]{1}[a-zA-Z0-9\.\-]{1,}$/;

const pluralize = (count, noun, suffix = 'es') => `${count} ${noun}${count !== 1 ? suffix : ''}`;
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
Expand Down Expand Up @@ -114,11 +115,39 @@ export const validateNewPathContentStr = value => {
}
};

export const validateNewBundleID = newBundleID => {
if (!VALID_BUNDLE_ID_REGEX.test(newBundleID)) {
console.log(
`The bundle identifier "${newBundleID}" is not valid. It should contain only alphanumeric characters and dots, e.g. com.example.app or com.example`
);
export const validateNewBundleID = (newBundleID, platforms = []) => {
const isIosBundleIdValid = VALID_IOS_BUNDLE_ID_REGEX.test(newBundleID);
const isAndroidBundleIdValid = VALID_ANDROID_BUNDLE_ID_REGEX.test(newBundleID);
const androidErrorMessage = `The bundle identifier "${newBundleID}" for ${chalk.bold(
'Android'
)} is not valid. It should contain only alphanumeric characters and dots.`;
const iosErrorMessage = `The bundle identifier "${newBundleID}" for ${chalk.bold(
'iOS'
)} is not valid. It should contain only alphanumeric characters, dots and dashes.`;
const additionalMessage =
'\nNote: You can also specify a custom bundle identifier for each platform using "--iosBundleID [value]" and "--androidBundleID [value]" options.';
const errorMessage = `${androidErrorMessage} \n${iosErrorMessage}`;

if (
platforms.includes('ios') &&
platforms.includes('android') &&
!isIosBundleIdValid &&
!isAndroidBundleIdValid
) {
console.log(errorMessage);
console.log(chalk.yellow(additionalMessage));
process.exit();
}

if (platforms.includes('ios') && !isIosBundleIdValid) {
console.log(iosErrorMessage);
console.log(chalk.yellow(additionalMessage));
process.exit();
}

if (platforms.includes('android') && !isAndroidBundleIdValid) {
console.log(androidErrorMessage);
console.log(chalk.yellow(additionalMessage));
process.exit();
}

Expand Down

0 comments on commit df0684e

Please sign in to comment.