bridgetown-core 0.12.0 → 0.15.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -1
  3. data/bin/bridgetown +9 -48
  4. data/bridgetown-core.gemspec +10 -5
  5. data/lib/bridgetown-core.rb +20 -4
  6. data/lib/bridgetown-core/cleaner.rb +1 -0
  7. data/lib/bridgetown-core/commands/apply.rb +73 -0
  8. data/lib/bridgetown-core/commands/base.rb +45 -0
  9. data/lib/bridgetown-core/commands/build.rb +91 -86
  10. data/lib/bridgetown-core/commands/clean.rb +30 -29
  11. data/lib/bridgetown-core/commands/concerns/actions.rb +95 -0
  12. data/lib/bridgetown-core/commands/concerns/build_options.rb +76 -0
  13. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +18 -0
  14. data/lib/bridgetown-core/commands/concerns/summarizable.rb +13 -0
  15. data/lib/bridgetown-core/commands/console.rb +46 -38
  16. data/lib/bridgetown-core/commands/doctor.rb +125 -135
  17. data/lib/bridgetown-core/commands/new.rb +120 -158
  18. data/lib/bridgetown-core/commands/plugins.rb +206 -0
  19. data/lib/bridgetown-core/commands/registrations.rb +16 -0
  20. data/lib/bridgetown-core/commands/serve.rb +214 -217
  21. data/lib/bridgetown-core/{convertible.rb → concerns/convertible.rb} +2 -2
  22. data/lib/bridgetown-core/concerns/site/configurable.rb +153 -0
  23. data/lib/bridgetown-core/concerns/site/content.rb +111 -0
  24. data/lib/bridgetown-core/concerns/site/extensible.rb +56 -0
  25. data/lib/bridgetown-core/concerns/site/processable.rb +74 -0
  26. data/lib/bridgetown-core/concerns/site/renderable.rb +50 -0
  27. data/lib/bridgetown-core/concerns/site/writable.rb +31 -0
  28. data/lib/bridgetown-core/configuration.rb +98 -108
  29. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +0 -3
  30. data/lib/bridgetown-core/document.rb +1 -1
  31. data/lib/bridgetown-core/drops/bridgetown_drop.rb +6 -1
  32. data/lib/bridgetown-core/drops/site_drop.rb +1 -2
  33. data/lib/bridgetown-core/external.rb +17 -21
  34. data/lib/bridgetown-core/filters.rb +10 -0
  35. data/lib/bridgetown-core/generators/prototype_generator.rb +3 -1
  36. data/lib/bridgetown-core/hooks.rb +62 -62
  37. data/lib/bridgetown-core/layout.rb +10 -4
  38. data/lib/bridgetown-core/liquid_renderer.rb +2 -0
  39. data/lib/bridgetown-core/liquid_renderer/file_system.rb +5 -1
  40. data/lib/bridgetown-core/page.rb +9 -2
  41. data/lib/bridgetown-core/plugin.rb +2 -0
  42. data/lib/bridgetown-core/plugin_manager.rb +68 -14
  43. data/lib/bridgetown-core/reader.rb +5 -0
  44. data/lib/bridgetown-core/readers/data_reader.rb +15 -2
  45. data/lib/bridgetown-core/readers/layout_reader.rb +9 -2
  46. data/lib/bridgetown-core/readers/plugin_content_reader.rb +48 -0
  47. data/lib/bridgetown-core/renderer.rb +51 -32
  48. data/lib/bridgetown-core/site.rb +20 -449
  49. data/lib/bridgetown-core/static_file.rb +1 -5
  50. data/lib/bridgetown-core/tags/include.rb +12 -0
  51. data/lib/bridgetown-core/tags/render_content.rb +27 -16
  52. data/lib/bridgetown-core/tags/with.rb +15 -0
  53. data/lib/bridgetown-core/utils.rb +2 -27
  54. data/lib/bridgetown-core/utils/ruby_exec.rb +66 -0
  55. data/lib/bridgetown-core/version.rb +2 -2
  56. data/lib/bridgetown-core/watcher.rb +21 -10
  57. data/lib/site_template/Gemfile.erb +19 -0
  58. data/lib/site_template/plugins/{.keep → builders/.keep} +0 -0
  59. data/lib/site_template/plugins/site_builder.rb +4 -0
  60. data/lib/site_template/src/_components/footer.html +3 -0
  61. data/lib/site_template/src/_components/head.html +9 -0
  62. data/lib/site_template/src/{_includes → _components}/navbar.html +1 -0
  63. data/lib/site_template/src/_layouts/default.html +3 -3
  64. data/lib/site_template/src/{_components/.keep → favicon.ico} +0 -0
  65. data/lib/site_template/src/posts.md +15 -0
  66. data/lib/site_template/start.js +1 -1
  67. metadata +107 -19
  68. data/lib/bridgetown-core/command.rb +0 -106
  69. data/lib/bridgetown-core/commands/help.rb +0 -34
  70. data/lib/site_template/src/_includes/footer.html +0 -3
  71. data/lib/site_template/src/_includes/head.html +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73f4610f5a38cc797e719301a59ce3c40ceef246702f3f20f6608a01cb05b23f
4
- data.tar.gz: 749f92dfd628f60c5cce698b009aa6aed110fc48daa921b523b50f2617d7987e
3
+ metadata.gz: ba553587c222b3cedc1844d3bf40845a83dd24d70e3c85d49965ad010687e1b5
4
+ data.tar.gz: 223fea6ecf255ebaab06e34d3f8fa8e47ab64d0dd63d2dffc5cd25361a232ded
5
5
  SHA512:
6
- metadata.gz: b1707b9be0641a5814fb6817633c5013e38aeb7293fb353e4cb6f9cde1cab7d09c3f91f3237fbcf435659f2cc61c8345d4c43162252b04308847c56233704df7
7
- data.tar.gz: 3e859ebb2c76bacacbb87c53f803277042560d6e9579911912504b5dd470f22a8be314ad440134fd97c8558d8757b0d7ba6988466804031934d7aedfc6ea6afc
6
+ metadata.gz: dbb889837e2ef982295b2880d76bf6f928ba808b048792250c201bf101eff0151406bad78ed1ea2229d1f1bd572c7b031889386c7dc765506f5f631c30825aff
7
+ data.tar.gz: c6c582d64cab40f9ad203752cc8168b91e446a6535716ea7d318359990ab74f256c57b2a910bed1fbfce316a590e389901a1335770d9171c6ae3852509625ef5
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
5
  $LOAD_PATH.unshift File.expand_path("lib", __dir__)
4
6
  require "bridgetown-core/version"
5
7
 
6
- task :spec => :test
8
+ task spec: :test
7
9
  require "rake/testtask"
8
10
  Rake::TestTask.new(:test) do |test|
9
11
  test.libs << "lib" << "test"
@@ -6,56 +6,17 @@ STDOUT.sync = true
6
6
  $LOAD_PATH.unshift File.expand_path("../../bridgetown/lib", __dir__)
7
7
 
8
8
  require "bridgetown"
9
- require "mercenary"
10
9
 
11
10
  Bridgetown::PluginManager.require_from_bundler
12
11
 
13
- Bridgetown::Deprecator.process(ARGV)
12
+ # Support NO_COLOR: https://no-color.org
13
+ # TODO: need to change behavior of Colorator gem
14
+ ENV["THOR_SHELL"] = "Basic" if ENV["NO_COLOR"]
14
15
 
15
- Mercenary.program(:bridgetown) do |p|
16
- p.version Bridgetown::VERSION
17
- p.description "Bridgetown is a Webpack-aware, Ruby-powered static site generator for the modern Jamstack era"
18
- p.syntax "bridgetown <subcommand> [options]"
16
+ output_version = if ARGV[0] == "-v"
17
+ puts "bridgetown #{Bridgetown::VERSION} \"#{Bridgetown::CODE_NAME}\""
18
+ true
19
+ end
19
20
 
20
- # TODO: it seems wonky to include build options in this top-level
21
- # exe. Should probably remove most things here and relocated to
22
- # individual comments. …in fact there are duplicate option listings
23
- # if you do bridgetown build --help — ouch!
24
- p.option "source", "-s", "--source [DIR]", "Source directory (defaults to src)"
25
- p.option "destination", "-d", "--destination [DIR]",
26
- "Destination directory (defaults to output)"
27
- p.option "plugins_dir", "-p", "--plugins PLUGINS_DIR1[,PLUGINS_DIR2[,...]]", Array,
28
- "Plugins directory (defaults to plugins)"
29
- p.option "layouts_dir", "--layouts DIR", String,
30
- "Layouts directory (defaults to src/_layouts)"
31
- p.option "profile", "--profile", "Generate a Liquid rendering profile"
32
-
33
- # TODO: this is not the way to bring in extra command gems!
34
- # Bridgetown::External.require_if_present(Bridgetown::External.blessed_gems) do |g, ver_constraint|
35
- # cmd = g.split("-").last
36
- # p.command(cmd.to_sym) do |c|
37
- # c.syntax cmd
38
- # c.action do
39
- # Bridgetown.logger.abort_with "You must install the '#{g}' gem" \
40
- # " version #{ver_constraint} to use the 'bridgetown #{cmd}' command."
41
- # end
42
- # end
43
- # end
44
-
45
- Bridgetown::Command.subclasses.each { |c| c.init_with_program(p) }
46
-
47
- p.action do |args, _|
48
- if args.empty?
49
- Bridgetown.logger.error "A subcommand is required."
50
- puts p
51
- abort
52
- else
53
- subcommand = args.first
54
- unless p.has_command? subcommand
55
- Bridgetown.logger.abort_with "fatal: 'bridgetown #{args.first}' could not" \
56
- " be found. You may need to install the bridgetown-#{args.first} gem" \
57
- " or a related gem to be able to use this subcommand."
58
- end
59
- end
60
- end
61
- end
21
+ require "bridgetown-core/commands/base"
22
+ Bridgetown::Commands::Base.start unless output_version
@@ -8,12 +8,12 @@ Gem::Specification.new do |s|
8
8
  s.license = "MIT"
9
9
  s.author = "Bridgetown Team"
10
10
  s.email = "maintainers@bridgetownrb.com"
11
- s.homepage = "https://bridgetownrb.com"
11
+ s.homepage = "https://www.bridgetownrb.com"
12
12
  s.summary = "A Webpack-aware, Ruby-based static site generator for the modern Jamstack era"
13
13
  s.description = "Bridgetown is a Webpack-aware, Ruby-powered static site generator for the modern Jamstack era"
14
14
 
15
15
  s.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(benchmark|features|script|test)/})
16
+ f.match(%r!^(benchmark|features|script|test)/!)
17
17
  end
18
18
  s.executables = ["bridgetown"]
19
19
  s.bindir = "bin"
@@ -26,21 +26,26 @@ Gem::Specification.new do |s|
26
26
  "homepage_uri" => s.homepage,
27
27
  }
28
28
 
29
- s.rdoc_options = ["--charset=UTF-8"]
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
30
 
31
- s.required_ruby_version = ">= 2.4.0"
31
+ s.required_ruby_version = ">= 2.5.0"
32
32
  s.required_rubygems_version = ">= 2.7.0"
33
33
 
34
+ s.add_runtime_dependency("activesupport", "~> 6.0")
34
35
  s.add_runtime_dependency("addressable", "~> 2.4")
35
36
  s.add_runtime_dependency("colorator", "~> 1.0")
37
+ s.add_runtime_dependency("faraday", "~> 1.0")
38
+ s.add_runtime_dependency("faraday_middleware", "~> 1.0")
36
39
  s.add_runtime_dependency("i18n", "~> 1.0")
37
40
  s.add_runtime_dependency("kramdown", "~> 2.1")
38
41
  s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
39
42
  s.add_runtime_dependency("liquid", "~> 4.0")
43
+ s.add_runtime_dependency("liquid-component", ">= 0.1")
44
+ s.add_runtime_dependency("liquid-render-tag", "~> 0.2")
40
45
  s.add_runtime_dependency("listen", "~> 3.0")
41
- s.add_runtime_dependency("mercenary", "~> 0.4.0")
42
46
  s.add_runtime_dependency("pathutil", "~> 0.9")
43
47
  s.add_runtime_dependency("rouge", "~> 3.0")
44
48
  s.add_runtime_dependency("safe_yaml", "~> 1.0")
45
49
  s.add_runtime_dependency("terminal-table", "~> 1.8")
50
+ s.add_runtime_dependency("thor", "~> 1.0")
46
51
  end
@@ -29,22 +29,32 @@ require "csv"
29
29
  require "json"
30
30
 
31
31
  # 3rd party
32
+ require "active_support/core_ext/hash/indifferent_access"
33
+ require "active_support/core_ext/string/inflections"
32
34
  require "pathutil"
33
35
  require "addressable/uri"
34
36
  require "safe_yaml/load"
35
37
  require "liquid"
38
+ require "liquid-render-tag"
39
+ require "liquid-component"
36
40
  require "kramdown"
37
41
  require "colorator"
38
42
  require "i18n"
43
+ require "faraday"
44
+ require "thor"
39
45
 
40
46
  SafeYAML::OPTIONS[:suppress_warnings] = true
41
47
 
48
+ # Create our little String subclass for Ruby Front Matter
49
+ class Rb < String; end
50
+ SafeYAML::OPTIONS[:whitelisted_tags] = ["!ruby/string:Rb"]
51
+
42
52
  module Bridgetown
43
53
  # internal requires
44
54
  autoload :Cleaner, "bridgetown-core/cleaner"
45
55
  autoload :Collection, "bridgetown-core/collection"
46
56
  autoload :Configuration, "bridgetown-core/configuration"
47
- autoload :Convertible, "bridgetown-core/convertible"
57
+ autoload :Convertible, "bridgetown-core/concerns/convertible"
48
58
  autoload :Deprecator, "bridgetown-core/deprecator"
49
59
  autoload :Document, "bridgetown-core/document"
50
60
  autoload :EntryFilter, "bridgetown-core/entry_filter"
@@ -60,6 +70,7 @@ module Bridgetown
60
70
  autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
61
71
  autoload :PostReader, "bridgetown-core/readers/post_reader"
62
72
  autoload :PageReader, "bridgetown-core/readers/page_reader"
73
+ autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
63
74
  autoload :StaticFileReader, "bridgetown-core/readers/static_file_reader"
64
75
  autoload :LogAdapter, "bridgetown-core/log_adapter"
65
76
  autoload :Page, "bridgetown-core/page"
@@ -81,16 +92,15 @@ module Bridgetown
81
92
  autoload :Watcher, "bridgetown-core/watcher"
82
93
 
83
94
  # extensions
95
+ require "bridgetown-core/commands/registrations"
84
96
  require "bridgetown-core/plugin"
85
97
  require "bridgetown-core/converter"
86
98
  require "bridgetown-core/generator"
87
- require "bridgetown-core/command"
88
99
  require "bridgetown-core/liquid_extensions"
89
100
  require "bridgetown-core/filters"
90
101
 
91
102
  require "bridgetown-core/drops/drop"
92
103
  require "bridgetown-core/drops/document_drop"
93
- require_all "bridgetown-core/commands"
94
104
  require_all "bridgetown-core/converters"
95
105
  require_all "bridgetown-core/converters/markdown"
96
106
  require_all "bridgetown-core/drops"
@@ -101,9 +111,10 @@ module Bridgetown
101
111
  # Public: Tells you which Bridgetown environment you are building in so
102
112
  # you can skip tasks if you need to.
103
113
 
104
- def env
114
+ def environment
105
115
  ENV["BRIDGETOWN_ENV"] || "development"
106
116
  end
117
+ alias_method :env, :environment
107
118
 
108
119
  # Public: Generate a Bridgetown configuration Hash by merging the default
109
120
  # options with anything in bridgetown.config.yml, and adding the given
@@ -128,6 +139,11 @@ module Bridgetown
128
139
  end
129
140
  end
130
141
 
142
+ # Conveinence method to register a new Thor command
143
+ def register_command(&block)
144
+ Bridgetown::Commands::Registrations.register(&block)
145
+ end
146
+
131
147
  # Public: Set the TZ environment variable to use the timezone specified
132
148
  #
133
149
  # timezone - the IANA Time Zone
@@ -24,6 +24,7 @@ module Bridgetown
24
24
  def obsolete_files
25
25
  out = (existing_files - new_files - new_dirs + replaced_files).to_a
26
26
  Bridgetown::Hooks.trigger :clean, :on_obsolete, out
27
+ @new_files = @new_dirs = nil
27
28
  out
28
29
  end
29
30
 
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Apply < Thor::Group
6
+ include Thor::Actions
7
+ include Actions
8
+ extend Summarizable
9
+
10
+ Registrations.register do
11
+ register(Apply, "apply", "apply", Apply.summary)
12
+ end
13
+
14
+ def self.banner
15
+ "bridgetown apply PATH or URL"
16
+ end
17
+ summary "Applies an automation to the current site"
18
+
19
+ def self.source_root
20
+ Dir.pwd
21
+ end
22
+
23
+ def self.exit_on_failure?
24
+ true
25
+ end
26
+
27
+ def apply_automation
28
+ @source_paths = [Dir.pwd]
29
+
30
+ if options[:apply]
31
+ apply_after_new_command
32
+ else
33
+ apply_in_pwd
34
+ end
35
+ rescue SystemExit => e
36
+ Bridgetown.logger.error "Problem occurred while running automation:"
37
+ e.backtrace[0..3].each do |backtrace_line|
38
+ Bridgetown.logger.info backtrace_line if backtrace_line.include?(":in `apply'")
39
+ end
40
+ raise e
41
+ end
42
+
43
+ protected
44
+
45
+ def apply_after_new_command
46
+ # Coming from the new command, so set up proper bundler env
47
+ Bundler.with_clean_env do
48
+ self.destination_root = New.created_site_dir
49
+ inside(New.created_site_dir) do
50
+ apply_from_url options[:apply]
51
+ end
52
+ end
53
+ end
54
+
55
+ def apply_in_pwd
56
+ # Running standalone
57
+ automation_command = args.empty? ? "bridgetown.automation.rb" : args[0]
58
+
59
+ if args.empty? && !File.exist?("bridgetown.automation.rb")
60
+ raise ArgumentError, "You must specify a path or a URL," \
61
+ " or add bridgetown.automation.rb to the" \
62
+ " current folder."
63
+ end
64
+
65
+ Bundler.with_clean_env do
66
+ apply_from_url automation_command
67
+ end
68
+ rescue ArgumentError => e
69
+ Bridgetown.logger.warn "Oops!", e.message
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_all "bridgetown-core/commands/concerns"
4
+ require_all "bridgetown-core/commands"
5
+
6
+ module Bridgetown
7
+ module Commands
8
+ class Base < Thor
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+
13
+ Registrations.registrations.each do |block|
14
+ instance_exec(&block)
15
+ end
16
+
17
+ class << self
18
+ # Override single character commands if necessary
19
+ def find_command_possibilities(subcommand)
20
+ if subcommand == "c"
21
+ ["console"]
22
+ else
23
+ super
24
+ end
25
+ end
26
+ end
27
+
28
+ desc "help <command>", "Show detailed command usage information and exit"
29
+ def help(subcommand = nil)
30
+ if subcommand && respond_to?(subcommand)
31
+ klass = Kernel.const_get("Bridgetown::Commands::#{subcommand.capitalize}")
32
+ klass.start(["-h"])
33
+ else
34
+ puts "Bridgetown v#{Bridgetown::VERSION.magenta} \"#{Bridgetown::CODE_NAME.yellow}\"" \
35
+ " is a Webpack-aware, Ruby-powered static site generator for the modern Jamstack era"
36
+ puts ""
37
+ puts "Usage:"
38
+ puts " bridgetown <command> [options]"
39
+ puts ""
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -2,106 +2,111 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Commands
5
- class Build < Command
6
- class << self
7
- # Create the Mercenary command for the Bridgetown CLI for this Command
8
- def init_with_program(prog)
9
- prog.command(:build) do |c|
10
- c.syntax "build [options]"
11
- c.description "Build your site"
12
- c.alias :b
5
+ class Build < Thor::Group
6
+ extend BuildOptions
7
+ extend Summarizable
8
+ include ConfigurationOverridable
13
9
 
14
- add_build_options(c)
10
+ Registrations.register do
11
+ register(Build, "build", "build", Build.summary)
12
+ end
15
13
 
16
- c.action do |_, options|
17
- options["serving"] = false
18
- process_with_graceful_fail(c, options, self)
19
- end
20
- end
21
- end
14
+ def self.banner
15
+ "bridgetown build [options]"
16
+ end
17
+ summary "Build your site and save to destination folder"
22
18
 
23
- # Build your bridgetown site
24
- # Continuously watch if `watch` is set to true in the config.
25
- def process(options)
26
- # Adjust verbosity quickly
27
- Bridgetown.logger.adjust_verbosity(options)
19
+ class_option :watch,
20
+ type: :boolean,
21
+ aliases: "-w",
22
+ desc: "Watch for changes and rebuild"
28
23
 
29
- Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
30
- " (codename \"#{Bridgetown::CODE_NAME.yellow}\")"
24
+ # Build your bridgetown site
25
+ # Continuously watch if `watch` is set to true in the config.
26
+ def build
27
+ Bridgetown.logger.adjust_verbosity(options)
31
28
 
32
- options = configuration_from_options(options)
33
- @site = Bridgetown::Site.new(options)
29
+ Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
30
+ " (codename \"#{Bridgetown::CODE_NAME.yellow}\")"
34
31
 
35
- if options.fetch("skip_initial_build", false)
36
- Bridgetown.logger.warn "Build Warning:", "Skipping the initial build." \
37
- " This may result in an out-of-date site."
38
- else
39
- build(options)
40
- end
32
+ config_options = Serve.loaded_config || configuration_with_overrides(options)
33
+ config_options["serving"] = false unless config_options["serving"]
34
+ @site = Bridgetown::Site.new(config_options)
41
35
 
42
- if options.fetch("detach", false)
43
- Bridgetown.logger.info "Auto-regeneration:",
44
- "disabled when running server detached."
45
- elsif options.fetch("watch", false)
46
- watch(options)
47
- else
48
- Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
49
- end
36
+ if config_options.fetch("skip_initial_build", false)
37
+ Bridgetown.logger.warn "Build Warning:", "Skipping the initial build." \
38
+ " This may result in an out-of-date site."
39
+ else
40
+ build_site(config_options)
50
41
  end
51
42
 
52
- # Build your Bridgetown site.
53
- #
54
- # options - A Hash of options passed to the command or loaded from config
55
- #
56
- # Returns nothing.
57
- def build(options)
58
- t = Time.now
59
- display_folder_paths(options)
60
- if options["unpublished"]
61
- Bridgetown.logger.info "Unpublished mode:",
62
- "enabled. Processing documents marked unpublished"
63
- end
64
- incremental = options["incremental"]
65
- Bridgetown.logger.info "Incremental build:",
66
- (incremental ? "enabled" : "disabled. Enable with --incremental")
67
- Bridgetown.logger.info "Generating…"
68
- process_site(@site)
69
- Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
70
- " #{(Time.now - t).ceil(2)} seconds."
43
+ if config_options.fetch("detach", false)
44
+ Bridgetown.logger.info "Auto-regeneration:",
45
+ "disabled when running server detached."
46
+ elsif config_options.fetch("watch", false)
47
+ watch_site(config_options)
48
+ else
49
+ Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
71
50
  end
51
+ end
72
52
 
73
- # Private: Watch for file changes and rebuild the site.
74
- #
75
- # options - A Hash of options passed to the command or loaded from config
76
- #
77
- # Returns nothing.
78
- def watch(options)
79
- # Warn Windows users that they might need to upgrade.
80
- if Utils::Platforms.bash_on_windows?
81
- Bridgetown.logger.warn "",
82
- "Auto-regeneration may not work on some Windows versions."
83
- Bridgetown.logger.warn "",
84
- "Please see: https://github.com/Microsoft/BashOnWindows/issues/216"
85
- Bridgetown.logger.warn "",
86
- "If it does not work, please upgrade Bash on Windows or "\
87
- "run Bridgetown with --no-watch."
88
- end
53
+ protected
89
54
 
90
- # External.require_with_graceful_fail "bridgetown-watch"
91
- Bridgetown::Watcher.watch(@site, options)
55
+ # Build your Bridgetown site.
56
+ #
57
+ # options - A Hash of options passed to the command or loaded from config
58
+ #
59
+ # Returns nothing.
60
+ def build_site(config_options)
61
+ t = Time.now
62
+ display_folder_paths(config_options)
63
+ if config_options["unpublished"]
64
+ Bridgetown.logger.info "Unpublished mode:",
65
+ "enabled. Processing documents marked unpublished"
92
66
  end
67
+ incremental = config_options["incremental"]
68
+ Bridgetown.logger.info "Incremental build:",
69
+ (incremental ? "enabled" : "disabled. Enable with --incremental")
70
+ Bridgetown.logger.info "Generating…"
71
+ @site.process
72
+ Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
73
+ " #{(Time.now - t).ceil(2)} seconds."
74
+ end
75
+
76
+ # Watch for file changes and rebuild the site.
77
+ #
78
+ # options - A Hash of options passed to the command or loaded from config
79
+ #
80
+ # Returns nothing.
81
+ def watch_site(config_options)
82
+ # Warn Windows users that they might need to upgrade.
83
+ if Utils::Platforms.bash_on_windows?
84
+ Bridgetown.logger.warn "",
85
+ "Auto-regeneration may not work on some Windows versions."
86
+ Bridgetown.logger.warn "",
87
+ "Please see: https://github.com/Microsoft/BashOnWindows/issues/216"
88
+ Bridgetown.logger.warn "",
89
+ "If it does not work, please upgrade Bash on Windows or "\
90
+ "run Bridgetown with --no-watch."
91
+ end
92
+
93
+ Bridgetown::Watcher.watch(@site, config_options)
94
+ end
93
95
 
94
- # Private: display the source and destination folder paths
95
- #
96
- # options - A Hash of options passed to the command
97
- #
98
- # Returns nothing.
99
- def display_folder_paths(options)
100
- source = File.expand_path(options["source"])
101
- destination = File.expand_path(options["destination"])
102
- plugins_dir = File.expand_path(options["plugins_dir"])
103
- Bridgetown.logger.info "Source:", source
104
- Bridgetown.logger.info "Destination:", destination
96
+ # Display the source and destination folder paths
97
+ #
98
+ # options - A Hash of options passed to the command
99
+ #
100
+ # Returns nothing.
101
+ def display_folder_paths(config_options)
102
+ source = File.expand_path(config_options["source"])
103
+ destination = File.expand_path(config_options["destination"])
104
+ Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
105
+ Bridgetown.logger.info "Source:", source
106
+ Bridgetown.logger.info "Destination:", destination
107
+ # TODO: work with arrays
108
+ if config_options["plugins_dir"].is_a?(String)
109
+ plugins_dir = File.expand_path(config_options["plugins_dir"])
105
110
  Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
106
111
  end
107
112
  end