Skip to content

Commit

Permalink
Adds build-extras.gradle to add Google Pay SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgustavo committed Jul 5, 2021
1 parent cf64aa5 commit 3264a62
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
33 changes: 33 additions & 0 deletions app-template/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,39 @@ try {
console.log('External services not configured.');
}

// Google Pay
if (configDir == 'bitpay') {
let buildExtrasGradle;
try {
const googlePayPath = 'GOOGLEPAY_DIR';
console.log('Looking for ' + googlePayPath + '...');
if (typeof process.env[googlePayPath] !== 'undefined') {
let location = process.env[googlePayPath];
if (location.charAt(0) === '~') {
location = location.replace(
/^\~/,
process.env.HOME || process.env.USERPROFILE
);
}
console.log('Found at: ' + location);

let content = fs.readFileSync('build-extras-template.gradle', 'utf8');
content = content.replace('*GOOGLEPAY_DIR*', location);

console.log(
'Copying build-extras-template.gradle to ./build-extras.gradle'
);
fs.writeFileSync('../build-extras.gradle', content);
console.log('Google Pay is ready.');
} else {
throw googlePayPath + ' environment variable not set.';
}
} catch (err) {
console.log(err);
console.log('Google Pay not configured.');
}
}

function copyDir(from, to, noRemove) {
console.log(`Copying dir '${from}' to '${to}'...`);
if (fs.existsSync(to) && !noRemove) fs.removeSync(to); // remove previous app directory
Expand Down
7 changes: 7 additions & 0 deletions app-template/build-extras-template.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
allprojects {
repositories {
mavenCentral()
jcenter()
maven { url "file://*GOOGLEPAY_DIR*" }
}
}
1 change: 1 addition & 0 deletions app-template/config-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
</platform>

<platform name="android">
<hook src="copy-build-extras-gradle.js" type="before_build" />
<preference name="android-manifest/application/@android:allowBackup" value="false" />

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
Expand Down
2 changes: 1 addition & 1 deletion copy-build-extras-gradle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var fs = require('fs');
var path = require('path');
var rootdir = process.env.PWD;
var platformAndroidPath = '/platforms/android/app/';
var platformAndroidPath = './platforms/android/app/';
var srcFile = path.join(rootdir, 'build-extras.gradle');
var destFile = path.join(rootdir, platformAndroidPath, 'build-extras.gradle');
var destDir = path.dirname(destFile);
Expand Down
File renamed without changes.

0 comments on commit 3264a62

Please sign in to comment.