From 95451bb68ba33cac614e007c78edeb7a9403fddb Mon Sep 17 00:00:00 2001 From: Matt Troutman Date: Mon, 19 May 2025 12:03:22 -0500 Subject: [PATCH] Add Homebrew formula generator script for font installation --- .fontfoldercleanup/create_homebrew_formula.py | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 .fontfoldercleanup/create_homebrew_formula.py diff --git a/.fontfoldercleanup/create_homebrew_formula.py b/.fontfoldercleanup/create_homebrew_formula.py new file mode 100755 index 0000000..a85f5db --- /dev/null +++ b/.fontfoldercleanup/create_homebrew_formula.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +import os +from pathlib import Path + +class HomebrewFormulaGenerator: + def __init__(self, fonts_dir): + self.fonts_dir = Path(fonts_dir) + self.formula_dir = self.fonts_dir.parent / 'Formula' + self.formula_dir.mkdir(exist_ok=True) + + def generate_formula_content(self, font_name, formula_name): + """Generate the Ruby formula content for a font.""" + return f'''# typed: false +# frozen_string_literal: true + +# This file was generated by the font folder cleanup script +# Do not edit this file directly + +class {formula_name.capitalize()} < Formula + desc "Font: {formula_name}" + homepage "https://github.com/your-username/homebrew-fonts" + version "1.0.0" + + def install + # Create font directories + (share/"fonts").mkpath + (share/"fonts/truetype").mkpath + (share/"fonts/opentype").mkpath + (share/"fonts/webfonts").mkpath + + # Install TTF fonts + Dir.glob("{font_name}/ttf/*.ttf").each do |font| + system "cp", font, share/"fonts/truetype" + end + + # Install OTF fonts + Dir.glob("{font_name}/otf/*.otf").each do |font| + system "cp", font, share/"fonts/opentype" + end + + # Install web fonts + Dir.glob("{font_name}/web/*.{{woff,woff2,eot,svg}}").each do |font| + system "cp", font, share/"fonts/webfonts" + end + + # Install documentation and other files + (share/"{formula_name}").mkpath + Dir.glob("{font_name}/other_files/*").each do |file| + system "cp", "-r", file, share/"{formula_name}" + end + end + + def caveats + <<~EOS + Fonts have been installed to: + #{'{share}/fonts/truetype'} + #{'{share}/fonts/opentype'} + #{'{share}/fonts/webfonts'} + + Additional files are available in: + #{'{share}/' + formula_name} + EOS + end + + test do + # Verify font installation + assert_predicate share/"fonts/truetype", :directory? + assert_predicate share/"fonts/opentype", :directory? + assert_predicate share/"fonts/webfonts", :directory? + end +end +''' + + def generate_formulas(self): + """Generate Homebrew formulas for all font folders.""" + for font_dir in self.fonts_dir.glob('font-*'): + if not font_dir.is_dir(): + continue + + font_name = font_dir.name + formula_name = font_name.replace('font-', '') + formula_content = self.generate_formula_content(font_name, formula_name) + + formula_path = self.formula_dir / f"{formula_name}.rb" + formula_path.write_text(formula_content) + print(f"Generated formula for {formula_name}") + +def main(): + # Get the absolute path to the font_files directory + script_dir = Path(__file__).parent + fonts_dir = script_dir.parent / 'font_files' + + if not fonts_dir.exists(): + print(f"Error: Font directory not found: {fonts_dir}") + return + + generator = HomebrewFormulaGenerator(fonts_dir) + generator.generate_formulas() + +if __name__ == "__main__": + main() \ No newline at end of file