Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Commit

Permalink
Introduce --update-docs flag to synchronously update Theme Check re…
Browse files Browse the repository at this point in the history
…sources (objects, filters, and tags) (#707)
  • Loading branch information
karreiro authored Feb 15, 2023
1 parent 3eba126 commit 647835a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/theme_check/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize
@include_categories = []
@exclude_categories = []
@auto_correct = false
@update_docs = false
@config_path = nil
@fail_level = :error
@format = :text
Expand Down Expand Up @@ -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!"
Expand Down Expand Up @@ -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)
Expand All @@ -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'

Expand Down
19 changes: 19 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 647835a

Please sign in to comment.