Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add signin apple capability automatically #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
.idea
node_modules
package-lock.json
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
"bugs": {
"url": "https://github.com/twogate/cordova-plugin-sign-in-with-apple/issues"
},
"homepage": "https://github.com/twogate/cordova-plugin-sign-in-with-apple#readme"
"homepage": "https://github.com/twogate/cordova-plugin-sign-in-with-apple#readme",
"dependencies": {
"plist": "^3.0.6",
"xml2js": "^0.5.0"
}
}
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
<string>Default</string>
</array>
</config-file>
<!--<hook type="after_prepare" src="scripts/after_prepare.js" />-->
<hook type="after_prepare" src="scripts/after_prepare.js" />
</platform>
</plugin>
42 changes: 29 additions & 13 deletions scripts/after_prepare.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
#!/usr/bin/env node
/**
Hook is executed at the end of the 'prepare' stage. Usually, when you call 'cordova build'.

'use strict';
It will inject required preferences in the platform-specific projects, based on <universal-links>
data you have specified in the projects config.xml file.
*/

var fs = require('fs');
var path = require('path');
var utilities = require("./lib/utilities");
var iosProjectEntitlements = require('./lib/ios/projectEntitlements.js');
var IOS = 'ios';

module.exports = function (context) {
//get platform from the context supplied by cordova
var platforms = context.opts.platforms;
// Copy key files to their platform specific folders
if (platforms.indexOf('ios') !== -1 && utilities.directoryExists(IOS_DIR)) {
console.log('Preparing Sign in with Apple on iOS');
utilities.copyKey(PLATFORM.IOS);
}
module.exports = function(ctx) {
run(ctx);
};

/**
* Execute hook.
*
* @param {Object} cordovaContext - cordova context object
*/
function run(cordovaContext) {
var platformsList = cordovaContext.opts.platforms;

platformsList.forEach(function(platform) {
switch (platform) {
case IOS:
{
// generate entitlements file
iosProjectEntitlements.generateAssociatedDomainsEntitlements(cordovaContext);
break;
}
}
});
}
10 changes: 0 additions & 10 deletions scripts/before_plugin_uninstall.js

This file was deleted.

144 changes: 0 additions & 144 deletions scripts/helper.js

This file was deleted.

117 changes: 117 additions & 0 deletions scripts/lib/configXmlHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
Helper class to read data from config.xml file.
*/
var path = require('path');
var xmlHelper = require('./xmlHelper.js');
var ANDROID = 'android';
var IOS = 'ios';
var CONFIG_FILE_NAME = 'config.xml';
var context;
var projectRoot;

module.exports = ConfigXmlHelper;

// region public API

/**
* Constructor.
*
* @param {Object} cordovaContext - cordova context object
*/
function ConfigXmlHelper(cordovaContext) {
context = cordovaContext;
projectRoot = context.opts.projectRoot;
}

/**
* Read config.xml data as JSON object.
*
* @return {Object} JSON object with data from config.xml
*/
ConfigXmlHelper.prototype.read = function() {
var filePath = getConfigXmlFilePath();

return xmlHelper.readXmlAsJson(filePath);
}

/**
* Get package name for the application. Depends on the platform.
*
* @param {String} platform - 'ios' or 'android'; for what platform we need a package name
* @return {String} package/bundle name
*/
ConfigXmlHelper.prototype.getPackageName = function(platform) {
var configFilePath = getConfigXmlFilePath();
var config = getCordovaConfigParser(configFilePath);
var packageName;

switch (platform) {
case ANDROID:
{
packageName = config.android_packageName();
break;
}
case IOS:
{
packageName = config.ios_CFBundleIdentifier();
break;
}
}
if (packageName === undefined || packageName.length == 0) {
packageName = config.packageName();
}

return packageName;
}

/**
* Get name of the current project.
*
* @return {String} name of the project
*/
ConfigXmlHelper.prototype.getProjectName = function() {
return getProjectName();
}

// endregion

// region Private API

/**
* Get config parser from cordova library.
*
* @param {String} configFilePath absolute path to the config.xml file
* @return {Object}
*/
function getCordovaConfigParser(configFilePath) {
var ConfigParser;

// If we are running Cordova 5.4 or abova - use parser from cordova-common.
// Otherwise - from cordova-lib.
try {
ConfigParser = context.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser');
} catch (e) {
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser')
}

return new ConfigParser(configFilePath);
}

/**
* Get absolute path to the config.xml.
*/
function getConfigXmlFilePath() {
return path.join(projectRoot, CONFIG_FILE_NAME);
}

/**
* Get project name from config.xml
*/
function getProjectName() {
var configFilePath = getConfigXmlFilePath();
var config = getCordovaConfigParser(configFilePath);

return config.name();
}

// endregion
Loading