react-native-notificare-push-ui
Version:
Notificare Push UI React Native module.
61 lines (60 loc) • 3.18 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAndSetStringsResource = createAndSetStringsResource;
const Locales_1 = require("@expo/config-plugins/build/ios/Locales");
const config_plugins_1 = require("expo/config-plugins");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const LOCALIZABLE_FILE = 'Localizable.strings';
const LOCALIZABLES_FOLDER = 'Notificare';
async function createAndSetStringsResource(proj, projRoot, appName, locales) {
const localesMap = await (0, Locales_1.getResolvedLocalesAsync)(projRoot, locales);
const iosAppPath = config_plugins_1.IOSConfig.Paths.getSourceRoot(projRoot);
const destinationPath = path_1.default.join(iosAppPath, LOCALIZABLES_FOLDER);
for (const [lang, localizationObj] of Object.entries(localesMap)) {
const localizableFolderName = lang === 'default' ? 'Base' : lang;
const localizableGroupName = `${appName}/${LOCALIZABLES_FOLDER}/${localizableFolderName}.lproj`;
const localizableFileContent = [];
const localizableFolderPath = path_1.default.join(destinationPath, `${localizableFolderName}.lproj`);
const localizableFilePath = path_1.default.join(localizableFolderPath, LOCALIZABLE_FILE);
await fs_1.default.promises.mkdir(localizableFolderPath, { recursive: true });
for (const [key, value] of Object.entries(localizationObj)) {
localizableFileContent.push(`${key} = "${value}";`);
}
fs_1.default.writeFileSync(localizableFilePath, localizableFileContent.join('\n'));
// Adds children to PBXGroup and creates one when doesn't exist
// Note: created PBXGroup will have path === '""'
config_plugins_1.IOSConfig.XcodeUtils.ensureGroupRecursively(proj, localizableGroupName);
if (!groupHasChild(proj, `${localizableFolderName}.lproj`, LOCALIZABLE_FILE)) {
proj = config_plugins_1.IOSConfig.XcodeUtils.addResourceFileToGroup({
filepath: path_1.default.relative(destinationPath, localizableFilePath),
groupName: localizableGroupName,
project: proj,
isBuildFile: true,
verbose: true,
});
}
}
setNotificarePBXGroupPath(proj, appName);
return proj;
}
function setNotificarePBXGroupPath(proj, appName) {
const groups = proj.hash.project.objects['PBXGroup'];
Object.keys(groups).forEach(function (key) {
if (groups[key]?.name === LOCALIZABLES_FOLDER &&
groups[key]?.path === '""') {
groups[key].path = `${appName}/${LOCALIZABLES_FOLDER}`;
}
});
}
function groupHasChild(proj, group, child) {
const groups = proj.hash.project.objects['PBXGroup'];
return Object.keys(groups).some(function (key) {
return ((groups[key]?.name === group || groups[key]?.name === `"${group}"`) &&
// @ts-ignore
groups[key]?.children?.some(({ comment }) => comment === child));
});
}
;