Skip to content

Commit

Permalink
fix afterBuild.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yudai1204 committed Jan 8, 2025
1 parent 30aed5a commit 684e9b1
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions afterBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,51 @@ def afterBuild():
build_dirs = [
d
for d in os.listdir("build")
if "prod" in d and os.path.isdir(os.path.join("build", d)) and "chrome" not in d
if "prod" in d and os.path.isdir(os.path.join("build", d))
]

for build_dir in build_dirs:
manifest_path = os.path.join("build", build_dir, "manifest.json")
with open(manifest_path, "r") as f:
manifest = json.load(f)
# keyとoauth2とidentityの設定を削除
manifest.pop("key", None)
manifest.pop("oauth2", None)
# permissionsからidentityを削除
if "permissions" in manifest:
manifest["permissions"] = [
p for p in manifest["permissions"] if p != "identity"
]

if "chrome" not in build_dir:
# keyとoauth2とidentityの設定を削除
manifest.pop("key", None)
manifest.pop("oauth2", None)
# permissionsからidentityを削除
if "permissions" in manifest:
manifest["permissions"] = [
p for p in manifest["permissions"] if p != "identity"
]

# 存在しないresourcesを削除
if "mv3" in build_dir:
for web_accessible_resource in manifest["web_accessible_resources"]:
for resource in web_accessible_resource["resources"]:
# assets/*, css/*は許可
if resource == "assets/*" or resource == "css/*":
continue
# 存在しているかチェックする
resource_path = os.path.join("build", build_dir, resource)
if not os.path.exists(resource_path):
web_accessible_resource["resources"].remove(resource)
print(f"Removed: {resource}")
# resourcesが空になったら削除
if len(web_accessible_resource["resources"]) == 0:
manifest["web_accessible_resources"].remove(
web_accessible_resource
)
if "mv2" in build_dir:
for resource in manifest["web_accessible_resources"]:
# assets/*, css/*は許可
if resource == "assets/*" or resource == "css/*":
continue
# 存在しているかチェックする
resource_path = os.path.join("build", build_dir, resource)
if not os.path.exists(resource_path):
manifest["web_accessible_resources"].remove(resource)
print(f"Removed: {resource}")
with open(manifest_path, "w") as f:
json.dump(manifest, f)

Expand Down

0 comments on commit 684e9b1

Please sign in to comment.