Skip to content

Commit

Permalink
Use theme id as file namme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovenoboyo committed Dec 30, 2024
1 parent dd403c7 commit 80f7f42
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ jobs:
console.log('created release', { release });
for (let file of await fs.readdir('./')) {
for (let file of await fs.readdir('./dist/')) {
if (file.endsWith('.mstx') || file.endsWith('.json')) {
console.log('uploading', file);
await github.repos.uploadReleaseAsset({
owner, repo,
release_id: release.data.id,
name: file,
data: await fs.readFile(`./${file}`)
data: await fs.readFile(`./dist/${file}`)
});
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.json
dist/*
24 changes: 17 additions & 7 deletions gen-manifest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os
import shutil
import zipfile
import json

# Directory path (current directory)
cwd = os.getcwd()

# Consolidated manifest
def consolidate_manifest():
manifest = {}

# Create 'dist' directory if it doesn't exist
dist_dir = os.path.join(cwd, 'dist')
os.makedirs(dist_dir, exist_ok=True)

# Iterate through all .mstx files in the directory
for file in os.listdir(cwd):
if file.endswith(".mstx"):
Expand All @@ -20,22 +24,28 @@ def consolidate_manifest():
# Extract and parse config.json
with zip_ref.open('config.json') as config_file:
config_data = json.load(config_file)
if 'customCSS' in config_data['theme']:
del config_data["theme"]["customCSS"]

# Remove 'customCSS' from 'theme' if it exists
if 'theme' in config_data and 'customCSS' in config_data['theme']:
del config_data['theme']['customCSS']

# Extract the id and use the entire config.json as value
if 'id' in config_data:
manifest[config_data['id']] = {}
manifest[config_data['id']]["data"] = config_data
id_value = config_data['id']
manifest[id_value] = {"data": config_data}

# Copy the .mstx file to the 'dist' directory with the new name
new_filename = f"{id_value}.mstx"
shutil.copy(file, os.path.join(dist_dir, new_filename))
else:
print(f"Warning: 'id' missing in {file}'s config.json")
except zipfile.BadZipFile:
print(f"Error: {file} is not a valid zip file.")
except Exception as e:
print(f"Error processing {file}: {e}")

# Write the consolidated manifest to manifest.json
manifest_path = os.path.join(cwd, 'manifest.json')
# Write the consolidated manifest to manifest.json in 'dist'
manifest_path = os.path.join(dist_dir, 'manifest.json')
with open(manifest_path, 'w') as manifest_file:
json.dump(manifest, manifest_file, indent=4)

Expand Down

0 comments on commit 80f7f42

Please sign in to comment.