Class: Fontist::Import::V4ToV5Migrator
- Inherits:
-
Object
- Object
- Fontist::Import::V4ToV5Migrator
- Defined in:
- lib/fontist/import/v4_to_v5_migrator.rb
Overview
Migrate v4 formulas to v5 schema
This script converts existing v4 formula files to v5 format by:
-
Adding schema_version: 5
-
Detecting format from file extensions in resources
-
Detecting variable fonts from filename patterns
Usage:
Fontist::Import::V4ToV5Migrator.new(input_path, output_path).migrate_all
Constant Summary collapse
- FONT_EXTENSIONS =
%w[ttf otf woff woff2 ttc otc dfont].freeze
- ARCHIVE_EXTENSIONS =
%w[zip tar gz tgz bz2 7z rar exe cab].freeze
Instance Method Summary collapse
-
#initialize(input_path, output_path = nil, options = {}) ⇒ V4ToV5Migrator
constructor
A new instance of V4ToV5Migrator.
-
#migrate_all ⇒ Hash
Migrate all formulas in the input path.
-
#migrate_file(path) ⇒ Symbol
Migrate a single formula file.
Constructor Details
#initialize(input_path, output_path = nil, options = {}) ⇒ V4ToV5Migrator
Returns a new instance of V4ToV5Migrator.
22 23 24 25 26 27 |
# File 'lib/fontist/import/v4_to_v5_migrator.rb', line 22 def initialize(input_path, output_path = nil, = {}) @input_path = input_path @output_path = output_path || input_path @verbose = [:verbose] @dry_run = [:dry_run] end |
Instance Method Details
#migrate_all ⇒ Hash
Migrate all formulas in the input path
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fontist/import/v4_to_v5_migrator.rb', line 32 def migrate_all results = { migrated: 0, skipped: 0, failed: 0, errors: [] } files = formula_files log "Found #{files.size} formula file(s) to process" files.each do |path| result = migrate_file(path) case result when :migrated results[:migrated] += 1 when :skipped results[:skipped] += 1 end rescue StandardError => e results[:failed] += 1 results[:errors] << { formula: path, error: e. } log "✗ Failed #{File.basename(path)}: #{e.}" end log_summary(results) results end |
#migrate_file(path) ⇒ Symbol
Migrate a single formula file
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fontist/import/v4_to_v5_migrator.rb', line 60 def migrate_file(path) formula_data = load_yaml_without_aliases(path) already_v5 = formula_data["schema_version"] == 5 # Add schema_version: 5 formula_data = add_schema_version(formula_data) unless already_v5 # Check if the raw file contains YAML aliases that need resolving changed = file_has_yaml_aliases?(path) changed |= upgrade_resources(formula_data) if formula_data["resources"] # Nothing to do if already v5 and no fixes needed if already_v5 && !changed log " Already v5: #{File.basename(path)}" return :skipped end # Calculate output path output_file = output_path_for(path) # Save if not dry run if @dry_run log " Would save: #{output_file}" else FileUtils.mkdir_p(File.dirname(output_file)) File.write(output_file, YAML.dump(formula_data)) log " Saved: #{output_file}" end :migrated end |