diff --git a/cordova-plugin-fcm-with-dependecy-updated.podspec b/cordova-plugin-fcm-with-dependecy-updated.podspec index b28658299..6e4e5d1f2 100644 --- a/cordova-plugin-fcm-with-dependecy-updated.podspec +++ b/cordova-plugin-fcm-with-dependecy-updated.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "cordova-plugin-fcm-with-dependecy-updated" - spec.version = "4.5.2" + spec.version = "4.5.3" spec.summary = "Google FCM Push Notifications Cordova Plugin" # This description is used to generate tags and improve search results. diff --git a/package.json b/package.json index 27c7339f5..9e8d36458 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "4.5.2", + "version": "4.5.3", "name": "cordova-plugin-fcm-with-dependecy-updated", "cordova_name": "Cordova FCM Push Plugin", "description": "Google Firebase Cloud Messaging Cordova Push Plugin fork with dependecy updated", diff --git a/plugin.xml b/plugin.xml index a8d7c3e1e..ecbc2807e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -17,7 +17,7 @@ specific language governing permissions and limitations under the License. --> - + Cordova FCM Push Plugin Google Firebase Cloud Messaging Cordova Push Plugin fork with dependecy updated MIT @@ -120,4 +120,5 @@ + diff --git a/scripts/cdnfy_podfile.js b/scripts/cdnfy_podfile.js new file mode 100644 index 000000000..b8bfecfb2 --- /dev/null +++ b/scripts/cdnfy_podfile.js @@ -0,0 +1,104 @@ +#!/usr/bin/env node +'use strict'; + +var child_process = require('child_process'); +var helpers = require('./helpers'); +var fs = require('fs'); + +var IOS_PLATFORM_PATH = 'platforms/ios'; +var PODFILE_PATH = 'platforms/ios/Podfile'; +var PLUGIN_DEFINITION_PATH = 'plugins/cordova-plugin-fcm-with-dependecy-updated/plugin.xml'; + +function isSupportedByCocoapods(callback) { + // Verifies if installed version of cocoapods supports the cdn repo + // 1.7.2 + var major = '1'; + var minor = '7'; + var patch = '2'; + child_process.exec('pod --version', (err, stdout) => { + if (err) { + callback(false); + } + var currentVersion = stdout.replace(/[^\.\d]/, '').split('.'); + if (currentVersion[0] < major) { + callback(false); + } + if (currentVersion[0] === major) { + if (currentVersion[1] < minor) { + callback(false); + } + if (currentVersion[1] === minor && currentVersion[2] < patch) { + callback(false); + } + } + callback(true); + }); +} + +function isPluginFileAvailable() { + if (helpers.fileExists(PLUGIN_DEFINITION_PATH)) { + return true; + } else { + helpers.logWarning('Plugin.xml not found as ' + PLUGIN_DEFINITION_PATH); + return false; + } +} + +function isIOSPlatformInstalled() { + return helpers.directoryExists(IOS_PLATFORM_PATH); +} + +function replaceGithubHostedByCDN() { + if (isIOSPlatformInstalled()) { + replaceContentInFile( + PODFILE_PATH, + 'Podfile', + "source 'https://github.com/CocoaPods/Specs.git'", + "source 'https://cdn.cocoapods.org/'" + ); + } + replaceContentInFile( + PLUGIN_DEFINITION_PATH, + 'Plugin.xml', + '', + '' + ); +} + +function replaceContentInFile(filePath, fileName, from, to) { + var currentContent; + try { + currentContent = fs.readFileSync(filePath).toString(); + } catch (e) { + helpers.logWarning('Failed to read ' + fileName); + return; + } + if (currentContent === '') { + helpers.logWarning(fileName + ' found is completely empty'); + return; + } + var newContent = currentContent.replace(from, to); + if (newContent === currentContent) { + return; + } + try { + fs.writeFileSync(filePath, newContent); + } catch (e) { + helpers.logWarning('Failed to write enhanced ' + fileName); + return; + } +} + +function main() { + isSupportedByCocoapods(function (isVersionSupported) { + if (!isVersionSupported) { + return; + } + if (!isPluginFileAvailable()) { + return; + } + replaceGithubHostedByCDN(); + }); +} + +main(); diff --git a/scripts/copy_google_service_files.js b/scripts/copy_google_service_files.js index c8720d3f6..2e83a77ca 100644 --- a/scripts/copy_google_service_files.js +++ b/scripts/copy_google_service_files.js @@ -23,14 +23,6 @@ function copyGoogleServiceFile(platform) { }); } -function directoryExists(path) { - try { - return fs.statSync(path).isDirectory(); - } catch (e) { - return false; - } -} - function ensureFileDirExistance(filePath) { var dirPath = filePath.substring(0, filePath.lastIndexOf('/')); ensureDirExistance(dirPath); @@ -48,9 +40,9 @@ function ensureDirExistance(dirPath) { } } -if (directoryExists(PLATFORM.ANDROID.dir)) { +if (helpers.directoryExists(PLATFORM.ANDROID.dir)) { copyGoogleServiceFile(PLATFORM.ANDROID); } -if (directoryExists(PLATFORM.IOS.dir)) { +if (helpers.directoryExists(PLATFORM.IOS.dir)) { copyGoogleServiceFile(PLATFORM.IOS); } diff --git a/scripts/helpers.js b/scripts/helpers.js index db9347a37..c5d04f2c1 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -2,17 +2,25 @@ var fs = require('fs'); -function fileExists(path) { +exports.fileExists = function (path) { try { return fs.statSync(path).isFile(); } catch (e) { return false; } -} +}; + +exports.directoryExists = function (path) { + try { + return fs.statSync(path).isDirectory(); + } catch (e) { + return false; + } +}; exports.findExistingFilePath = function (paths) { for (var i = paths.length - 1; i > -1; i--) { - if (fileExists(paths[i])) { + if (exports.fileExists(paths[i])) { return paths[i]; } } diff --git a/scripts/insert_app_id_key_to_strings.js b/scripts/insert_app_id_key_to_strings.js deleted file mode 100644 index 5c12f0769..000000000 --- a/scripts/insert_app_id_key_to_strings.js +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env node -'use strict'; - -var fs = require('fs'); -var helpers = require('./helpers'); -var configurations = require(`./configuration`); - -var PLATFORM = configurations.PLATFORM; - -function updateAndroidStringsXml() { - var googleServiceContent = helpers.getGoogleServiceContent(PLATFORM.ANDROID); - if (!googleServiceContent) { - return; - } - var stringXmlPath = helpers.findExistingFilePath(PLATFORM.ANDROID.stringsXmls); - if (!stringXmlPath) { - helpers.logWarning('Android-specific strings.xml file not found!'); - return; - } - - // Current string values - var strings = fs.readFileSync(stringXmlPath).toString(); - - // Read Google Service app id and key - var googleServiceClient; - try { - googleServiceClient = JSON.parse(googleServiceContent).client[0]; - } catch (error) { - helpers.logError('google-services.json found was not a valid JSON', error); - } - - var entries = [ - { - name: 'google_app_id', - value: googleServiceClient.client_info.mobilesdk_app_id - }, - { - name: 'google_api_key', - value: googleServiceClient.api_key[0].current_key - } - ]; - - entries.forEach(function (entry) { - // If found, remove old entry - strings = strings.replace( - new RegExp('([^<]+?)', 'i'), - '\n' - ); - - var newEntryStartPosition = strings.indexOf(''); - if (newEntryStartPosition === -1) { - helpers.logError('string.xml unrecognizable!', strings); - return; - } - - strings = - strings.substr(0, newEntryStartPosition) + - ' ' + - entry.value + - '\n' + - strings.substr(newEntryStartPosition); - }); - - // strip empty lines - strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), ''); - - fs.writeFileSync(stringXmlPath, strings); -} - -if (directoryExists(PLATFORM.ANDROID.dir)) { - updateAndroidStringsXml(); -}