forked from iyegoroff/react-native-text-gradient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch-rn.js
31 lines (24 loc) · 880 Bytes
/
patch-rn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
const {writeFile, readFile, readdir} = require('fs');
const {promisify} = require('util');
const path = require('path');
const folder = 'node_modules/react-native/Libraries/Renderer/implementations/';
const pattern = new RegExp(
'throw ReactError[\\s\\S]{0,80}Text strings must be rendered within a <Text> component[\\s\\S]{0,80}[^()]\\)[;,]'
, 'gm');
const patchFile = async (file) => {
const content = (await promisify(readFile)(file)).toString();
const patched = content.replace(pattern, () => {
const fileRegEx = new RegExp('dev');
if (fileRegEx.test(file))
return '';
else
return '{}';
});
await promisify(writeFile)(file, patched);
};
const patchAll = async () => {
const files = await promisify(readdir)(folder);
await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};
patchAll();