🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-native-rename

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-rename - npm Package Compare versions

Comparing version

to
1.0.5

199

lib/index.js

@@ -5,5 +5,4 @@ #!/usr/bin/env node --harmony

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/* eslint-disable no-console */
/* eslint-disable no-param-reassign */
var _templateObject = _taggedTemplateLiteral(['\n\t\t\t\t\t\t\tThe app_name value in ./android/app/src/main/res/values/strings.xml must be the same with ./ios/AppFolderName before renaming the app.\n\t\t\t\t\t\t\tex. ./ios/CoolApp ---> <string name="app_name">CoolApp</string>\n\t\t\t\t\t\t\tand try running the command again with you new app name.\n\t\t\t\t\t\t\tex. react-native-rename "Awesome App"\n\t\t\t\t\t\t'], ['\n\t\t\t\t\t\t\tThe app_name value in ./android/app/src/main/res/values/strings.xml must be the same with ./ios/AppFolderName before renaming the app.\n\t\t\t\t\t\t\tex. ./ios/CoolApp ---> <string name="app_name">CoolApp</string>\n\t\t\t\t\t\t\tand try running the command again with you new app name.\n\t\t\t\t\t\t\tex. react-native-rename "Awesome App"\n\t\t\t\t\t\t']);

@@ -30,2 +29,6 @@ var _cheerio = require('cheerio');

var _outdent = require('outdent');
var _outdent2 = _interopRequireDefault(_outdent);
var _commander = require('commander');

@@ -41,6 +44,9 @@

function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
/* eslint-disable no-console */
/* eslint-disable no-param-reassign */
var projectName = (0, _projectName2.default)();
projectName = projectName.replace(/\s/g, '');
var replaceOptions = {

@@ -52,36 +58,111 @@ recursive: true,

_fs2.default.readFile('./android/app/src/main/res/values/strings.xml', 'utf8', function (err, markup) {
if (err) return console.log(err);
var $ = _cheerio2.default.load(markup);
var appName = $('string[name=app_name]').text();
if (err === null) {
(function () {
var $ = _cheerio2.default.load(markup);
var currentAppName = $('string[name=app_name]').text();
var nS_CurrentAppName = currentAppName.replace(/\s/g, '');
var lC_Ns_CurrentAppName = nS_CurrentAppName.toLowerCase();
_commander2.default.version('1.0.4').arguments('<currentProjectName> <newName>').action(function (currentProjectName, newName) {
if (currentProjectName !== projectName) {
return console.log('Project name didn\'t match!, your current project name is "' + projectName + '" ');
}
_commander2.default.version('1.0.5').arguments('<newName>').action(function (newName) {
if (newName.replace(/\s/g, '') === projectName) {
return console.log('Please try different name.');
}
if (newName === currentAppName) {
return console.log('Please try a different name.');
}
var withSpaceNewName = newName;
newName = newName.replace(/\s/g, '');
var lowercaseCurrentProjectName = currentProjectName.toLowerCase();
var lowercaseNewName = newName.toLowerCase();
var pattern = /^([0-9]|[a-z])+([0-9a-z\s]+)$/i;
var nS_NewName = newName.replace(/\s/g, '');
var lC_Ns_NewName = nS_NewName.toLowerCase();
var pattern = /^([0-9]|[a-z])+([0-9a-z\s]+)$/i;
if (!pattern.test(newName)) {
return console.log('"' + newName + '" is not a valid name for a project. Please use a valid identifier name (alphanumeric and space).');
}
// Check if entered new name is valid based on regex pattern
if (!pattern.test(newName)) {
return console.log('"' + newName + '" is not a valid name for a project. Please use a valid identifier name (alphanumeric and space).');
}
// Android App name
(0, _replace2.default)(_extends({
regex: '<string name="app_name">' + appName + '</string>',
replacement: '<string name="app_name">' + withSpaceNewName + '</string>',
paths: ['./android/app/src/main/res/values/strings.xml']
}, replaceOptions));
// Rename all folders
var commands = ['mv ./ios/' + nS_CurrentAppName + ' ios/' + nS_NewName, 'mv ./ios/' + nS_CurrentAppName + '.xcodeproj/xcshareddata/xcschemes/' + nS_CurrentAppName + '.xcscheme ios/' + nS_CurrentAppName + '.xcodeproj/xcshareddata/xcschemes/' + nS_NewName + '.xcscheme', 'mv ./ios/' + nS_CurrentAppName + '.xcodeproj ios/' + nS_NewName + '.xcodeproj', 'mv ./ios/' + nS_CurrentAppName + 'Tests/' + nS_CurrentAppName + 'Tests.m ios/' + nS_CurrentAppName + 'Tests/' + nS_NewName + 'Tests.m', 'mv ./ios/' + nS_CurrentAppName + 'Tests ios/' + nS_NewName + 'Tests', 'mv ./android/app/src/main/java/com/' + lC_Ns_CurrentAppName + ' android/app/src/main/java/com/' + lC_Ns_NewName, 'rm -rf ./ios/' + nS_CurrentAppName, 'rm -rf ./ios/' + nS_CurrentAppName + '.xcodeproj/xcshareddata/xcschemes/' + nS_CurrentAppName + '.xcscheme', 'rm -rf ./ios/' + nS_CurrentAppName + '.xcodeproj', 'rm -rf ./ios/' + nS_CurrentAppName + 'Tests/' + nS_CurrentAppName + 'Tests.m', 'rm -rf ./ios/' + nS_CurrentAppName + 'Tests', 'rm -rf ./android/app/src/main/java/com/' + lC_Ns_CurrentAppName, 'rm -rf ./ios/build', 'rm -rf ./android/.gradle', 'rm -rf ./android/app/build', 'rm -rf ./android/build'];
var iosPlistFiles = ['./ios/' + currentProjectName + '/Info.plist', './ios/' + currentProjectName + 'Tests/Info.plist'];
commands = commands.toString().replace(/,/g, ' && ');
// iOs App name
_child_process2.default.exec(commands, function (error, stdout) {
if (error !== null) {
console.log((0, _outdent2.default)(_templateObject));
process.exit(1);
}
});
setTimeout(function () {
// Replace android display name
(0, _replace2.default)(_extends({
regex: '<string name="app_name">' + currentAppName + '</string>',
replacement: '<string name="app_name">' + newName + '</string>',
paths: ['./android/app/src/main/res/values/strings.xml']
}, replaceOptions));
// Replace ios display name
renameIosPlist(nS_NewName, newName);
// Replace LaunchScreen text for the first time
(0, _replace2.default)(_extends({
regex: 'text="' + nS_CurrentAppName + '"',
replacement: 'text="' + newName + '"',
paths: ['./ios/' + nS_NewName + '/Base.lproj/LaunchScreen.xib']
}, replaceOptions));
// Replace LaunchScreen text
(0, _replace2.default)(_extends({
regex: 'text="' + currentAppName + '"',
replacement: 'text="' + newName + '"',
paths: ['./ios/' + nS_NewName + '/Base.lproj/LaunchScreen.xib']
}, replaceOptions));
// Replace text based on newName w/o the spaces and in lowercase
(0, _replace2.default)(_extends({
regex: lC_Ns_CurrentAppName,
replacement: lC_Ns_NewName,
paths: ['./android/app/BUCK', './android/app/build.gradle', './android/app/src/main/AndroidManifest.xml', './android/app/src/main/java/com/' + lC_Ns_NewName + '/MainActivity.java']
}, replaceOptions));
// Check if MainApplication.java exists, because some project don't have this file
if ((0, _fileExists2.default)('./android/app/src/main/java/com/' + lC_Ns_NewName + '/MainApplication.java')) {
(0, _replace2.default)(_extends({
regex: lC_Ns_CurrentAppName,
replacement: lC_Ns_NewName,
paths: ['./android/app/src/main/java/com/' + lC_Ns_NewName + '/MainApplication.java']
}, replaceOptions));
}
// Replace text based on newName w/o the spaces
(0, _replace2.default)(_extends({
regex: nS_CurrentAppName,
replacement: nS_NewName,
paths: ['./index.ios.js', './ios/' + nS_NewName + '/AppDelegate.m', './ios/' + nS_NewName + '.xcodeproj/xcshareddata/xcschemes/' + nS_NewName + '.xcscheme', './ios/' + nS_NewName + '.xcodeproj/project.pbxproj', './ios/' + nS_NewName + 'Tests/' + nS_NewName + 'Tests.m', './index.android.js', './android/app/src/main/java/com/' + lC_Ns_NewName + '/MainActivity.java', './android/settings.gradle']
}, replaceOptions));
// Replace package.json name property
(0, _replace2.default)(_extends({
regex: projectName,
replacement: nS_NewName,
paths: ['./package.json']
}, replaceOptions));
console.log('App successfully renamed to "' + newName + '"');
}, 1000);
}).parse(process.argv);
if (!process.argv.slice(2).length) _commander2.default.outputHelp();
})();
} else if (err.code === 'ENOENT') {
return console.log('Directory should be created using "react-native init"');
} else {
return console.log('Something went wrong: ', err.code);
}
});
function renameIosPlist(nS_NewName, newName) {
_fs2.default.readFile('./ios/' + nS_NewName + '/Info.plist', 'utf8', function (err, markup) {
var $ = _cheerio2.default.load(markup);
var CFBundleName = $("key:contains('CFBundleName')").next().text();
var iosPlistFiles = ['./ios/' + nS_NewName + '/Info.plist', './ios/' + nS_NewName + 'Tests/Info.plist'];
var _iteratorNormalCompletion = true;

@@ -98,3 +179,3 @@ var _didIteratorError = false;

var result = data.replace('<string>$(PRODUCT_NAME)</string>', '<string>' + withSpaceNewName + '</string>');
var result = data.replace(CFBundleName, newName);
_fs2.default.writeFile(file, result, 'utf8', function (err) {

@@ -123,55 +204,3 @@ if (err) return console.log(err);

}
(0, _replace2.default)(_extends({
regex: '<string>' + appName + '</string>',
replacement: '<string>' + withSpaceNewName + '</string>',
paths: ['./ios/' + currentProjectName + '/Info.plist', './ios/' + currentProjectName + 'Tests/Info.plist']
}, replaceOptions));
(0, _replace2.default)(_extends({
regex: currentProjectName,
replacement: withSpaceNewName,
paths: ['./ios/' + currentProjectName + '/Base.lproj/LaunchScreen.xib']
}, replaceOptions));
(0, _replace2.default)(_extends({
regex: appName,
replacement: withSpaceNewName,
paths: ['./ios/' + currentProjectName + '/Base.lproj/LaunchScreen.xib']
}, replaceOptions));
// Lowercase strings
(0, _replace2.default)(_extends({
regex: lowercaseCurrentProjectName,
replacement: lowercaseNewName,
paths: ['./android/app/BUCK', './android/app/build.gradle', './android/app/src/main/AndroidManifest.xml', './android/app/src/main/java/com/' + lowercaseCurrentProjectName + '/MainActivity.java']
}, replaceOptions));
if ((0, _fileExists2.default)('./android/app/src/main/java/com/' + lowercaseCurrentProjectName + '/MainApplication.java')) {
(0, _replace2.default)(_extends({
regex: lowercaseCurrentProjectName,
replacement: lowercaseNewName,
paths: ['./android/app/src/main/java/com/' + lowercaseCurrentProjectName + '/MainApplication.java']
}, replaceOptions));
}
(0, _replace2.default)(_extends({
regex: currentProjectName,
replacement: newName,
paths: ['./package.json', './index.ios.js', './ios/' + currentProjectName + '/AppDelegate.m', './ios/' + currentProjectName + '.xcodeproj/xcshareddata/xcschemes/' + currentProjectName + '.xcscheme', './ios/' + currentProjectName + '.xcodeproj/project.pbxproj', './ios/' + currentProjectName + 'Tests/' + currentProjectName + 'Tests.m', './index.android.js', './android/app/src/main/java/com/' + lowercaseCurrentProjectName + '/MainActivity.java', './android/settings.gradle']
}, replaceOptions));
var commands = ['mv ./ios/' + currentProjectName + ' ios/' + newName, 'mv ./ios/' + currentProjectName + '.xcodeproj/xcshareddata/xcschemes/' + currentProjectName + '.xcscheme ios/' + currentProjectName + '.xcodeproj/xcshareddata/xcschemes/' + newName + '.xcscheme', 'mv ./ios/' + currentProjectName + '.xcodeproj ios/' + newName + '.xcodeproj', 'mv ./ios/' + currentProjectName + 'Tests/' + currentProjectName + 'Tests.m ios/' + currentProjectName + 'Tests/' + newName + 'Tests.m', 'mv ./ios/' + currentProjectName + 'Tests ios/' + newName + 'Tests', 'mv ./android/app/src/main/java/com/' + lowercaseCurrentProjectName + ' android/app/src/main/java/com/' + lowercaseNewName, 'rm -rf ./ios/' + currentProjectName, 'rm -rf ./ios/' + currentProjectName + '.xcodeproj/xcshareddata/xcschemes/' + currentProjectName + '.xcscheme', 'rm -rf ./ios/' + currentProjectName + '.xcodeproj', 'rm -rf ./ios/' + currentProjectName + 'Tests/' + currentProjectName + 'Tests.m', 'rm -rf ./ios/' + currentProjectName + 'Tests', 'rm -rf ./android/app/src/main/java/com/' + lowercaseCurrentProjectName, 'rm -rf ./ios/build', 'rm -rf ./android/.gradle', 'rm -rf ./android/app/build', 'rm -rf ./android/build'];
commands = commands.toString().replace(/,/g, ' && ');
setTimeout(function () {
_child_process2.default.exec(commands, function (error, stdout) {
if (error !== null) console.log('exec error: ' + error);
console.log('App successfully renamed to "' + withSpaceNewName + '"');
});
}, 1000);
}).parse(process.argv);
if (!process.argv.slice(2).length) _commander2.default.outputHelp();
});
});
}
{
"name": "react-native-rename",
"version": "1.0.4",
"version": "1.0.5",
"description": "Rename react-native app with just one command",

@@ -36,2 +36,3 @@ "main": "lib/index.js",

"file-exists": "^2.0.0",
"outdent": "^0.2.1",
"project-name": "^0.2.6",

@@ -38,0 +39,0 @@ "replace": "^0.3.0"

### React Native Rename
Rename react-native app with just one command
> This package assumes that you created your react-native project using `react-native init`.
#### Installation

@@ -11,12 +13,8 @@ ```

```
react-native-rename <currentProjectName> <newName>
react-native-rename <newName>
```
#### Example
```
react-native-rename AwesomeApp "Cool App"
```
`currentProjectName` is from `package.json` `name` property
>Yes, it allows you to add spaces :-)
react-native-rename "Awesome App"
```