-
Notifications
You must be signed in to change notification settings - Fork 6
/
ios-configuration.js
40 lines (34 loc) · 1.3 KB
/
ios-configuration.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
32
33
34
35
36
37
38
39
40
const fs = require('fs');
const path = require("path");
const appName = process.argv[2];
const configiOS = () => {
if(!appName) {
console.log('The appName is not specific, see https://github.com/Kennytian/meiqia-react-native#ios-3');
return;
}
const iosRootPath = `${__dirname}/../../ios/`;
const plistPath = `${appName}/Info.plist`;
const filePath = path.join(iosRootPath, plistPath);
fs.readFile(filePath, 'utf-8', (readErr, file) => {
if (readErr) {
console.error('readFile:', readErr);
return;
}
const zhCNString = /<string>zh_CN<\/string>/;
if (zhCNString.test(file)) {
console.log('Localizations is added!');
return;
}
const searchValue = /(\t<key>CFBundleInfoDictionaryVersion<\/key>\n\t<string>6.0<\/string>)(\s{2})/;
const replaceValue = '$1 \n\t<key>CFBundleLocalizations<\/key>\n\t<array>\n\t\t<string>zh_CN<\/string>\n\t\t<string>zh_TW<\/string>\n\t\t<string>en<\/string>\n\t<\/array>\n\t';
const result = file.replace(searchValue, replaceValue);
fs.writeFile(filePath, result, 'utf-8', (writeErr) => {
if (writeErr) {
console.error('writeFile:', writeErr);
return;
}
console.log(`🎉 🎉 🎉, CFBundleLocalizations configuration is successful 👍 👍 👍!`);
});
});
};
configiOS();