erisu commented on a change in pull request #1212:
URL: https://github.com/apache/cordova-android/pull/1212#discussion_r663524709



##########
File path: bin/templates/cordova/lib/prepare.js
##########
@@ -92,6 +76,76 @@ module.exports.prepare = function (cordovaProject, options) {
     });
 };
 
+function updateUserProjectGradleConfig (configXml, defaultGradleConfigPath, 
projectGradleConfigPath) {
+    const defaultGradleConfig = fs.readJSONSync(defaultGradleConfigPath);
+    const profileGradleConfig = fs.readJSONSync(projectGradleConfigPath);
+
+    // Replace modified configs with defaults
+    const mergedConfigs = Object.assign(profileGradleConfig, 
defaultGradleConfig);
+
+    const configXmlToGradleMapping = [
+        { xmlKey: 'android-minSdkVersion', gradleKey: 'MIN_SDK_VERSION', type: 
Number },
+        { xmlKey: 'android-maxSdkVersion', gradleKey: 'MAX_SDK_VERSION', 
default: null, type: Number },
+        { xmlKey: 'android-targetSdkVersion', gradleKey: 'SDK_VERSION', type: 
Number },
+        { xmlKey: 'android-buildToolsVersion', gradleKey: 
'BUILD_TOOLS_VERSION', type: String },
+        { xmlKey: 'GradleVersion', gradleKey: 'GRADLE_VERSION', type: String },
+        { xmlKey: 'AndroidGradlePluginVersion', gradleKey: 'AGP_VERSION', 
type: String },
+        { xmlKey: 'GradlePluginKotlinVersion', gradleKey: 'KOTLIN_VERSION', 
type: String },
+        { xmlKey: 'AndroidXAppCompatVersion', gradleKey: 
'ANDROIDX_APP_COMPAT_VERSION', type: String },
+        { xmlKey: 'GradlePluginGoogleServicesVersion', gradleKey: 
'GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION', type: String },
+        { xmlKey: 'GradlePluginGoogleServicesEnabled', gradleKey: 
'IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED', type: Boolean },
+        { xmlKey: 'GradlePluginKotlinEnabled', gradleKey: 
'IS_GRADLE_PLUGIN_KOTLIN_ENABLED', type: Boolean }
+    ];
+
+    configXmlToGradleMapping.forEach(mapping => {
+        const configXmlValue = configXml.getPreference(mapping.xmlKey, 
'android');
+
+        if (Object.prototype.hasOwnProperty.call(mapping, 'default')) {
+            if (configXmlValue || typeof configXmlValue === 'boolean') {

Review comment:
       ```js
   // replace default with `required` or `optional`
   if (Object.prototype.hasOwnProperty.call(mapping, 'default')) {
     // Replace this with a `switch` statement after more use cases appear.
     // `Number` could also be replaced with `mapping.type` since there is only 
one case and is Number.
     if (configXmlValue || typeof configXmlValue === Number) {
       mergedConfigs[mapping.gradleKey] = parseFloat(value);
     } else if (Object.prototype.hasOwnProperty.call(mergedConfigs, 
mapping.gradleKey)) {
       // Since configXmlValue had an incorrect data type, if the key already 
exists, remove it.
       delete mergedConfigs[mapping.gradleKey];
     }
   } else {
     // ..
   }
   ```
   
   Not tested, but maybe this will work instead.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to