BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

modules_to_plugin_json.rb (1261B)


      1 #!/usr/bin/ruby
      2 
      3 require 'JSON'
      4 
      5 plugin_json = File.read("plugin.json")
      6 plugin = JSON.parse(plugin_json)
      7 
      8 flags = []
      9 flags << '-DTEST=1' if ENV['TEST']
     10 flags << '-DEXPERIMENTAL=1' if ENV['EXPERIMENTAL']
     11 models = `c++ #{flags.join(' ')} -E src/bogaudio.cpp 2>&1 | grep addModel`
     12 models = models.split.map do |s|
     13   s.sub(/^\s*p->addModel\(([^)]+)\);\s*$/, '\1')
     14 end
     15 
     16 modules = []
     17 models.each do |model|
     18   create = `grep -in #{model} src/*cpp | grep createModel`
     19   if create =~ /createModel.*?\("([^"]+)",\s*"([^"]+)",\s*"([^"]*)"(?:,\s*([^)]*))?\);/
     20     slug = $1
     21     name = $2
     22     description = $3
     23     tags = $4
     24     if tags
     25       tags = tags.split(/,\s+/).map { |t| t.sub(/^\s*"([^"]+)"\s*$/, '\1') }
     26     else
     27       tags = []
     28     end
     29     anchor = slug.sub(/^Bogaudio-/, '').downcase
     30 
     31     modules << {
     32       slug: slug,
     33       name: name,
     34       description: description,
     35       manualUrl: 'https://github.com/bogaudio/BogaudioModules/blob/master/README.md#' + anchor,
     36       tags: tags
     37     }
     38   else
     39     STDERR.puts "Failed to get create line for #{model}"
     40     exit 1
     41   end
     42 end
     43 
     44 plugin['modules'] = modules
     45 File.write('plugin.json.bak', plugin_json)
     46 puts 'wrote plugin.json.bak'
     47 File.write('plugin.json', JSON.pretty_generate(plugin) + "\n")
     48 puts "wrote plugin.json"