feat: use repos to get version of plugins

This commit is contained in:
2023-11-04 04:45:01 +08:00
parent 02fb33eb25
commit 4c67dca537
2 changed files with 38 additions and 2 deletions

View File

@@ -3,6 +3,40 @@
import os
import json
import sys
import urllib.request
import re
def get_latest_version(repo_url):
api_url = f"https://api.github.com/repos/{repo_url}/releases/latest"
try:
response = urllib.request.urlopen(api_url)
if response.status == 200:
data = json.loads(response.read().decode('utf-8'))
return data['tag_name']
except Exception as e:
print(f"Unable to get version in repository {repo_url}, the error is {e}.")
return None
def update_settings_gradle():
repo_sweet_dependency_url = "HighCapable/SweetDependency"
repo_sweet_property_url = "HighCapable/SweetProperty"
version_sweet_dependency = get_latest_version(repo_sweet_dependency_url)
version_sweet_property = get_latest_version(repo_sweet_property_url)
if version_sweet_dependency and version_sweet_property:
with open('settings.gradle.kts', 'r') as file:
content = file.read()
content = re.sub(r'__SWEET_DEPENDENCY_VERSION__', version_sweet_dependency, content)
content = re.sub(r'__SWEET_PROPERTY_VERSION__', version_sweet_property, content)
with open('settings.gradle.kts', 'w') as file:
file.write(content)
return True
else:
print("Unable to initialize the project, please check the network connection and try again.")
return False
def replace_strings_in_file(file_path, replacements):
with open(file_path, 'r', encoding = 'utf-8') as file:
@@ -20,6 +54,8 @@ def replace_strings_in_directory(directory, replacements, extensions):
replace_strings_in_file(file_path, replacements)
def main():
if not update_settings_gradle():
return
with open('initializer.json', 'r', encoding = 'utf-8') as json_file:
replacements = json.load(json_file)
extensions = ('.kt', '.properties', '.xml', '.gradle.kts', '.xcconfig', '.plist')

View File

@@ -7,8 +7,8 @@ pluginManagement {
}
}
plugins {
id("com.highcapable.sweetdependency") version "1.0.3"
id("com.highcapable.sweetproperty") version "1.0.4"
id("com.highcapable.sweetdependency") version "__SWEET_DEPENDENCY_VERSION__"
id("com.highcapable.sweetproperty") version "__SWEET_PROPERTY_VERSION__"
}
sweetProperty {
rootProject { all { isEnable = false } }