From 56c81fc699bf49d16f991896d1878a7458c6a327 Mon Sep 17 00:00:00 2001 From: Jared White Date: Sat, 21 Dec 2024 22:34:06 -0800 Subject: [PATCH] Remove legacy `doctor` command --- .../lib/bridgetown-core/commands/doctor.rb | 147 ------------------ bridgetown-core/test/test_doctor_command.rb | 41 ----- .../src/_docs/command-line-usage.md | 3 +- 3 files changed, 1 insertion(+), 190 deletions(-) delete mode 100644 bridgetown-core/lib/bridgetown-core/commands/doctor.rb delete mode 100644 bridgetown-core/test/test_doctor_command.rb diff --git a/bridgetown-core/lib/bridgetown-core/commands/doctor.rb b/bridgetown-core/lib/bridgetown-core/commands/doctor.rb deleted file mode 100644 index f3c032fa4..000000000 --- a/bridgetown-core/lib/bridgetown-core/commands/doctor.rb +++ /dev/null @@ -1,147 +0,0 @@ -# frozen_string_literal: true - -module Bridgetown - module Commands - class Doctor < Thor::Group - extend BuildOptions - extend Summarizable - include ConfigurationOverridable - - Registrations.register do - register(Doctor, "doctor", "doctor", Doctor.summary) - end - - def self.banner - "bridgetown doctor [options]" - end - summary "Search site and print specific deprecation warnings" - - def doctor - site = Bridgetown::Site.new(configuration_with_overrides(options)) - site.reset - site.read - site.generate - - if healthy?(site) - Bridgetown.logger.info "Your test results", "are in. Everything looks fine." - else - abort - end - end - - protected - - def healthy?(site) - [ - !conflicting_urls(site), - !urls_only_differ_by_case(site), - proper_site_url?(site), - properly_gathered_posts?(site), - ].all? - end - - def properly_gathered_posts?(site) - return true if site.config["collections_dir"].empty? - - posts_at_root = site.in_source_dir("_posts") - return true unless File.directory?(posts_at_root) - - Bridgetown.logger.warn "Warning:", - "Detected '_posts' directory outside custom `collections_dir`!" - Bridgetown.logger.warn "", - "Please move '#{posts_at_root}' into the custom directory at " \ - "'#{site.in_source_dir(site.config["collections_dir"])}'" - false - end - - def conflicting_urls(site) - conflicting_urls = false - urls = {} - urls = collect_urls(urls, site.contents, site.dest) - urls.each do |url, paths| - next unless paths.size > 1 - - conflicting_urls = true - Bridgetown.logger.warn "Conflict:", "The URL '#{url}' is the destination " \ - "for the following pages: #{paths.join(", ")}" - end - conflicting_urls - end - - def urls_only_differ_by_case(site) - urls_only_differ_by_case = false - urls = case_insensitive_urls(site.resources, site.dest) - urls.each_value do |real_urls| - next unless real_urls.uniq.size > 1 - - urls_only_differ_by_case = true - Bridgetown.logger.warn( - "Warning:", - "The following URLs only differ by case. On a case-insensitive file system one of " \ - "the URLs will be overwritten by the other: #{real_urls.join(", ")}" - ) - end - urls_only_differ_by_case - end - - def proper_site_url?(site) - url = site.config["url"] - [ - url_exists?(url), - url_valid?(url), - url_absolute(url), - ].all? - end - - private - - def collect_urls(urls, things, destination) - things.each do |thing| - dest = thing.method(:destination).arity == 1 ? - thing.destination(destination) : - thing.destination - if urls[dest] - urls[dest] << thing.path - else - urls[dest] = [thing.path] - end - end - urls - end - - def case_insensitive_urls(things, _destination) - things.each_with_object({}) do |thing, memo| - dest = thing.destination&.output_path - (memo[dest.downcase] ||= []) << dest if dest - end - end - - def url_exists?(url) - return true unless url.nil? || url.empty? - - Bridgetown.logger.warn "Warning:", "You didn't set an URL in the config file, " \ - "you may encounter problems with some plugins." - false - end - - def url_valid?(url) - Addressable::URI.parse(url) - true - # Addressable::URI#parse only raises a TypeError - # https://git.io/vFfbx - rescue TypeError - Bridgetown.logger.warn "Warning:", "The site URL does not seem to be valid, " \ - "check the value of `url` in your config file." - false - end - - def url_absolute(url) - return true if url.is_a?(String) && Addressable::URI.parse(url).absolute? - - Bridgetown.logger.warn "Warning:", "Your site URL does not seem to be absolute, " \ - "check the value of `url` in your config file." - false - end - end - end -end diff --git a/bridgetown-core/test/test_doctor_command.rb b/bridgetown-core/test/test_doctor_command.rb deleted file mode 100644 index db735e6c3..000000000 --- a/bridgetown-core/test/test_doctor_command.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require "helper" -require_all "bridgetown-core/commands/concerns" -require "bridgetown-core/commands/doctor" - -class TestDoctorCommand < BridgetownUnitTest - context "URLs only differ by case" do - setup do - clear_dest - end - - should "return success on a valid site/page" do - @site = Site.new(Bridgetown.configuration( - "source" => File.join(source_dir, "/_urls_differ_by_case_valid"), - "destination" => dest_dir - )) - @site.process - output = capture_stderr do - ret = Bridgetown::Commands::Doctor.new.send(:urls_only_differ_by_case, @site) - assert_equal false, ret - end - assert_equal "", output - end - - should "return warning for pages only differing by case" do - @site = Site.new(Bridgetown.configuration( - "source" => File.join(source_dir, "/_urls_differ_by_case_invalid"), - "destination" => dest_dir - )) - @site.process - output = capture_stderr do - ret = Bridgetown::Commands::Doctor.new.send(:urls_only_differ_by_case, @site) - assert_equal true, ret - end - assert_includes output, "Warning: The following URLs only differ by case. " \ - "On a case-insensitive file system one of the URLs will be overwritten by the " \ - "other: #{dest_dir}/about/index.html, #{dest_dir}/About/index.html" - end - end -end diff --git a/bridgetown-website/src/_docs/command-line-usage.md b/bridgetown-website/src/_docs/command-line-usage.md index fecf392f8..335e8d140 100644 --- a/bridgetown-website/src/_docs/command-line-usage.md +++ b/bridgetown-website/src/_docs/command-line-usage.md @@ -17,7 +17,7 @@ Available commands are: * `bridgetown new PATH` - Creates a new Bridgetown site at the specified path with a default configuration and typical site folder structure. * Use the `--apply=` or `-a` option to [apply an automation](/docs/automations) to the new site. * Use the `--configure=` or `-c` option to [apply one or more bundled configurations](/docs/bundled-configurations) to the new site. - * Use the `-t` option to choose ERB or Serbea templates instead of Liquid (aka `-t erb`). + * Use the `-t` option to choose Serbea or Liquid templates instead of ERB (aka `-t serbea`). * Use the `--use-sass` option to configure your project to support Sass. * `bin/bridgetown start` or `s` - Boots the Rack-based server (using Puma) at `localhost:4000`. In development, you'll get live reload functionality as long as `{% live_reload_dev_js %}` or `<%= live_reload_dev_js %>` is in your HTML head. * `bin/bridgetown deploy` - Ensures that all frontend assets get built alongside the published Bridgetown output. This is the command you'll want to use for [deployment](/docs/deployment). @@ -29,7 +29,6 @@ Available commands are: * `bin/bridgetown configure CONFIGURATION` - Run a [bundled configuration](/docs/bundled-configurations) for your existing site. Invoke without arguments to see all available configurations. * `bin/bridgetown date` - Displays the current date and time so you can copy'n'paste it into your front matter. * `bin/bridgetown help` - Shows help, optionally for a given subcommand, e.g. `bridgetown help build`. -* `bin/bridgetown doctor` - Outputs any deprecation or configuration issues. * `bin/bridgetown clean` - Removes all generated files: destination folder, metadata file, and Bridgetown caches. * `bin/bridgetown esbuild ACTION` - Allows you to perform actions such as `update` on your project's esbuild configuration. Invoke without arguments to see all available actions. {% endraw %}