This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate enabling iOS 10 keychain sharing #216
- Loading branch information
1 parent
ce20438
commit 399c087
Showing
4 changed files
with
59 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters