feat(huawei-push): implement settings.gradle configuration via withSettingsGradle
Integrate Huawei Maven repository and AGConnect plugin into settings.gradle using the withSettingsGradle helper. This ensures the necessary repositories and plugin management are correctly configured for Huawei Push services.
This commit is contained in:
@@ -11,6 +11,45 @@ const path = require('path');
|
||||
const withHuaweiPush = (config, options = {}) => {
|
||||
const { jpushVersion = '5.8.0' } = options;
|
||||
|
||||
config = withSettingsGradle(config, (config) => {
|
||||
const contents = config.modResults.contents;
|
||||
|
||||
if (!contents.includes('developer.huawei.com/repo')) {
|
||||
if (contents.includes('pluginManagement')) {
|
||||
config.modResults.contents = contents.replace(
|
||||
/(pluginManagement\s*\{[\s\S]*?repositories\s*\{)/,
|
||||
`$1\n maven { url 'https://developer.huawei.com/repo/' }`
|
||||
);
|
||||
}
|
||||
if (!config.modResults.contents.includes('developer.huawei.com/repo')) {
|
||||
config.modResults.contents =
|
||||
`pluginManagement {\n repositories {\n maven { url 'https://developer.huawei.com/repo/' }\n }\n}\n` +
|
||||
config.modResults.contents;
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.modResults.contents.includes("id 'com.huawei.agconnect'")) {
|
||||
if (config.modResults.contents.includes('pluginManagement')) {
|
||||
config.modResults.contents = config.modResults.contents.replace(
|
||||
/(pluginManagement\s*\{)/,
|
||||
`$1\n plugins {\n id 'com.huawei.agconnect' version '1.9.1.301' apply false\n }`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.modResults.contents.includes('developer.huawei.com/repo')) {
|
||||
const depMgmtPattern = /dependencyResolutionManagement\s*\{[\s\S]*?repositories\s*\{/;
|
||||
if (depMgmtPattern.test(config.modResults.contents)) {
|
||||
config.modResults.contents = config.modResults.contents.replace(
|
||||
depMgmtPattern,
|
||||
`$&\n maven { url 'https://developer.huawei.com/repo/' }`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
config = withProjectBuildGradle(config, (config) => {
|
||||
const contents = config.modResults.contents;
|
||||
|
||||
@@ -41,6 +80,16 @@ const withHuaweiPush = (config, options = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.modResults.contents.includes('developer.huawei.com/repo')) {
|
||||
const bsRepoPattern = /(buildscript\s*\{[\s\S]*?repositories\s*\{)/;
|
||||
if (bsRepoPattern.test(config.modResults.contents)) {
|
||||
config.modResults.contents = config.modResults.contents.replace(
|
||||
bsRepoPattern,
|
||||
`$1\n maven { url 'https://developer.huawei.com/repo/' }`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user