Skip to content

Commit

Permalink
Generate consolidated manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovenoboyo committed Dec 27, 2024
1 parent 19c4137 commit de47979
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
- name: build extensions
run: make

- name: Generate manifest
run: python3 gen-manifest.py

- name: Get release name
id: date
run: |
Expand All @@ -70,7 +73,7 @@ jobs:
const release = await github.repos.createRelease({
owner, repo,
tag_name: `release-${sha}`,
draft: true,
draft: false,
target_commitish: sha
});
Expand Down
60 changes: 60 additions & 0 deletions gen-manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import json

def find_and_consolidate_package_json():
# Get the current directory
current_dir = os.getcwd()

# Dictionary to store consolidated data
consolidated_data = {}

# Traverse through all directories in the current directory, depth = 1
for root, dirs, files in os.walk(current_dir):
# Limit depth to 1 by filtering subdirectories
if root != current_dir:
del dirs[:]

if 'package.json' in files:
package_json_path = os.path.join(root, 'package.json')
print(f"Found package.json at: {package_json_path}")

# Parse the package.json file
try:
with open(package_json_path, 'r', encoding='utf-8') as file:
package_data = json.load(file)

# Extract required fields
name = package_data.get('name')
if name:
# Resolve the icon path relative to current_dir if it exists
icon = package_data.get("icon")
if icon:
icon = os.path.relpath(os.path.join(root, icon), current_dir)

consolidated_data[name] = {
"displayName": package_data.get("displayName"),
"version": package_data.get("version"),
"icon": icon,
"permissions": package_data.get("permissions", [])
}

except json.JSONDecodeError as e:
print(f"Error decoding JSON from {package_json_path}: {e}")
except Exception as e:
print(f"Error reading {package_json_path}: {e}")

# Create the output directory
output_dir = os.path.join(current_dir, 'dist')
os.makedirs(output_dir, exist_ok=True)

# Output the consolidated data to a JSON file
output_file = os.path.join(output_dir, 'manifest.json')
try:
with open(output_file, 'w', encoding='utf-8') as outfile:
json.dump(consolidated_data, outfile, indent=4)
print(f"Consolidated data written to {output_file}")
except Exception as e:
print(f"Error writing consolidated data to file: {e}")

if __name__ == "__main__":
find_and_consolidate_package_json()

0 comments on commit de47979

Please sign in to comment.