mirror of
https://github.com/BetterAndroid/compose-multiplatform-template.git
synced 2025-09-05 10:15:24 +08:00
feat: use repos to get version of plugins
This commit is contained in:
@@ -3,6 +3,40 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import sys
|
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):
|
def replace_strings_in_file(file_path, replacements):
|
||||||
with open(file_path, 'r', encoding = 'utf-8') as file:
|
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)
|
replace_strings_in_file(file_path, replacements)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if not update_settings_gradle():
|
||||||
|
return
|
||||||
with open('initializer.json', 'r', encoding = 'utf-8') as json_file:
|
with open('initializer.json', 'r', encoding = 'utf-8') as json_file:
|
||||||
replacements = json.load(json_file)
|
replacements = json.load(json_file)
|
||||||
extensions = ('.kt', '.properties', '.xml', '.gradle.kts', '.xcconfig', '.plist')
|
extensions = ('.kt', '.properties', '.xml', '.gradle.kts', '.xcconfig', '.plist')
|
||||||
|
@@ -7,8 +7,8 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
plugins {
|
plugins {
|
||||||
id("com.highcapable.sweetdependency") version "1.0.3"
|
id("com.highcapable.sweetdependency") version "__SWEET_DEPENDENCY_VERSION__"
|
||||||
id("com.highcapable.sweetproperty") version "1.0.4"
|
id("com.highcapable.sweetproperty") version "__SWEET_PROPERTY_VERSION__"
|
||||||
}
|
}
|
||||||
sweetProperty {
|
sweetProperty {
|
||||||
rootProject { all { isEnable = false } }
|
rootProject { all { isEnable = false } }
|
||||||
|
Reference in New Issue
Block a user