This commit is contained in:
Jarm7 2025-06-23 17:13:47 +05:00 committed by GitHub
commit 3dd2eb7d31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,49 +3,49 @@ import time
import os
import sys
def panic(message: str):
print(message, file=sys.stderr)
exit(1)
def update_theme_date(theme_path):
theme_file = os.path.join(theme_path, "theme.json")
if not os.path.exists(theme_file):
panic(f"{theme_file} not found.")
# Load the theme JSON data
with open(theme_file, "r") as f:
# Load the theme JSON data with single file operation
try:
with open(theme_file, "r") as f:
theme_data = json.load(f)
except json.JSONDecodeError as e:
panic("Error reading theme.json: " + str(e))
# Get the current date
# Get the current date once and reuse
current_date = time.strftime("%Y-%m-%d")
# Set `createdAt` to the current date if it doesn't exist
# Combine checks and updates for efficiency
updates_made = False
if "createdAt" not in theme_data:
theme_data["createdAt"] = current_date
print(f"Set `createdAt` for {theme_path} to {theme_data['createdAt']}")
updates_made = True
# Update the `updatedAt` field to the current date
if theme_data.get("updatedAt") != current_date:
theme_data["updatedAt"] = current_date
print(f"Updated `updatedAt` for {theme_path} to {theme_data['updatedAt']}")
updates_made = True
# Add `tags` as an empty list if it doesn't exist
if "tags" not in theme_data:
theme_data["tags"] = []
print(f"Initialized `tags` for {theme_path} as an empty list")
updates_made = True
# Write the changes back to theme.json
# Write changes only if modifications were made
if updates_made:
with open(theme_file, "w") as f:
json.dump(theme_data, f, indent=4)
print(f"Updated `updatedAt` for {theme_path} to {theme_data['updatedAt']}")
if __name__ == "__main__":
# Make sure the script is run with the theme path as an argument
if len(sys.argv) != 2: