All checks were successful
Deploy to Production / deploy (push) Successful in 14s
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
import json
|
|
import os
|
|
import shutil
|
|
import zipfile
|
|
|
|
# Configuration
|
|
SOURCE_DIR = "extension"
|
|
BUILD_DIR = "dist-extension"
|
|
MANIFEST_FILE = "manifest.json"
|
|
|
|
# Read version to create dynamic zip name
|
|
with open(os.path.join(SOURCE_DIR, MANIFEST_FILE), "r") as f:
|
|
source_manifest = json.load(f)
|
|
version = source_manifest.get("version", "unknown")
|
|
OUTPUT_ZIP = f"tools-app-extension-v{version}.zip"
|
|
|
|
# Remove build directory if exists
|
|
if os.path.exists(BUILD_DIR):
|
|
shutil.rmtree(BUILD_DIR)
|
|
|
|
# Copy source directory to build directory
|
|
shutil.copytree(SOURCE_DIR, BUILD_DIR)
|
|
|
|
# Modify manifest.json for production
|
|
manifest_path = os.path.join(BUILD_DIR, MANIFEST_FILE)
|
|
with open(manifest_path, "r") as f:
|
|
manifest = json.load(f)
|
|
|
|
# Filter permissions and content scripts (remove localhost)
|
|
print("Removing localhost from manifest...")
|
|
|
|
# Filter host_permissions
|
|
if "host_permissions" in manifest:
|
|
manifest["host_permissions"] = [
|
|
perm for perm in manifest["host_permissions"]
|
|
if "localhost" not in perm
|
|
]
|
|
|
|
# Filter content_scripts matches
|
|
if "content_scripts" in manifest:
|
|
for script in manifest["content_scripts"]:
|
|
if "matches" in script:
|
|
script["matches"] = [
|
|
match for match in script["matches"]
|
|
if "localhost" not in match
|
|
]
|
|
|
|
# Save modified manifest
|
|
with open(manifest_path, "w") as f:
|
|
json.dump(manifest, f, indent=2)
|
|
|
|
# Create ZIP file
|
|
print(f"Creating {OUTPUT_ZIP}...")
|
|
with zipfile.ZipFile(OUTPUT_ZIP, "w", zipfile.ZIP_DEFLATED) as zipf:
|
|
for root, dirs, files in os.walk(BUILD_DIR):
|
|
for file in files:
|
|
file_path = os.path.join(root, file)
|
|
arcname = os.path.relpath(file_path, BUILD_DIR)
|
|
zipf.write(file_path, arcname)
|
|
|
|
# Cleanup
|
|
shutil.rmtree(BUILD_DIR)
|
|
print(f"Done! {OUTPUT_ZIP} is ready for upload to Chrome Web Store.")
|