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



##########
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') {
+                mergedConfigs[mapping.gradleKey] = configXmlValue;
+            } else if (Object.prototype.hasOwnProperty.call(mergedConfigs, 
mapping.gradleKey)) {
+                delete mergedConfigs[mapping.gradleKey];
+            }
+        } else {
+            let value = configXmlValue || 
defaultGradleConfig[mapping.gradleKey];
+
+            switch (mapping.type) {
+            default:
+            case String:
+                value = value.toString();
+                break;
+            case Number:
+                value = parseFloat(value);

Review comment:
       Fair enough




-- 
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.

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