UNPKG

nativescript-plugin-firebase-ssi

Version:
33 lines (29 loc) 1.35 kB
var fs = require('fs'); var path = require('path'); module.exports = function (hookArgs, $projectData) { var platform = (hookArgs.platform || hookArgs.prepareData.platform).toLowerCase(), appResourcesDirectoryPath = $projectData.appResourcesDirectoryPath, entitlementsFile = path.join(appResourcesDirectoryPath, "iOS", $projectData.projectName + ".entitlements"), platformResourcesDirectory = path.join(appResourcesDirectoryPath, 'iOS'); // look for both <projectname.entitlements and app.entitlements if (!fs.existsSync(entitlementsFile)) { entitlementsFile = path.join(appResourcesDirectoryPath, "iOS", "app.entitlements"); } return new Promise(function (resolve, reject) { if (platform === 'ios' && fs.existsSync(entitlementsFile)) { var target = path.join(platformResourcesDirectory, 'build.xcconfig'); try { var buildData = fs.readFileSync(target).toString(); if (!buildData.toString().match(/^\s*CODE_SIGN_ENTITLEMENTS/mg)) { fs.appendFileSync(target, '\nCODE_SIGN_ENTITLEMENTS = ' + path.join($projectData.projectName, $projectData.projectName + '.entitlements')); } } catch (error) { console.log("Error in hook 'entitlements-before-prepare.js': " + error); reject(); } } else { resolve(); } resolve(); }); };