From 647835a5dec8e9d7279fff90fe7c62e3c4144def Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Wed, 15 Feb 2023 09:35:41 +0100 Subject: [PATCH] Introduce `--update-docs` flag to synchronously update Theme Check resources (objects, filters, and tags) (#707) --- lib/theme_check/cli.rb | 15 +++++++++++++++ test/cli_test.rb | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/theme_check/cli.rb b/lib/theme_check/cli.rb index 4a76f1b7..4b18672e 100644 --- a/lib/theme_check/cli.rb +++ b/lib/theme_check/cli.rb @@ -15,6 +15,7 @@ def initialize @include_categories = [] @exclude_categories = [] @auto_correct = false + @update_docs = false @config_path = nil @fail_level = :error @format = :text @@ -65,6 +66,10 @@ def option_parser(parser = OptionParser.new, help: true) "--print", "Output active config to STDOUT" ) { @command = :print } + @option_parser.on( + "--update-docs", + "Update Theme Check docs (objects, filters, and tags)" + ) { @update_docs = true } @option_parser.on( "-h", "--help", "Show this. Hi!" @@ -181,6 +186,8 @@ def help end def check(out_stream = STDOUT) + update_docs + STDERR.puts "Checking #{@config.root} ..." storage = ThemeCheck::FileSystemStorage.new(@config.root, ignored_patterns: @config.ignored_patterns) theme = ThemeCheck::Theme.new(storage) @@ -199,6 +206,14 @@ def check(out_stream = STDOUT) end end + def update_docs + return unless @update_docs + + puts 'Updating documentation...' + + ThemeCheck::ShopifyLiquid::SourceManager.download + end + def profile require 'ruby-prof-flamegraph' diff --git a/test/cli_test.rb b/test/cli_test.rb index 7b8e7e86..8d067af4 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -175,6 +175,25 @@ def test_list assert_includes(out, "LiquidTag:") end + def test_update_docs + ThemeCheck::ShopifyLiquid::SourceManager.expects(:download) + + storage = make_file_system_storage( + 'layout/theme.liquid' => '', + '.theme-check.yml' => <<~YAML, + extends: :nothing + RequiredDirectories: + enabled: false + YAML + ) + + out, _err = capture_io do + ThemeCheck::Cli.parse_and_run!([storage.root, '--update-docs']) + end + + assert_includes(out, 'Updating documentation...') + end + def test_auto_correct storage = make_file_system_storage( "templats/theme.liquid" => <<~LIQUID,