#!/usr/bin/env ruby require_relative 'lib/makeplugin/plugin_description_template' require_relative 'lib/makeplugin/plugin_info' def make_param_assigns(ctrl_ports) ctrl_ports .map.with_index { |p, n| "#{p[:sym]} = *param[#{n}];" } .join("\n ") end if ARGV.length < 1 puts "Usage: #{__FILE__} " exit end root = File.dirname(__FILE__) plugin_name = ARGV[0] target_dir = File.join(root, 'src', plugin_name) template_dir = File.join(root, 'Template') puts "Reading plugin info from cheatsheet..." pi = MakePlugin::PluginInfo.new(root, plugin_name) puts "Creating plugin #{pi.name}..." puts "Type: #{pi.type} (#{pi.raw_type})" puts "CTRL ports: #{pi.ctrl_ports.length}" Templates = %w{ manifest.ttl.in Plugin.h Plugin.cpp } begin Dir.mkdir(target_dir) plugin_ttl = MakePlugin::PluginDescriptionTemplate.new(template_dir, pi) IO.write(File.join(target_dir, plugin_ttl.filename), plugin_ttl.render) Templates.each do |t| tpl = IO.read(File.join(template_dir, t)) .gsub('@Plugin@', pi.name) .gsub('@plugin@', pi.slug) .gsub('@NCtrlPorts@', pi.n_ctrl_ports.to_s) .gsub('@AssignParams@', make_param_assigns(pi.ctrl_ports)) .gsub('@VARDECLS@', pi.var_decls.join("\n")) fname = t.sub('Plugin', pi.name) puts " - #{fname}..." File.open(File.join(target_dir, fname), "w") do |f| f.write(tpl) end end rescue SystemCallError => e puts "Could not create plugin: #{e}" puts "Aborting!" end