Skip to content

Commit

Permalink
Merge branch 'release/3.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
junedomingo committed Dec 28, 2022
2 parents ad3412d + cc07e1c commit 27a37ce
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ npx react-native-rename "Travel App" -b "com.junedomingo.travelapp"
### CLI Options
| Name | Description |
| :------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `-b` or `--bundleID` [value] | Set custom bundle identifier both ios and android eg. "com.example.app" or "com.example". |
| `-b` or `--bundleID` [value] | Set custom bundle identifier for both ios and android eg. "com.example.app" or "com.example". |
| `--iosBundleID` [value] | Set custom bundle identifier specifically for ios. |
| `--androidBundleID` [value] | Set custom bundle identifier specifically for android. |
| `-p` or `--pathContentStr` [value] | Path and content string that can be used in replacing folders, files and their content. Make sure it doesn't include any special characters. |
Expand Down
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.1.0",
"version": "3.1.1",
"description": "Rename react-native app with just one command",
"main": "lib/index.js",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ program
.arguments('[newName]')
.option(
'-b, --bundleID [value]',
'Set custom bundle identifier eg. "com.example.app" or "com.example"'
'Set custom bundle identifier for both ios and android eg. "com.example.app" or "com.example".'
)
.option('--iosBundleID [value]', 'Set custom bundle identifier specifically for ios')
.option('--androidBundleID [value]', 'Set custom bundle identifier specifically for android')
Expand Down Expand Up @@ -115,7 +115,14 @@ program
}

await updateAndroidNameInStringsXml(newName);
await updateOtherFilesContent({ newName, newPathContentStr });
await updateOtherFilesContent({
newName,
currentPathContentStr,
newPathContentStr,
currentIosName,
newAndroidBundleID: newAndroidBundleID || newBundleID,
newIosBundleID: newIosBundleID || newBundleID,
});

cleanBuilds();
showSuccessMessages(newName);
Expand Down
57 changes: 42 additions & 15 deletions src/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ export const getIosUpdateFilesContentOptions = ({

// IMPORTANT: "files:" value should be in array even if there is only one file
return [
{
files: ['index.ios.js'],
from: [new RegExp(`\\b${currentName}\\b`, 'g'), new RegExp(`\\b'${currentName}'\\b`, 'g')],
to: newName,
},
{
files: ['ios/Podfile'],
from: [
Expand Down Expand Up @@ -188,7 +183,7 @@ export const getAndroidUpdateFilesContentOptions = ({
newName,
newBundleIDAsPath,
}) => {
const modulesName = cleanString(newName).toLowerCase();
const newModulesName = cleanString(newName).toLowerCase();

return [
{
Expand All @@ -212,17 +207,27 @@ export const getAndroidUpdateFilesContentOptions = ({
`android/app/src/main/java/${newBundleIDAsPath}/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java`,
],
from: /SoLoader\.loadLibrary\("(.*)"\)/g,
to: `SoLoader.loadLibrary("${modulesName}_appmodules")`,
to: `SoLoader.loadLibrary("${newModulesName}_appmodules")`,
},
{
files: ['android/app/src/main/jni/CMakeLists.txt'],
from: /project\((.*)\)/g,
to: `project(${modulesName}_appmodules)`,
to: `project(${newModulesName}_appmodules)`,
},
{
files: ['android/app/build.gradle'],
from: /targets \"(.*)_appmodules\"/,
to: `targets "${newModulesName}_appmodules"`,
},
{
files: ['android/app/src/main/jni/Android.mk'],
from: /LOCAL_MODULE \:\= (.*)_appmodules/,
to: `LOCAL_MODULE := ${newModulesName}_appmodules`,
},
{
files: ['android/.idea/workspace.xml'],
from: [/<module name="(.*)\.app\.main" \/>/, new RegExp(currentName, 'g')],
to: [`<module name="${modulesName}.app.main" />`, newName],
to: [`<module name="${newModulesName}.app.main" />`, newName],
},
];
};
Expand All @@ -237,6 +242,7 @@ export const getAndroidUpdateBundleIDOptions = ({
{
files: [
'android/app/_BUCK',
'android/app/BUCK',
'android/app/build.gradle',
`android/app/src/debug/java/${newBundleIDAsPath}/ReactNativeFlipper.java`,
`android/app/src/main/java/${newBundleIDAsPath}/MainActivity.java`,
Expand All @@ -259,8 +265,8 @@ export const getAndroidUpdateBundleIDOptions = ({
'android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h',
'android/app/src/main/jni/MainComponentsRegistry.h',
],
from: new RegExp(`L${currentBundleIDAsPath}`, 'g'),
to: `L${newBundleIDAsPath}`,
from: [new RegExp(`L${currentBundleIDAsPath}`, 'g'), new RegExp(`L${currentBundleID}`, 'g')],
to: [`L${newBundleIDAsPath}`, `L${newBundleID}`],
},
{
files: ['android/.idea/workspace.xml'],
Expand All @@ -276,22 +282,43 @@ export const getAndroidUpdateBundleIDOptions = ({
};

export const getOtherUpdateFilesContentOptions = ({
currentName,
newName,
currentPathContentStr,
newPathContentStr,
appJsonName,
appJsonDisplayName,
packageJsonName,
newAndroidBundleID,
newIosBundleID,
}) => {
return [
{
files: ['index.js', 'index.ios.js', 'index.android.js'],
from: [new RegExp(`\\b${currentName}\\b`, 'g'), new RegExp(`\\b'${currentName}'\\b`, 'g')],
to: newName,
},
{
files: ['package.json'],
from: [new RegExp(`${packageJsonName}`, 'gi')],
to: cleanString(newPathContentStr).toLowerCase(),
from: [new RegExp(`${packageJsonName}`, 'gi'), new RegExp(`${currentPathContentStr}`, 'gi')],
to: newPathContentStr,
},
{
files: ['app.json'],
from: [new RegExp(`${appJsonName}`, 'gi'), new RegExp(`${appJsonDisplayName}`, 'gi')],
to: newName,
from: [
new RegExp(`${appJsonName}`, 'gi'),
new RegExp(`${appJsonDisplayName}`, 'gi'),
/\"scheme\"\: \"(.*)\"/,
/\"package\"\: \"(.*)\"/,
/\"bundleIdentifier\"\: \"(.*)\"/,
],
to: [
newName,
newName,
`"scheme": "${newPathContentStr.toLowerCase()}"`,
`"package": "${newAndroidBundleID}"`,
`"bundleIdentifier": "${newIosBundleID}"`,
],
},
];
};
15 changes: 13 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const checkGitRepoStatus = () => {
if (!isClean) {
console.log(
`The directory is not clean. There are changes that have not been committed to the Git repository.
Clean it first and try again.`
Clean it first and try again or use "--skipGitStatusCheck" option to skip this check.`
);
process.exit();
}
Expand Down Expand Up @@ -346,16 +346,27 @@ export const updateAndroidFilesContentBundleID = async ({
await updateFilesContent(filesContentOptions);
};

export const updateOtherFilesContent = async ({ newName, newPathContentStr }) => {
export const updateOtherFilesContent = async ({
newName,
currentPathContentStr,
newPathContentStr,
currentIosName,
newAndroidBundleID,
newIosBundleID,
}) => {
const appJsonContent = JSON.parse(fs.readFileSync(path.join(APP_PATH, appJson), 'utf8'));
const packageJsonContent = JSON.parse(fs.readFileSync(path.join(APP_PATH, packageJson), 'utf8'));

const filesContentOptions = getOtherUpdateFilesContentOptions({
currentName: appJsonContent?.name || currentIosName,
newName,
currentPathContentStr,
newPathContentStr,
appJsonName: appJsonContent?.name,
appJsonDisplayName: appJsonContent?.displayName,
packageJsonName: packageJsonContent?.name,
newAndroidBundleID,
newIosBundleID,
});

await updateFilesContent(filesContentOptions);
Expand Down

0 comments on commit 27a37ce

Please sign in to comment.