Different Leanplum settings for dev and prod.

This commit is contained in:
Brendon Duncan 2018-09-13 12:47:01 +12:00
commit 8d8a5421bb

View file

@ -29,7 +29,7 @@ module.exports = function(grunt) {
build_ios_release: {
command: 'cordova prepare ios && cordova build ios --release',
options: {
maxBuffer: 1600 * 1024
maxBuffer: 3200 * 1024
}
},
chrome: {
@ -243,23 +243,21 @@ module.exports = function(grunt) {
},
},
copy: {
gen_constant_leanplum: {
gen_constant_leanplum_dev: {
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;
return processLeanplumConfig(content, 'dev');
},
},
},
gen_constant_leanplum_prod: {
src: 'src/js/templates/constants/leanplum-config.constant.js',
dest: 'src/js/generated/constants/leanplum-config.constant.js',
options: {
process: function (content, srcpath) {
return processLeanplumConfig(content, 'prod');
},
},
},
@ -367,13 +365,12 @@ module.exports = function(grunt) {
}
});
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('default', ['pre-dev', 'main']);
grunt.registerTask('main', ['nggettext_compile', 'exec:appConfig', 'exec:externalServices', 'browserify', 'sass', 'concat', 'copy:ionic_fonts', 'copy:ionic_js']);
grunt.registerTask('pre-dev', ['copy:gen_constant_leanplum_dev']);
grunt.registerTask('prod', ['copy:gen_constant_leanplum_prod', 'main', 'uglify']);
grunt.registerTask('translate', ['nggettext_extract']);
grunt.registerTask('chrome', ['default','exec:chrome']);
grunt.registerTask('wp', ['prod', 'exec:wp']);
grunt.registerTask('wp-copy', ['default', 'exec:wpcopy']);
grunt.registerTask('wp-init', ['default', 'exec:wpinit']);
grunt.registerTask('cordovaclean', ['exec:cordovaclean']);
// Build all
@ -387,14 +384,14 @@ module.exports = function(grunt) {
grunt.registerTask('build-mobile-release', ['build-ios-release', 'build-android-release']);
// Build ios
grunt.registerTask('start-ios', ['exec:build_ios_debug', 'exec:xcode']);
grunt.registerTask('build-ios-debug', ['exec:build_ios_debug']);
grunt.registerTask('start-ios', ['pre-dev', 'exec:build_ios_debug', 'exec:xcode']);
grunt.registerTask('build-ios-debug', ['pre-dev', 'exec:build_ios_debug']);
grunt.registerTask('build-ios-release', ['prod', 'exec:build_ios_release']);
// Build android
grunt.registerTask('start-android', ['build-android-debug', 'exec:run_android']);
grunt.registerTask('build-android-debug', ['exec:build_android_debug']);
grunt.registerTask('start-android-emulator', ['build-android-debug', 'exec:run_android_emulator']);
grunt.registerTask('start-android', ['pre-dev', 'build-android-debug', 'exec:run_android']);
grunt.registerTask('build-android-debug', ['pre-dev', 'exec:build_android_debug']);
grunt.registerTask('start-android-emulator', ['pre-dev', 'build-android-debug', 'exec:run_android_emulator']);
grunt.registerTask('build-android-release', ['prod', 'exec:build_android_release', 'sign-android']);
grunt.registerTask('sign-android', ['exec:sign_android']);
@ -418,5 +415,24 @@ module.exports = function(grunt) {
grunt.registerTask('sign-desktop', ['exec:sign_desktop_dist']);
// Release desktop
grunt.registerTask('build-desktop-release', ['build-desktop', 'sign-desktop']);
grunt.registerTask('build-desktop-release', ['build-desktop', 'sign-desktop']);
function processLeanplumConfig(content, env) {
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 leanplumForEnv = env === 'prod' ? leanplumConfig.prod : leanplumConfig.dev;
var newContent = '// Generated\n' + content
.replace("appId: ''","appId: '" + leanplumForEnv.appId + "'")
.replace("key: ''", "key: '" + leanplumForEnv.key + "'");
return newContent;
}
};