diff --git a/plugin.xml b/plugin.xml index d413e2460..469ac67c6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -11,7 +11,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"> - @@ -64,7 +63,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"> - @@ -118,4 +116,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"> + + diff --git a/scripts/ios/after_prepare.js b/scripts/after_prepare.js similarity index 58% rename from scripts/ios/after_prepare.js rename to scripts/after_prepare.js index 81b7470f3..9e3111164 100644 --- a/scripts/ios/after_prepare.js +++ b/scripts/after_prepare.js @@ -9,12 +9,13 @@ */ var fs = require('fs'); var path = require('path'); -var utilities = require("../lib/utilities"); +var utilities = require("./lib/utilities"); var config = fs.readFileSync('config.xml').toString(); var name = utilities.getValue(config, 'name'); var IOS_DIR = 'platforms/ios'; +var ANDROID_DIR = 'platforms/android'; var PLATFORM = { IOS: { @@ -27,13 +28,31 @@ var PLATFORM = { IOS_DIR + '/www/GoogleService-Info.plist', 'www/GoogleService-Info.plist' ] + }, + ANDROID: { + dest: [ + ANDROID_DIR + '/google-services.json', + ANDROID_DIR + '/app/google-services.json' + ], + src: [ + 'google-services.json', + ANDROID_DIR + '/assets/www/google-services.json', + 'www/google-services.json', + ANDROID_DIR + '/app/src/main/google-services.json' + ], } }; 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 (utilities.directoryExists(IOS_DIR)) { + if (platforms.indexOf('ios') !== -1 && utilities.directoryExists(IOS_DIR)) { console.log('Preparing Firebase on iOS'); utilities.copyKey(PLATFORM.IOS); } + if (platforms.indexOf('android') !== -1 && utilities.directoryExists(ANDROID_DIR)) { + console.log('Preparing Firebase on Android'); + utilities.copyKey(PLATFORM.ANDROID); + } }; diff --git a/scripts/android/after_prepare.js b/scripts/android/after_prepare.js deleted file mode 100644 index 7fe8cd137..000000000 --- a/scripts/android/after_prepare.js +++ /dev/null @@ -1,39 +0,0 @@ -#!/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 utilities = require("../lib/utilities"); - -var config = fs.readFileSync('config.xml').toString(); -var name = utilities.getValue(config, 'name'); - -var ANDROID_DIR = 'platforms/android'; - -var PLATFORM = { - ANDROID: { - dest: [ - ANDROID_DIR + '/google-services.json', - ANDROID_DIR + '/app/google-services.json' - ], - src: [ - 'google-services.json', - ANDROID_DIR + '/assets/www/google-services.json', - 'www/google-services.json', - ANDROID_DIR + '/app/src/main/google-services.json' - ], - } -}; - -module.exports = function (context) { - if (utilities.directoryExists(ANDROID_DIR)) { - console.log('Preparing Firebase on Android'); - utilities.copyKey(PLATFORM.ANDROID); - } -}; diff --git a/scripts/lib/utilities.js b/scripts/lib/utilities.js index 1a5ba0791..7154f60d4 100644 --- a/scripts/lib/utilities.js +++ b/scripts/lib/utilities.js @@ -17,7 +17,6 @@ fs.ensureDirSync = function (dir) { }; module.exports = { - /** * Used to get the name of the application as defined in the config.xml. *