Skip to content

Commit 01b1bc9

Browse files
committed
script to update manifest
1 parent 8890744 commit 01b1bc9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# This script is used to replace a package from the project manifest.json with a local version.
2+
# The goal is that you will trigger the build process from your branch (for example release/1.2.3) and package from this branch will be use in the project manifest.1
3+
# Note that for now this script is assuming that such package already has an entry in the manifest
4+
# TODO: consider if it makes sense to just add new manifest entry (to test what?)
5+
6+
import json
7+
import argparse
8+
import os
9+
10+
def parse_args():
11+
global args
12+
parser = argparse.ArgumentParser(description='Update a Unity project manifest to point to the local package version.')
13+
parser.add_argument('--manifest-path', required=True, help='The absolute path to the project manifest.json file.')
14+
parser.add_argument('--package-name', default="com.unity.netcode.gameobjects", help="The name of the package to modify in the manifest.")
15+
parser.add_argument('--local-package-path', required=True, help='The absolute file path to the local package source directory.')
16+
args = parser.parse_args()
17+
18+
def main():
19+
"""
20+
Updates a project's manifest.json to use package under passed local-package-path,
21+
and then prints the version of that local package.
22+
"""
23+
parse_args()
24+
25+
# Update the target project's manifest
26+
try:
27+
with open(args.manifest_path, 'r') as f:
28+
manifest_data = json.load(f)
29+
30+
local_path_normalized = args.local_package_path.replace(os.sep, '/')
31+
manifest_data["dependencies"][args.package_name] = f"file:{local_path_normalized}"
32+
33+
with open(args.manifest_path, 'w') as f:
34+
json.dump(manifest_data, f, indent=4)
35+
36+
print(f"Successfully updated manifest at '{args.manifest_path}'")
37+
print(f"Set '{args.package_name}' to use local package at '{args.local_package_path}'")
38+
except Exception as e:
39+
print(f"Error updating manifest: {e}")
40+
exit(1)
41+
42+
# --- Read and report the local package's version for log confirmation---
43+
# This is only for debug purposes
44+
try:
45+
# Construct the path to the local package's package.json file
46+
local_package_json_path = os.path.join(args.local_package_path, 'package.json')
47+
48+
with open(local_package_json_path, 'r') as f:
49+
local_package_data = json.load(f)
50+
51+
# Extract the version, providing a default if not found
52+
local_package_version = local_package_data.get('version', 'N/A')
53+
54+
print(f"--> Verified local '{args.package-name}' version is: {local_package_version}")
55+
56+
except FileNotFoundError:
57+
print(f"Warning: Could not find package.json at '{local_package_json_path}'")
58+
except Exception as e:
59+
print(f"Error reading local package version: {e}")
60+
61+
if __name__ == "__main__":
62+
main()

0 commit comments

Comments
 (0)