cordova-plugin-firebase
Advanced tools
Comparing version 0.1.23 to 0.1.24
@@ -11,3 +11,3 @@ { | ||
"name": "cordova-plugin-firebase", | ||
"version": "0.1.23", | ||
"version": "0.1.24", | ||
"description": "Cordova plugin for Google Firebase", | ||
@@ -14,0 +14,0 @@ "cordova": { |
@@ -5,2 +5,8 @@ # cordova-plugin-firebase | ||
Donations are welcome and will go towards further development of this project. Use the wallet address below to donate. | ||
BTC: 1JuXhHMCPHXT2fDfSRUTef9TpE2D67sc9f | ||
Thank you for your support! | ||
## Installation | ||
@@ -11,7 +17,7 @@ See npm package for versions - https://www.npmjs.com/package/cordova-plugin-firebase | ||
``` | ||
<plugin name="cordova-plugin-firebase" spec="0.1.23" /> | ||
<plugin name="cordova-plugin-firebase" spec="0.1.24" /> | ||
``` | ||
or by running: | ||
``` | ||
cordova plugin add cordova-plugin-firebase@0.1.23 --save | ||
cordova plugin add cordova-plugin-firebase@0.1.24 --save | ||
``` | ||
@@ -18,0 +24,0 @@ Download your Firebase configuration files, GoogleService-Info.plist for ios and google-services.json for android, and place them in the root folder of your cordova project: |
#!/usr/bin/env node | ||
'use strict'; | ||
/** | ||
* This hook makes sure projects using [cordova-plugin-firebase](https://github.com/arnesson/cordova-plugin-firebase) | ||
* will build properly and have the required key files copied to the proper destinations when the app is build on Ionic Cloud using the package command. | ||
* Credits: https://github.com/arnesson. | ||
*/ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var getValue = function(config, name) { | ||
var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', "i")) | ||
if(value && value[1]) { | ||
return value[1] | ||
} else { | ||
return null | ||
fs.ensureDirSync = function (dir) { | ||
if (!fs.existsSync(dir)) { | ||
dir.split(path.sep).reduce(function (currentPath, folder) { | ||
currentPath += folder + path.sep; | ||
if (!fs.existsSync(currentPath)) { | ||
fs.mkdirSync(currentPath); | ||
} | ||
return currentPath; | ||
}, ''); | ||
} | ||
} | ||
}; | ||
function fileExists(path) { | ||
try { | ||
return fs.statSync(path).isFile(); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} | ||
var config = fs.readFileSync('config.xml').toString(); | ||
var name = getValue(config, 'name'); | ||
function directoryExists(path) { | ||
try { | ||
return fs.statSync(path).isDirectory(); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} | ||
var IOS_DIR = 'platforms/ios'; | ||
var ANDROID_DIR = 'platforms/android'; | ||
var config = fs.readFileSync("config.xml").toString() | ||
var name = getValue(config, "name") | ||
var PLATFORM = { | ||
IOS: { | ||
dest: [ | ||
IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist', | ||
IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist' | ||
], | ||
src: [ | ||
'GoogleService-Info.plist', | ||
IOS_DIR + '/www/GoogleService-Info.plist', | ||
'www/GoogleService-Info.plist' | ||
] | ||
}, | ||
ANDROID: { | ||
dest: [ | ||
ANDROID_DIR + '/google-services.json' | ||
], | ||
src: [ | ||
'google-services.json', | ||
ANDROID_DIR + '/assets/www/google-services.json', | ||
'www/google-services.json' | ||
], | ||
stringsXml: ANDROID_DIR + '/res/values/strings.xml' | ||
} | ||
}; | ||
if (directoryExists("platforms/ios")) { | ||
var paths = ["GoogleService-Info.plist", "platforms/ios/www/GoogleService-Info.plist"]; | ||
// Copy key files to their platform specific folders | ||
if (directoryExists(IOS_DIR)) { | ||
copyKey(PLATFORM.IOS); | ||
} else if (directoryExists(ANDROID_DIR)) { | ||
copyKey(PLATFORM.ANDROID, updateStringsXml) | ||
} | ||
for (var i = 0; i < paths.length; i++) { | ||
if (fileExists(paths[i])) { | ||
try { | ||
var contents = fs.readFileSync(paths[i]).toString(); | ||
fs.writeFileSync("platforms/ios/" + name + "/Resources/GoogleService-Info.plist", contents) | ||
} catch(err) { | ||
process.stdout.write(err); | ||
} | ||
function updateStringsXml(contents) { | ||
var json = JSON.parse(contents); | ||
var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString(); | ||
break; | ||
} | ||
} | ||
} | ||
// strip non-default value | ||
strings = strings.replace(new RegExp('<string name="google_app_id">([^\@<]+?)</string>', 'i'), ''); | ||
if (directoryExists("platforms/android")) { | ||
var paths = ["google-services.json", "platforms/android/assets/www/google-services.json"]; | ||
// strip non-default value | ||
strings = strings.replace(new RegExp('<string name="google_api_key">([^\@<]+?)</string>', 'i'), ''); | ||
for (var i = 0; i < paths.length; i++) { | ||
if (fileExists(paths[i])) { | ||
try { | ||
var contents = fs.readFileSync(paths[i]).toString(); | ||
fs.writeFileSync("platforms/android/google-services.json", contents); | ||
// strip empty lines | ||
strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), '$1'); | ||
if (contents) { | ||
var json = JSON.parse(contents); | ||
// replace the default value | ||
strings = strings.replace(new RegExp('<string name="google_app_id">([^<]+?)</string>', 'i'), '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string>'); | ||
var strings = fs.readFileSync("platforms/android/res/values/strings.xml").toString(); | ||
// replace the default value | ||
strings = strings.replace(new RegExp('<string name="google_api_key">([^<]+?)</string>', 'i'), '<string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string>'); | ||
// strip non-default value | ||
strings = strings.replace(new RegExp('<string name="google_app_id">([^\@<]+?)<\/string>', "i"), '') | ||
fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings); | ||
} | ||
// strip non-default value | ||
strings = strings.replace(new RegExp('<string name="google_api_key">([^\@<]+?)<\/string>', "i"), '') | ||
function copyKey(platform, callback) { | ||
for (var i = 0; i < platform.src.length; i++) { | ||
var file = platform.src[i]; | ||
if (fileExists(file)) { | ||
try { | ||
var contents = fs.readFileSync(file).toString(); | ||
// strip empty lines | ||
strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', "gm"), '$1') | ||
try { | ||
platform.dest.forEach(function (destinationPath) { | ||
var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/')); | ||
fs.ensureDirSync(folder); | ||
fs.writeFileSync(destinationPath, contents); | ||
}); | ||
} catch (e) { | ||
// skip | ||
} | ||
// replace the default value | ||
strings = strings.replace(new RegExp('<string name="google_app_id">([^<]+?)<\/string>', "i"), '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string>') | ||
callback && callback(contents); | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
// replace the default value | ||
strings = strings.replace(new RegExp('<string name="google_api_key">([^<]+?)<\/string>', "i"), '<string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string>') | ||
fs.writeFileSync("platforms/android/res/values/strings.xml", strings); | ||
break; | ||
} | ||
} catch(err) { | ||
process.stdout.write(err); | ||
} | ||
} | ||
} | ||
break; | ||
function getValue(config, name) { | ||
var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', 'i')); | ||
if (value && value[1]) { | ||
return value[1] | ||
} else { | ||
return null | ||
} | ||
} | ||
} | ||
function fileExists(path) { | ||
try { | ||
return fs.statSync(path).isFile(); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function directoryExists(path) { | ||
try { | ||
return fs.statSync(path).isDirectory(); | ||
} catch (e) { | ||
return false; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63553146
311
343