Skip to content

Instantly share code, notes, and snippets.

@kocyigityunus
Created February 16, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kocyigityunus/2393c857f7e2557fab88b687f0435186 to your computer and use it in GitHub Desktop.
Save kocyigityunus/2393c857f7e2557fab88b687f0435186 to your computer and use it in GitHub Desktop.
change react native port
'ust strict';
var fs = require('fs');
var replaceOptions = [
{
location: './node_modules/react-native/React/React.xcodeproj/project.pbxproj',
replaceFrom: [
' localhost 8081 ;',
'http://localhost:8081/status',
'Port 8081 already in use',
],
replaceTo: [
' localhost 9000 ;',
'http://localhost:9000/status',
'Port 9000 already in use',
],
},
{
location: './node_modules/react-native/local-cli/server/server.js',
replaceFrom: [
'default: 8081,',
],
replaceTo: [
'default: 9000,',
]
},
{
location: './node_modules/react-native/Libraries/WebSocket/RCTWebSocketExecutor.m',
replaceFrom: [
'?: 8081;',
],
replaceTo: [
'?: 9000;',
]
},
{
location: './node_modules/react-native/React/Base/RCTBridgeDelegate.h',
replaceFrom: [
'localhost:8081',
],
replaceTo: [
'localhost:9000',
]
},
{
location: './node_modules/react-native/React/Base/RCTBundleURLProvider.m',
replaceFrom: [
'DefaultPort = 8081;',
],
replaceTo: [
'DefaultPort = 9000;',
]
},
{
location: './node_modules/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm',
replaceFrom: [
'port = @8081;',
],
replaceTo: [
'port = @9000;',
]
},
{
location: './node_modules/react-native/React/DevSupport/RCTPackagerConnectionBridgeConfig.m',
replaceFrom: [
'port = @8081;',
],
replaceTo: [
'port = @9000;',
]
},
];
replaceOptions.forEach( function(replaceOption){
var filePath = replaceOption.location;
var fileContent = fs.readFileSync(filePath, 'utf8');
console.log('read file: ' + filePath );
var replaceCount = replaceOption.replaceFrom.length;
for (var i = 0; i < replaceCount; i++){
var replaceFrom = replaceOption.replaceFrom[i];
var replaceTo = replaceOption.replaceTo[i];
fileContent = fileContent.replace(replaceFrom,replaceTo);
console.log('replaced ' + replaceFrom + ' to ' + replaceTo + '.');
}
fs.writeFileSync(filePath, fileContent, 'utf8');
console.log('write new file: ' + filePath );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment