Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Automate enabling iOS 10 keychain sharing #216
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Nov 20, 2016
1 parent ce20438 commit 399c087
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.DS_Store
node_modules
*.tgz
scripts/postinstall.js
scripts/postinstall.js
scripts/install_ios_entitlements_packed.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
},
"scripts": {
"bundle-installer": "npm install --ignore-scripts && webpack --config scripts/webpack.config.js scripts/installer.js scripts/postinstall.js",
"bundle-installer": "npm install --ignore-scripts && webpack --config scripts/webpack.config.js scripts/installer.js scripts/postinstall.js && webpack --config scripts/webpack.config.js scripts/install_ios_entitlements.js scripts/install_ios_entitlements_packed.js",
"prepublish": "npm run bundle-installer",
"postinstall": "node scripts/postinstall.js",
"config": "node scripts/postinstall.js config"
Expand Down
115 changes: 53 additions & 62 deletions scripts/install_ios_entitlements.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,58 @@
var xcode = require('xcode'),
fs = require('fs'),
path = require('path'),
appRoot = require('app-root-path').toString(),
pjson = require(path.join(appRoot, 'package.json')),
util = require('util'),
iosFolder = path.join(appRoot, 'platforms', 'ios');

fs.readdir(iosFolder, function (err, data) {
if (err) {
throw err;
pjson = eval('require(\'../../package.json\')'),
iosFolder = path.join('platforms', 'ios'),
data = fs.readdirSync(iosFolder),
projFolder,
projName;

// Find the project folder by looking for *.xcodeproj
if (data && data.length) {
data.forEach(function (folder) {
if (folder.match(/\.xcodeproj$/)) {
projFolder = path.join(iosFolder, folder);
projName = path.basename(folder, '.xcodeproj');
}
});
}

if (!projFolder || !projName) {
throw new Error("Could not find an .xcodeproj folder in: " + iosFolder);
}

var destFolder = path.join(iosFolder, projName, 'Resources');
if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder);
}

var destFile = path.join(destFolder, projName + '.entitlements');

if (!fs.existsSync(destFile)) {
var bundleID = pjson.nativescript.id;

// create a new entitlements plist file
var sourceFile = path.join('node_modules', 'nativescript-plugin-firebase', 'scripts', 'resources', 'KeychainSharing.entitlements');

var fileData = fs.readFileSync(sourceFile).toString();
fileData = fileData.replace(/__KEYCHAIN_ACCESS_GROUP__/g, bundleID);
fs.writeFileSync(destFile, fileData);

var projectPath = path.join(projFolder, 'project.pbxproj'),
pbxProject = xcode.project(projectPath);

pbxProject.parseSync();
pbxProject.addResourceFile(path.join("Firebase", "Resources", projName + ".entitlements"));


var configGroups = pbxProject.hash.project.objects['XCBuildConfiguration'];
for (var key in configGroups) {
var config = configGroups[key];
if (config.buildSettings !== undefined) {
config.buildSettings.CODE_SIGN_ENTITLEMENTS = '"' + projName + '/Resources/' + projName + '.entitlements"';
}
}

var projFolder;
var projName;

// Find the project folder by looking for *.xcodeproj
if (data && data.length) {
data.forEach(function (folder) {
if (folder.match(/\.xcodeproj$/)) {
projFolder = path.join(iosFolder, folder);
projName = path.basename(folder, '.xcodeproj');
}
});
}

if (!projFolder || !projName) {
throw new Error("Could not find an .xcodeproj folder in: " + iosFolder);
}

var destFolder = path.join(iosFolder, projName, 'Resources');
if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder);
}

var destFile = path.join(destFolder, projName + '.entitlements');

if (!fs.existsSync(destFile)) {
var bundleID = pjson.nativescript.id;

// create a new entitlements plist file
var sourceFile = path.join(appRoot, 'node_modules', 'nativescript-plugin-firebase', 'scripts', 'resources', 'KeychainSharing.entitlements');

fs.readFile(sourceFile, 'utf8', function (err, data) {
data = data.replace(/__KEYCHAIN_ACCESS_GROUP__/g, bundleID);

fs.writeFileSync(destFile, data);

var projectPath = path.join(projFolder, 'project.pbxproj'),
pbxProject = xcode.project(projectPath);

pbxProject.parseSync();
pbxProject.addResourceFile(path.join("Firebase", "Resources", projName + ".entitlements"));

var configGroups = pbxProject.hash.project.objects['XCBuildConfiguration'];
for (var key in configGroups) {
var config = configGroups[key];
if (config.buildSettings !== undefined) {
config.buildSettings.CODE_SIGN_ENTITLEMENTS = '"' + projName + '/Resources/' + projName + '.entitlements"';
}
}

// write the updated project file
fs.writeFileSync(projectPath, pbxProject.writeSync());
});
}
});
// write the updated project file
fs.writeFileSync(projectPath, pbxProject.writeSync());
}
8 changes: 3 additions & 5 deletions scripts/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function promptQuestions() {
function promptQuestionsResult(result) {
if(usingiOS) {
writePodFile(result);
// writeIOSEntitlementsCopyHook();
writeIOSEntitlementsCopyHook();
}
if(usingAndroid) {
writeGradleFile(result);
Expand All @@ -157,13 +157,11 @@ function askSaveConfigPrompt() {
});
}

// "scripts/install_ios_entitlements.js"
function writeIOSEntitlementsCopyHook() {
console.log("Install ios-entitlements installation hook.");
try {
var scriptContent = "module.exports = require(\"nativescript-plugin-firebase/scripts/install_ios_entitlements.js\");";

var scriptPath = path.join(appRoot, "hooks", "after-prepare", "run_ios_entitlements_install_script.js");
var scriptContent = fs.readFileSync(path.join(appRoot, 'node_modules', 'nativescript-plugin-firebase', 'scripts', 'install_ios_entitlements_packed.js'));
var scriptPath = path.join(appRoot, "hooks", "after-prepare", "firebase-install-ios-entitlements.js");
var afterPrepareDirPath = path.dirname(scriptPath);
var hooksDirPath = path.dirname(afterPrepareDirPath);
if (!fs.existsSync(afterPrepareDirPath)) {
Expand Down

0 comments on commit 399c087

Please sign in to comment.