From eae887561d50450dfb6e6cd0ef0b252942446af4 Mon Sep 17 00:00:00 2001 From: Pepijn Van Eeckhoudt Date: Mon, 22 Jan 2024 08:31:48 +0100 Subject: [PATCH] #453 Improve error message when WaveDrom cannot be located --- CHANGELOG.adoc | 4 ++ .../ROOT/pages/diagram_types/wavedrom.adoc | 2 +- lib/asciidoctor-diagram/wavedrom/converter.rb | 67 ++++++++++--------- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index d9308eda..7000c3dd 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -2,6 +2,10 @@ == 2.2.15 +Enhacements:: + +* Issue #453: Improve error message when WaveDrom cannot be located + Bugfixes:: * Issue #428: Improve support for reading UTF-16 encoded source files diff --git a/docs/modules/ROOT/pages/diagram_types/wavedrom.adoc b/docs/modules/ROOT/pages/diagram_types/wavedrom.adoc index 70359e3b..e33c9828 100644 --- a/docs/modules/ROOT/pages/diagram_types/wavedrom.adoc +++ b/docs/modules/ROOT/pages/diagram_types/wavedrom.adoc @@ -13,5 +13,5 @@ include::partial$uris.adoc[] [cols=">,<,<",options="header"] |=== |Name |Default value |Description -|wavedrom |wavedrom |The path to the `wavedrom` executable +|wavedrom |wavedrom |The path to the `wavedrom-cli` or `wavedrom` executable |=== \ No newline at end of file diff --git a/lib/asciidoctor-diagram/wavedrom/converter.rb b/lib/asciidoctor-diagram/wavedrom/converter.rb index 27ed6579..c59ab216 100644 --- a/lib/asciidoctor-diagram/wavedrom/converter.rb +++ b/lib/asciidoctor-diagram/wavedrom/converter.rb @@ -9,48 +9,53 @@ class WavedromConverter include DiagramConverter include CliGenerator - def supported_formats [:png, :svg] end - def convert(source, format, options) - wavedrom_cli = source.find_command('wavedrom-cli', :raise_on_error => false) - if wavedrom_cli - generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path| + wavedrom = source.find_command('wavedrom-cli', :attrs => ['wavedrom'], :raise_on_error => false) + + unless wavedrom + wavedrom = source.find_command('wavedrom', :raise_on_error => false) + end + + unless wavedrom + if ::Asciidoctor::Diagram::Platform.os == :macosx + wavedrom = source.find_command('WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'], :path => ['/Applications'], :raise_on_error => false) + if wavedrom + wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs') + end + else + wavedrom = source.find_command('WaveDromEditor', :raise_on_error => false) + end + end + + unless wavedrom + source.find_command('wavedrom-cli', :attrs => ['wavedrom']) + end + + if wavedrom.end_with?('-cli') + generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path| { :args => [Platform.native_path(tool_path), '--input', Platform.native_path(input_path), "--#{format.to_s}", Platform.native_path(output_path)], :chdir => source.base_dir } end + elsif wavedrom.include?('WaveDromEditor') + generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path| + { + :args => [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)], + :chdir => source.base_dir + } + end else - wavedrom_cli = source.find_command('wavedrom', :raise_on_error => false) - phantomjs = source.find_command('phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false) - - if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs - generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path| - { - :args => [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)], - :chdir => source.base_dir - } - end - else - if ::Asciidoctor::Diagram::Platform.os == :macosx - wavedrom = source.find_command('WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'], :path => ['/Applications']) - if wavedrom - wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs') - end - else - wavedrom = source.find_command('WaveDromEditor') - end - - generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path| - { - :args => [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)], - :chdir => source.base_dir - } - end + phantomjs = source.find_command('phantomjs', :alt_attrs => ['phantomjs_2']) + generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path| + { + :args => [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)], + :chdir => source.base_dir + } end end end