From 92ae53b03ebfff9d561f122c863524b637961ff6 Mon Sep 17 00:00:00 2001 From: soumak77 Date: Tue, 9 Oct 2018 08:50:18 -0700 Subject: [PATCH 1/2] refactor after_prepare hook --- plugin.xml | 4 +- scripts/after_prepare.js | 70 ++++++++++++++++++++++++++++++++ scripts/android/after_prepare.js | 39 ------------------ scripts/ios/after_prepare.js | 39 ------------------ scripts/lib/utilities.js | 13 ------ 5 files changed, 72 insertions(+), 93 deletions(-) create mode 100644 scripts/after_prepare.js delete mode 100644 scripts/android/after_prepare.js delete mode 100644 scripts/ios/after_prepare.js 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/after_prepare.js b/scripts/after_prepare.js new file mode 100644 index 000000000..a98083b38 --- /dev/null +++ b/scripts/after_prepare.js @@ -0,0 +1,70 @@ +#!/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"); + +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; + }, ''); + } +}; + +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: { + 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', + 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 (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/ios/after_prepare.js b/scripts/ios/after_prepare.js deleted file mode 100644 index 81b7470f3..000000000 --- a/scripts/ios/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 IOS_DIR = 'platforms/ios'; - -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' - ] - } -}; - -module.exports = function (context) { - // Copy key files to their platform specific folders - if (utilities.directoryExists(IOS_DIR)) { - console.log('Preparing Firebase on iOS'); - utilities.copyKey(PLATFORM.IOS); - } -}; diff --git a/scripts/lib/utilities.js b/scripts/lib/utilities.js index 1a5ba0791..8054c6ffd 100644 --- a/scripts/lib/utilities.js +++ b/scripts/lib/utilities.js @@ -4,20 +4,7 @@ var fs = require('fs'); var path = require("path"); -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; - }, ''); - } -}; - module.exports = { - /** * Used to get the name of the application as defined in the config.xml. * From cac4c2bd0d27e09881b70d20c08fceb44a8e4191 Mon Sep 17 00:00:00 2001 From: soumak77 Date: Tue, 9 Oct 2018 22:10:51 -0700 Subject: [PATCH 2/2] undo ensureDirSync refactoring --- scripts/after_prepare.js | 12 ------------ scripts/lib/utilities.js | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/after_prepare.js b/scripts/after_prepare.js index a98083b38..9e3111164 100644 --- a/scripts/after_prepare.js +++ b/scripts/after_prepare.js @@ -11,18 +11,6 @@ var fs = require('fs'); var path = require('path'); var utilities = require("./lib/utilities"); -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; - }, ''); - } -}; - var config = fs.readFileSync('config.xml').toString(); var name = utilities.getValue(config, 'name'); diff --git a/scripts/lib/utilities.js b/scripts/lib/utilities.js index 8054c6ffd..7154f60d4 100644 --- a/scripts/lib/utilities.js +++ b/scripts/lib/utilities.js @@ -4,6 +4,18 @@ var fs = require('fs'); var path = require("path"); +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; + }, ''); + } +}; + module.exports = { /** * Used to get the name of the application as defined in the config.xml.