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

Commit 4eddc18

Browse files
Automate enabling iOS 10 keychain sharing #216
1 parent 00f9a4d commit 4eddc18

File tree

4 files changed

+59
-69
lines changed

4 files changed

+59
-69
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.DS_Store
33
node_modules
44
*.tgz
5-
scripts/postinstall.js
5+
scripts/postinstall.js
6+
scripts/install_ios_entitlements_packed.js

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
},
1313
"scripts": {
14-
"bundle-installer": "npm install --ignore-scripts && webpack --config scripts/webpack.config.js scripts/installer.js scripts/postinstall.js",
14+
"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",
1515
"prepublish": "npm run bundle-installer",
1616
"postinstall": "node scripts/postinstall.js",
1717
"config": "node scripts/postinstall.js config"

scripts/install_ios_entitlements.js

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,58 @@
11
var xcode = require('xcode'),
22
fs = require('fs'),
33
path = require('path'),
4-
appRoot = require('app-root-path').toString(),
5-
pjson = require(path.join(appRoot, 'package.json')),
6-
util = require('util'),
7-
iosFolder = path.join(appRoot, 'platforms', 'ios');
8-
9-
fs.readdir(iosFolder, function (err, data) {
10-
if (err) {
11-
throw err;
4+
pjson = eval('require(\'../../package.json\')'),
5+
iosFolder = path.join('platforms', 'ios'),
6+
data = fs.readdirSync(iosFolder),
7+
projFolder,
8+
projName;
9+
10+
// Find the project folder by looking for *.xcodeproj
11+
if (data && data.length) {
12+
data.forEach(function (folder) {
13+
if (folder.match(/\.xcodeproj$/)) {
14+
projFolder = path.join(iosFolder, folder);
15+
projName = path.basename(folder, '.xcodeproj');
16+
}
17+
});
18+
}
19+
20+
if (!projFolder || !projName) {
21+
throw new Error("Could not find an .xcodeproj folder in: " + iosFolder);
22+
}
23+
24+
var destFolder = path.join(iosFolder, projName, 'Resources');
25+
if (!fs.existsSync(destFolder)) {
26+
fs.mkdirSync(destFolder);
27+
}
28+
29+
var destFile = path.join(destFolder, projName + '.entitlements');
30+
31+
if (!fs.existsSync(destFile)) {
32+
var bundleID = pjson.nativescript.id;
33+
34+
// create a new entitlements plist file
35+
var sourceFile = path.join('node_modules', 'nativescript-plugin-firebase', 'scripts', 'resources', 'KeychainSharing.entitlements');
36+
37+
var fileData = fs.readFileSync(sourceFile).toString();
38+
fileData = fileData.replace(/__KEYCHAIN_ACCESS_GROUP__/g, bundleID);
39+
fs.writeFileSync(destFile, fileData);
40+
41+
var projectPath = path.join(projFolder, 'project.pbxproj'),
42+
pbxProject = xcode.project(projectPath);
43+
44+
pbxProject.parseSync();
45+
pbxProject.addResourceFile(path.join("Firebase", "Resources", projName + ".entitlements"));
46+
47+
48+
var configGroups = pbxProject.hash.project.objects['XCBuildConfiguration'];
49+
for (var key in configGroups) {
50+
var config = configGroups[key];
51+
if (config.buildSettings !== undefined) {
52+
config.buildSettings.CODE_SIGN_ENTITLEMENTS = '"' + projName + '/Resources/' + projName + '.entitlements"';
53+
}
1254
}
1355

14-
var projFolder;
15-
var projName;
16-
17-
// Find the project folder by looking for *.xcodeproj
18-
if (data && data.length) {
19-
data.forEach(function (folder) {
20-
if (folder.match(/\.xcodeproj$/)) {
21-
projFolder = path.join(iosFolder, folder);
22-
projName = path.basename(folder, '.xcodeproj');
23-
}
24-
});
25-
}
26-
27-
if (!projFolder || !projName) {
28-
throw new Error("Could not find an .xcodeproj folder in: " + iosFolder);
29-
}
30-
31-
var destFolder = path.join(iosFolder, projName, 'Resources');
32-
if (!fs.existsSync(destFolder)) {
33-
fs.mkdirSync(destFolder);
34-
}
35-
36-
var destFile = path.join(destFolder, projName + '.entitlements');
37-
38-
if (!fs.existsSync(destFile)) {
39-
var bundleID = pjson.nativescript.id;
40-
41-
// create a new entitlements plist file
42-
var sourceFile = path.join(appRoot, 'node_modules', 'nativescript-plugin-firebase', 'scripts', 'resources', 'KeychainSharing.entitlements');
43-
44-
fs.readFile(sourceFile, 'utf8', function (err, data) {
45-
data = data.replace(/__KEYCHAIN_ACCESS_GROUP__/g, bundleID);
46-
47-
fs.writeFileSync(destFile, data);
48-
49-
var projectPath = path.join(projFolder, 'project.pbxproj'),
50-
pbxProject = xcode.project(projectPath);
51-
52-
pbxProject.parseSync();
53-
pbxProject.addResourceFile(path.join("Firebase", "Resources", projName + ".entitlements"));
54-
55-
var configGroups = pbxProject.hash.project.objects['XCBuildConfiguration'];
56-
for (var key in configGroups) {
57-
var config = configGroups[key];
58-
if (config.buildSettings !== undefined) {
59-
config.buildSettings.CODE_SIGN_ENTITLEMENTS = '"' + projName + '/Resources/' + projName + '.entitlements"';
60-
}
61-
}
62-
63-
// write the updated project file
64-
fs.writeFileSync(projectPath, pbxProject.writeSync());
65-
});
66-
}
67-
});
56+
// write the updated project file
57+
fs.writeFileSync(projectPath, pbxProject.writeSync());
58+
}

scripts/installer.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function promptQuestions() {
133133
function promptQuestionsResult(result) {
134134
if(usingiOS) {
135135
writePodFile(result);
136-
// writeIOSEntitlementsCopyHook();
136+
writeIOSEntitlementsCopyHook();
137137
}
138138
if(usingAndroid) {
139139
writeGradleFile(result);
@@ -157,13 +157,11 @@ function askSaveConfigPrompt() {
157157
});
158158
}
159159

160-
// "scripts/install_ios_entitlements.js"
161160
function writeIOSEntitlementsCopyHook() {
162161
console.log("Install ios-entitlements installation hook.");
163162
try {
164-
var scriptContent = "module.exports = require(\"nativescript-plugin-firebase/scripts/install_ios_entitlements.js\");";
165-
166-
var scriptPath = path.join(appRoot, "hooks", "after-prepare", "run_ios_entitlements_install_script.js");
163+
var scriptContent = fs.readFileSync(path.join(appRoot, 'node_modules', 'nativescript-plugin-firebase', 'scripts', 'install_ios_entitlements_packed.js'));
164+
var scriptPath = path.join(appRoot, "hooks", "after-prepare", "firebase-install-ios-entitlements.js");
167165
var afterPrepareDirPath = path.dirname(scriptPath);
168166
var hooksDirPath = path.dirname(afterPrepareDirPath);
169167
if (!fs.existsSync(afterPrepareDirPath)) {

0 commit comments

Comments
 (0)