Skip to content

Commit

Permalink
Merge pull request #702 from shankari/script_fixes
Browse files Browse the repository at this point in the history
Fix issues in the hook scripts
  • Loading branch information
shankari authored Jul 14, 2020
2 parents ac65596 + 015747b commit d0d576d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions hooks/after_platform_add/ios/ios_copy_locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var fs = require('fs-extra');
var path = require('path');
var et = require('elementtree');

const LOG_NAME = "Copying locales: ";

Expand All @@ -14,7 +15,6 @@ module.exports = function (context) {

console.log(LOG_NAME + "Retrieving application name...")
var config_xml = path.join(context.opts.projectRoot, 'config.xml');
var et = context.requireCordovaModule('elementtree');
var data = fs.readFileSync(config_xml).toString();
// If no data then no config.xml
if (data) {
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = function (context) {
var platformlproj = platformRes + lproj;
if (!fs.existsSync(platformlproj)) {
console.log(LOG_NAME + platformlproj + "does not exist, I will create it.");
fs.mkdirSync(platformlproj);
fs.mkdirSync(platformlproj, {recursive: true} );
}

fs.copySync(lprojFolder, platformlproj);
Expand Down
4 changes: 2 additions & 2 deletions hooks/before_build/android/android_copy_locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function (context) {
var platformValues = platformRes + values;
if (!fs.existsSync(platformValues)) {
console.log(LOG_NAME + platformValues + "does not exist, I will create it.");
fs.mkdirSync(platformValues);
fs.mkdirSync(platformValues, {recursive: true});
}

fs.copySync(valuesFolder, platformValues);
Expand All @@ -48,4 +48,4 @@ module.exports = function (context) {
console.log(LOG_NAME + languagei18n + " not found, I will continue.")
}
});
}
}
8 changes: 4 additions & 4 deletions hooks/before_build/android/android_set_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

var fs = require('fs');
var path = require('path');
var et = require('elementtree');

const PROVIDER = "edu.berkeley.eecs.emission.provider";
const ACCOUNT_TYPE = "eecs.berkeley.edu";
const LOG_NAME = "Changing Providers: ";
Expand Down Expand Up @@ -74,12 +76,10 @@ var changeAccountTypeAndProvider = function (file, accountType, providerName, ne

module.exports = function (context) {
// If Android platform is not installed, don't even execute
if (context.opts.cordova.platforms.indexOf('android') < 0)
return;
if (!context.opts.platforms.includes('android')) return;

console.log(LOG_NAME + "Retrieving application name...")
var config_xml = path.join(context.opts.projectRoot, 'config.xml');
var et = context.requireCordovaModule('elementtree');
var data = fs.readFileSync(config_xml).toString();
// If no data then no config.xml
if (data) {
Expand Down Expand Up @@ -111,4 +111,4 @@ module.exports = function (context) {
} else {
throw new Error(LOG_NAME + "Could not retrieve application name.");
}
}
}
22 changes: 22 additions & 0 deletions hooks/before_prepare/ios_use_apns_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

'use strict'

var fs = require('fs-extra');

const LOG_NAME = "Setting iOS push: FCM = false, APNS = true";
const CONF_FILE = "GoogleServicesInfo.plist";

module.exports = function (context) {
const FCM_TOKEN_SETTING = new RegEx("<key>IS_GCM_ENABLED</key>(\n\\s*)<true></true>", "g");
if (!ctx.opts.platforms.includes('ios')) return;
if (fs.existsSync(confFile)) {
console.log(LOG_NAME + confFile + " found, modifying it");
var regEx = new RegExp(currentName, 'g');

var data = fs.readFileSync(confFile, 'utf8');
var replacedData = data.replace(regEx, "<key>IS_GCM_ENABLED</key>$1<false></false>");
fs.writeFileSync(CONF_FILE, replacedData, 'utf8');
console.log(LOG_NAME + confFile + " modified file written");
}
}

0 comments on commit d0d576d

Please sign in to comment.