Skip to content

Commit

Permalink
update build
Browse files Browse the repository at this point in the history
  • Loading branch information
yudai1204 committed Jan 10, 2025
1 parent 8ca668d commit 9dc3b3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions afterBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ def afterBuild():
if "prod" in d and os.path.isdir(os.path.join("build", d))
]

# chromeディレクトリをコピーして、chromiumディレクトリを作成
chrome_dir_name = [d for d in build_dirs if "chrome" in d][0]
chromium_dir_name = chrome_dir_name.replace("chrome", "chromium")
if os.path.exists(f"build/{chromium_dir_name}"):
print(f"Remove: build/{chromium_dir_name}")
os.system(f"rm -rf build/{chromium_dir_name}")
os.system(f"cp -r build/{chrome_dir_name} build/{chromium_dir_name}")
build_dirs.append(chromium_dir_name)

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)

# chromeディレクトリは除外
if "chrome" not in build_dir:
# keyとoauth2とidentityの設定を削除
manifest.pop("key", None)
Expand All @@ -27,6 +36,7 @@ def afterBuild():
manifest["permissions"] = [
p for p in manifest["permissions"] if p != "identity"
]
print(f"Removed: key, oauth2, identity from {manifest_path}")

# 存在しないresourcesを削除
if "mv3" in build_dir:
Expand All @@ -39,7 +49,7 @@ def afterBuild():
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}")
print(f"Removed resources: {resource}")
# resourcesが空になったら削除
if len(web_accessible_resource["resources"]) == 0:
manifest["web_accessible_resources"].remove(
Expand All @@ -54,7 +64,7 @@ def afterBuild():
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}")
print(f"Removed resources: {resource}")
with open(manifest_path, "w") as f:
json.dump(manifest, f)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:edge": "plasmo build --target=edge-mv3 && npm run afterBuild",
"build:firefox": "plasmo build --target=firefox-mv2 && npm run afterBuild",
"build": "plasmo build --target=chrome-mv3 && plasmo build --target=edge-mv3 && plasmo build --target=firefox-mv2 && npm run afterBuild",
"package": "plasmo package --target=chrome-mv3 && plasmo package --target=edge-mv3 && plasmo package --target=firefox-mv2",
"package": "plasmo package --target=chrome-mv3 && plasmo package --target=chromium-mv3 && plasmo package --target=edge-mv3 && plasmo package --target=firefox-mv2",
"eslint": "eslint '**/*.ts?(x)' --fix",
"afterBuild": "python ./afterBuild.py",
"publish": "npm run build && npm run package && zip -r build/sources.zip src assets css locales package.json .env.production tsconfig.json README.md && publish-extension --chrome-zip build/chrome-mv3-prod.zip --firefox-zip build/firefox-mv2-prod.zip --firefox-sources-zip build/sources.zip --edge-zip build/edge-mv3-prod.zip"
Expand Down

0 comments on commit 9dc3b3d

Please sign in to comment.