From ff01933151897ea845ccbfbfcb83cb8f23e708f6 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 13 Sep 2018 12:02:25 +1200 Subject: [PATCH] Getting Leanplum app ID and key from outside the repo. --- .gitignore | 1 + Gruntfile.js | 25 ++++++++++++++-- src/js/routes.js | 9 +++--- .../constants/leanplum-config.constant.js | 29 +++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 src/js/templates/constants/leanplum-config.constant.js diff --git a/.gitignore b/.gitignore index 3c2ae0c74..e435345d0 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,4 @@ www/img/app ## Firebase /GoogleService-Info.plist /google-services.json +src/js/generated diff --git a/Gruntfile.js b/Gruntfile.js index 1092b3de2..8652863fb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -175,6 +175,7 @@ module.exports = function(grunt) { js: { src: [ 'src/js/app.js', + 'src/js/generated/constants/*.js', 'src/js/routes.js', 'src/js/decorators/*.js', @@ -242,6 +243,26 @@ module.exports = function(grunt) { }, }, copy: { + gen_constant_leanplum: { + src: 'src/js/templates/constants/leanplum-config.constant.js', + dest: 'src/js/generated/constants/leanplum-config.constant.js', + options: { + process: function (content, srcpath) { + var leanplumConfig = {}; + try { + leanplumConfig = grunt.file.readJSON('../leanplum-config.json'); + } catch (e) { + // Without this, there is no clue on the console about what happened. + console.error('Error reading JSON', e); + throw e; + } + var newContent = '// Generated\n' + content + .replace("appId: ''","appId: '" + leanplumConfig.dev.appId + "'") + .replace("key: ''", "key: '" + leanplumConfig.dev.key + "'"); + return newContent; + }, + }, + }, ionic_fonts: { expand: true, flatten: true, @@ -345,8 +366,8 @@ module.exports = function(grunt) { } } }); - - grunt.registerTask('default', ['nggettext_compile', 'exec:appConfig', 'exec:externalServices', 'browserify', 'sass', 'concat', 'copy:ionic_fonts', 'copy:ionic_js']); + + grunt.registerTask('default', ['nggettext_compile', 'exec:appConfig', 'exec:externalServices', 'browserify', 'sass', 'copy:gen_constant_leanplum', 'concat', 'copy:ionic_fonts', 'copy:ionic_js']); grunt.registerTask('prod', ['default', 'uglify']); grunt.registerTask('translate', ['nggettext_extract']); grunt.registerTask('chrome', ['default','exec:chrome']); diff --git a/src/js/routes.js b/src/js/routes.js index f83bcec2b..48dae52ab 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1207,7 +1207,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, pushNotificationsService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService, rateService) { + .run(function(leanplumConfig, $rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, pushNotificationsService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService, rateService) { $ionicPlatform.ready(function() { @@ -1228,7 +1228,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr "wallet_created": "nd3dg5", "wallet_opened": "4n39l7" } - } + }, + leanplum: leanplumConfig }); configService.whenAvailable(function(config) { @@ -1273,14 +1274,14 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr name: 'tab_open', class: 'track_tab_open', params: ['href', 'title', 'icon-off'], - channels: [channel] + channels: [channel, 'leanplum'] }); window.BitAnalytics.ActionHandlers.trackAction(actionTabOpen); var actionShapeShiftStart = new window.BitAnalytics.ActionFactory.createAction('click', { name: 'shapeshift_start_click', class: 'track_shapeshift_start_click', - channels: [channel] + channels: [channel, 'leanplum'] }); window.BitAnalytics.ActionHandlers.trackAction(actionShapeShiftStart); diff --git a/src/js/templates/constants/leanplum-config.constant.js b/src/js/templates/constants/leanplum-config.constant.js new file mode 100644 index 000000000..f09b6b76f --- /dev/null +++ b/src/js/templates/constants/leanplum-config.constant.js @@ -0,0 +1,29 @@ +'use strict'; + +/* +Template is at: + src/js/templates/constants + +Requires a file above the project root: leanplum-config.json, containing: + { + "dev": { + "appId": "YOUR_DEV_APP_ID", + "key": "YOUR_DEV_KEY" + }, + "prod": { + "appId": "YOUR_PROD_APP_ID", + "key": "YOUR_PROD_KEY" + } + } +*/ + +(function(){ + + angular + .module('bitcoincom.services') + .constant('leanplumConfig', { + appId: '', + key: '' + }); + +})(); \ No newline at end of file