refactor: restructure dist/ and implement aggregated Zed theme
- Updated build.py to support app-centric directory structure (dist/<app>/). - Modified build.py to allow aggregated multi-scheme rendering (for Zed). - Refactored Zed template to include both Neon and Aeon variants in a single JSON. - Standardized theme file naming in dist/.
This commit is contained in:
87
build.py
87
build.py
@@ -6,7 +6,7 @@ from jinja2 import Environment, FileSystemLoader
|
||||
SRC_DIR = 'src'
|
||||
TEMPLATES_DIR = 'templates'
|
||||
DIST_DIR = 'dist'
|
||||
SCHEMES = ['neon.yaml', 'aeon.yaml']
|
||||
SCHEME_FILES = ['neon.yaml', 'aeon.yaml']
|
||||
|
||||
def load_scheme(filename):
|
||||
with open(os.path.join(SRC_DIR, filename), 'r') as f:
|
||||
@@ -18,47 +18,72 @@ def render_template(template_path, context):
|
||||
return template.render(context)
|
||||
|
||||
def build():
|
||||
# Load all schemes first
|
||||
schemes = []
|
||||
for f in SCHEME_FILES:
|
||||
schemes.append(load_scheme(f))
|
||||
|
||||
# Ensure dist directory exists
|
||||
if not os.path.exists(DIST_DIR):
|
||||
os.makedirs(DIST_DIR)
|
||||
|
||||
for scheme_file in SCHEMES:
|
||||
scheme_data = load_scheme(scheme_file)
|
||||
scheme_name_slug = scheme_data['scheme'].lower().replace(' ', '-')
|
||||
print(f"Building {scheme_data['scheme']}...")
|
||||
# Walk through templates
|
||||
for root, dirs, files in os.walk(TEMPLATES_DIR):
|
||||
for file in files:
|
||||
if not file.endswith('.j2'):
|
||||
continue
|
||||
|
||||
# Find all templates
|
||||
for root, dirs, files in os.walk(TEMPLATES_DIR):
|
||||
for file in files:
|
||||
if file.endswith('.j2'):
|
||||
# Calculate relative path to mirror structure in dist
|
||||
rel_path = os.path.relpath(root, TEMPLATES_DIR)
|
||||
template_rel_path = os.path.join(rel_path, file)
|
||||
rel_path = os.path.relpath(root, TEMPLATES_DIR)
|
||||
app_name = rel_path # e.g., 'nvim', 'zed', 'kitty'
|
||||
|
||||
template_rel_path = os.path.join(rel_path, file)
|
||||
output_filename_base = file.replace('.j2', '')
|
||||
|
||||
# Create app directory in dist
|
||||
app_dist_dir = os.path.join(DIST_DIR, app_name)
|
||||
if not os.path.exists(app_dist_dir):
|
||||
os.makedirs(app_dist_dir)
|
||||
|
||||
print(f"Processing template: {template_rel_path}")
|
||||
|
||||
# Special case for Zed: Aggregated output (single JSON for all themes)
|
||||
if app_name == 'zed':
|
||||
context = {'schemes': schemes}
|
||||
rendered_content = render_template(template_rel_path, context)
|
||||
|
||||
# Output file: dist/zed/apex.json (matches base name)
|
||||
output_path = os.path.join(app_dist_dir, output_filename_base)
|
||||
|
||||
with open(output_path, 'w') as f:
|
||||
f.write(rendered_content)
|
||||
print(f" -> {output_path} (Aggregated)")
|
||||
|
||||
# Default behavior: Per-scheme output
|
||||
else:
|
||||
for scheme in schemes:
|
||||
scheme_slug = scheme['scheme'].lower().replace(' ', '-')
|
||||
|
||||
# Prepare output path
|
||||
output_filename = file.replace('.j2', '')
|
||||
# If the template is generic (apex.lua), rename it to the scheme name (apex-neon.lua)
|
||||
if 'apex' in output_filename:
|
||||
output_filename = output_filename.replace('apex', scheme_name_slug)
|
||||
# Rename output file: e.g., apex.conf -> apex-neon.conf
|
||||
# or apex.lua -> apex-neon.lua
|
||||
# If filename is generic 'apex', replace with slug.
|
||||
# If filename is 'apex.lua', result 'apex-neon.lua'
|
||||
|
||||
output_dir = os.path.join(DIST_DIR, scheme_name_slug, rel_path)
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
if 'apex' in output_filename_base:
|
||||
final_filename = output_filename_base.replace('apex', f"apex-{scheme_slug.replace('apex-', '')}")
|
||||
else:
|
||||
final_filename = f"{scheme_slug}-{output_filename_base}"
|
||||
|
||||
# Clean up double prefixes if any (e.g. apex-apex-neon)
|
||||
final_filename = final_filename.replace('apex-apex-', 'apex-')
|
||||
|
||||
output_path = os.path.join(app_dist_dir, final_filename)
|
||||
|
||||
output_path = os.path.join(output_dir, output_filename)
|
||||
|
||||
# Render and write
|
||||
# We pass template_rel_path because jinja loader is rooted at TEMPLATES_DIR
|
||||
# But os.walk returns paths relative to CWD usually, but we constructed it.
|
||||
# Actually Environment loader is correct. We just need the path relative to templates dir.
|
||||
template_name_for_jinja = template_rel_path
|
||||
|
||||
rendered_content = render_template(template_name_for_jinja, scheme_data)
|
||||
rendered_content = render_template(template_rel_path, scheme)
|
||||
|
||||
with open(output_path, 'w') as f:
|
||||
f.write(rendered_content)
|
||||
|
||||
print(f" -> {output_path}")
|
||||
print(f" -> {output_path} ({scheme['scheme']})")
|
||||
|
||||
if __name__ == '__main__':
|
||||
build()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user