-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support patching iOS, JavaScript and Java react-native files (#11)
* patch works ios and js * use TextImproved native component on Android
- Loading branch information
1 parent
0d805ea
commit 0540e72
Showing
12 changed files
with
460 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env node | ||
|
||
// Credits to ifsnow/react-native-networking-patch | ||
// https://github.com/ifsnow/react-native-networking-patch/blob/master/patch.js | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const rootPath = path.join(__dirname, '.'); | ||
|
||
// ============================================================================ | ||
// Get RN version | ||
// ============================================================================ | ||
// const RNRootPath = path.join(__dirname, '..', 'react-native'); | ||
const RNRootPath = path.join( | ||
__dirname, | ||
'./example/node_modules', | ||
'react-native' | ||
); | ||
const RNPackageFile = `${RNRootPath}/package.json`; | ||
if (!fs.existsSync(RNPackageFile)) { | ||
console.log('[!] Not exists react-native'); | ||
process.exit(1); | ||
} | ||
|
||
const packageFile = fs.readFileSync(RNPackageFile); | ||
let packageJSON = null; | ||
|
||
try { | ||
packageJSON = JSON.parse(packageFile); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
if (!packageJSON) { | ||
console.log('[!] Failed to get version of react-native'); | ||
process.exit(1); | ||
} | ||
|
||
const patchDir = packageJSON.version; | ||
const isPatchExists = | ||
patchDir !== '' && fs.existsSync(`${rootPath}/patches/${patchDir}`); | ||
if (!isPatchExists) { | ||
const supportVersions = fs | ||
.readdirSync(`${rootPath}/patches`) | ||
.filter((dir) => dir.match(/^\d/)) | ||
.join(', '); | ||
console.log(`[!] Unsupported react-native version! (${patchDir})`); | ||
console.log(`[!] Supported react-native versions: ${supportVersions}`); | ||
process.exit(1); | ||
} | ||
|
||
function getAllFiles(dirPath, arrayOfFiles) { | ||
const files = fs.readdirSync(dirPath); | ||
|
||
arrayOfFiles = arrayOfFiles || []; | ||
|
||
files.forEach(function (file) { | ||
if (file === '.DS_Store') { | ||
return; | ||
} | ||
|
||
const filePath = `${dirPath}/${file}`; | ||
if (fs.statSync(filePath).isDirectory()) { | ||
arrayOfFiles = getAllFiles(filePath, arrayOfFiles); | ||
} else { | ||
arrayOfFiles.push(filePath); | ||
} | ||
}); | ||
|
||
return arrayOfFiles; | ||
} | ||
|
||
// ============================================================================ | ||
// Copy files | ||
// ============================================================================ | ||
const targetFilesDir = `${rootPath}/patches/${patchDir}/files`; | ||
getAllFiles(targetFilesDir).forEach(function (sourceFile) { | ||
const destFile = `${RNRootPath}${sourceFile.replace(targetFilesDir, '')}`; | ||
fs.copyFileSync(sourceFile, destFile); | ||
}); | ||
|
||
console.log('[!] React Native was patched!'); |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.