exe/parlour in parlour-4.0.1 vs exe/parlour in parlour-5.0.0.beta.1

- old
+ new

@@ -23,13 +23,38 @@ configuration = keys_to_symbols(YAML.load_file(config_filename)) else configuration = {} end - # Output default - configuration[:output_file] ||= "rbi/#{File.basename(working_dir)}.rbi" + # Output file + if configuration[:output_file].is_a?(String) + assumed_format = \ + if configuration[:output_file].end_with?('.rbi') + :rbi + elsif configuration[:output_file].end_with?('.rbs') + :rbs + else + raise 'invalid output file; please specify an RBI or RBS file' + end + unless $VERBOSE.nil? + print Rainbow("Parlour warning: ").yellow.dark.bold + print Rainbow("CLI: ").magenta.bright.bold + puts "Specifying output_file in .parlour as a string is deprecated." + puts "For now, generating an #{assumed_format.to_s.upcase} file based on the file extension." + puts "Please update your .parlour to use the new form:" + puts " output_file:" + puts " #{assumed_format}: #{configuration[:output_file]}" + end + configuration[:output_file] = { + assumed_format => configuration[:output_file] + } + end + configuration[:output_file] ||= { + rbi: "rbi/#{File.basename(working_dir)}.rbi" + } + # Style defaults configuration[:style] ||= {} configuration[:style][:tab_size] ||= 2 configuration[:style][:break_params] ||= 4 @@ -43,11 +68,11 @@ # Included/Excluded path defaults configuration[:parser][:included_paths] ||= ['lib'] configuration[:parser][:excluded_paths] ||= ['sorbet', 'spec'] # Defaults can be overridden but we always want to exclude the output file - configuration[:parser][:excluded_paths] << configuration[:output_file] + configuration[:parser][:excluded_paths] << configuration[:output_file][:rbi] end # Included/Excluded module defaults configuration[:included_modules] ||= [] configuration[:excluded_modules] ||= [] @@ -139,12 +164,26 @@ else puts Rainbow('Note: ').yellow.bold + "Plugins specified multiple strictness levels, chose the weakest (#{strictness})" end end - # Write the final RBI - FileUtils.mkdir_p(File.dirname(configuration[:output_file])) - File.write(configuration[:output_file], gen.rbi(strictness)) + # Write the final files + if configuration[:output_file][:rbi] + FileUtils.mkdir_p(File.dirname(configuration[:output_file][:rbi])) + File.write(configuration[:output_file][:rbi], gen.rbi(strictness)) + end + if configuration[:output_file][:rbs] + gen.root.generalize_from_rbi! + rbs_gen = Parlour::RbsGenerator.new + + converter = Parlour::Conversion::RbiToRbs.new(rbs_gen) + gen.root.children.each do |child| + converter.convert_object(child, rbs_gen.root) + end + + FileUtils.mkdir_p(File.dirname(configuration[:output_file][:rbs])) + File.write(configuration[:output_file][:rbs], rbs_gen.rbs) + end end end private