bridgetown-core 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -1
  3. data/bin/bridgetown +9 -23
  4. data/bridgetown-core.gemspec +3 -1
  5. data/lib/bridgetown-core.rb +9 -2
  6. data/lib/bridgetown-core/commands/apply.rb +73 -0
  7. data/lib/bridgetown-core/commands/base.rb +45 -0
  8. data/lib/bridgetown-core/commands/build.rb +91 -86
  9. data/lib/bridgetown-core/commands/clean.rb +30 -29
  10. data/lib/bridgetown-core/commands/concerns/actions.rb +128 -0
  11. data/lib/bridgetown-core/commands/concerns/build_options.rb +76 -0
  12. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +18 -0
  13. data/lib/bridgetown-core/commands/concerns/summarizable.rb +13 -0
  14. data/lib/bridgetown-core/commands/console.rb +57 -39
  15. data/lib/bridgetown-core/commands/doctor.rb +126 -126
  16. data/lib/bridgetown-core/commands/new.rb +120 -155
  17. data/lib/bridgetown-core/commands/plugins.rb +167 -130
  18. data/lib/bridgetown-core/commands/registrations.rb +16 -0
  19. data/lib/bridgetown-core/commands/serve.rb +219 -215
  20. data/lib/bridgetown-core/concerns/convertible.rb +1 -4
  21. data/lib/bridgetown-core/concerns/site/renderable.rb +1 -2
  22. data/lib/bridgetown-core/drops/document_drop.rb +9 -1
  23. data/lib/bridgetown-core/drops/page_drop.rb +1 -1
  24. data/lib/bridgetown-core/excerpt.rb +4 -1
  25. data/lib/bridgetown-core/generators/prototype_generator.rb +2 -0
  26. data/lib/bridgetown-core/liquid_renderer.rb +1 -0
  27. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -4
  28. data/lib/bridgetown-core/liquid_renderer/file_system.rb +3 -1
  29. data/lib/bridgetown-core/page.rb +3 -18
  30. data/lib/bridgetown-core/plugin_manager.rb +31 -17
  31. data/lib/bridgetown-core/renderer.rb +31 -18
  32. data/lib/bridgetown-core/tags/include.rb +14 -0
  33. data/lib/bridgetown-core/tags/render_content.rb +39 -16
  34. data/lib/bridgetown-core/tags/with.rb +15 -0
  35. data/lib/bridgetown-core/utils.rb +44 -0
  36. data/lib/bridgetown-core/version.rb +2 -2
  37. data/lib/bridgetown-core/watcher.rb +17 -10
  38. data/lib/site_template/Gemfile.erb +19 -0
  39. data/lib/site_template/bridgetown.config.yml +5 -3
  40. data/lib/site_template/package.json +1 -0
  41. data/lib/site_template/src/_components/footer.liquid +3 -0
  42. data/lib/site_template/src/_components/head.liquid +9 -0
  43. data/lib/site_template/src/{_includes/navbar.html → _components/navbar.liquid} +0 -0
  44. data/lib/site_template/src/_layouts/default.html +3 -3
  45. data/lib/site_template/start.js +1 -1
  46. data/lib/site_template/webpack.config.js +3 -3
  47. metadata +53 -19
  48. data/lib/bridgetown-core/command.rb +0 -112
  49. data/lib/bridgetown-core/commands/help.rb +0 -34
  50. data/lib/site_template/src/_components/.keep +0 -0
  51. data/lib/site_template/src/_includes/footer.html +0 -3
  52. 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: 1c45c33f0989ba19297a2123d22d3d678c96e6a339beffc3ea3b70719ff12786
4
- data.tar.gz: 36bccfc77d17a3294220f5e49789e30bf6c738c967ff03b6f9cea0801b2dce23
3
+ metadata.gz: 97ae06ce8eba440f7fbf028094f48c4779b08245c7e2edd2641deed2ccb271b0
4
+ data.tar.gz: b0680214291a6721bb43230bca4627608414fea6a6fc741b2431672dfd04a39d
5
5
  SHA512:
6
- metadata.gz: b36d74cac58d2210185de187455f6ba3536feaccd34200b42dd08449c7c15745fb0ed468c2f551e31f3b7270ee286ea29396cfe0d4040a644d86b4750c3e3898
7
- data.tar.gz: 7833b8a76ca6b2e36cd398e21a2b18d0f38163210f49e679552e637a4c90bbe68f7d76582966cbbcc036f5a901bb86a24910280f23f79a4b29092ae862a7a99f
6
+ metadata.gz: b742ce6a54a89c48beb0f12e27cb0bb8a67630ca0e749b30919ffc8a4be2054a9de38374bde59ba2f2f2db1a436a6704dc070f6eb418e85f650bb2f66d8c3dd0
7
+ data.tar.gz: 99a4bfe0ab8fb3dcf94e92423089048d9149722044b79ac698c95eda96872cfa84a25e5cc2e190d4f77f2215c80199aae01d9d7aa63669f6e21790c4279e50dc
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,31 +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.magenta} \"#{Bridgetown::CODE_NAME.yellow}\""
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
- Bridgetown::Command.subclasses.each { |c| c.init_with_program(p) }
21
-
22
- p.action do |args, _|
23
- if args.empty?
24
- Bridgetown.logger.error "A subcommand is required."
25
- puts p
26
- abort
27
- else
28
- subcommand = args.first
29
- unless p.has_command? subcommand
30
- Bridgetown.logger.abort_with "fatal: 'bridgetown #{args.first}' could not" \
31
- " be found. You may need to install the bridgetown-#{args.first} gem" \
32
- " or a related gem to be able to use this subcommand."
33
- end
34
- end
35
- end
36
- end
21
+ require "bridgetown-core/commands/base"
22
+ Bridgetown::Commands::Base.start unless output_version
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
 
34
34
  s.add_runtime_dependency("activesupport", "~> 6.0")
35
35
  s.add_runtime_dependency("addressable", "~> 2.4")
36
+ s.add_runtime_dependency("awesome_print", "~> 1.8")
36
37
  s.add_runtime_dependency("colorator", "~> 1.0")
37
38
  s.add_runtime_dependency("faraday", "~> 1.0")
38
39
  s.add_runtime_dependency("faraday_middleware", "~> 1.0")
@@ -40,11 +41,12 @@ Gem::Specification.new do |s|
40
41
  s.add_runtime_dependency("kramdown", "~> 2.1")
41
42
  s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
42
43
  s.add_runtime_dependency("liquid", "~> 4.0")
44
+ s.add_runtime_dependency("liquid-component", ">= 0.1")
43
45
  s.add_runtime_dependency("liquid-render-tag", "~> 0.2")
44
46
  s.add_runtime_dependency("listen", "~> 3.0")
45
- s.add_runtime_dependency("mercenary", "~> 0.4.0")
46
47
  s.add_runtime_dependency("pathutil", "~> 0.9")
47
48
  s.add_runtime_dependency("rouge", "~> 3.0")
48
49
  s.add_runtime_dependency("safe_yaml", "~> 1.0")
49
50
  s.add_runtime_dependency("terminal-table", "~> 1.8")
51
+ s.add_runtime_dependency("thor", "~> 1.0")
50
52
  end
@@ -30,15 +30,18 @@ require "json"
30
30
 
31
31
  # 3rd party
32
32
  require "active_support/core_ext/hash/indifferent_access"
33
+ require "active_support/core_ext/string/inflections"
33
34
  require "pathutil"
34
35
  require "addressable/uri"
35
36
  require "safe_yaml/load"
36
37
  require "liquid"
37
38
  require "liquid-render-tag"
39
+ require "liquid-component"
38
40
  require "kramdown"
39
41
  require "colorator"
40
42
  require "i18n"
41
43
  require "faraday"
44
+ require "thor"
42
45
 
43
46
  SafeYAML::OPTIONS[:suppress_warnings] = true
44
47
 
@@ -89,16 +92,15 @@ module Bridgetown
89
92
  autoload :Watcher, "bridgetown-core/watcher"
90
93
 
91
94
  # extensions
95
+ require "bridgetown-core/commands/registrations"
92
96
  require "bridgetown-core/plugin"
93
97
  require "bridgetown-core/converter"
94
98
  require "bridgetown-core/generator"
95
- require "bridgetown-core/command"
96
99
  require "bridgetown-core/liquid_extensions"
97
100
  require "bridgetown-core/filters"
98
101
 
99
102
  require "bridgetown-core/drops/drop"
100
103
  require "bridgetown-core/drops/document_drop"
101
- require_all "bridgetown-core/commands"
102
104
  require_all "bridgetown-core/converters"
103
105
  require_all "bridgetown-core/converters/markdown"
104
106
  require_all "bridgetown-core/drops"
@@ -137,6 +139,11 @@ module Bridgetown
137
139
  end
138
140
  end
139
141
 
142
+ # Conveinence method to register a new Thor command
143
+ def register_command(&block)
144
+ Bridgetown::Commands::Registrations.register(&block)
145
+ end
146
+
140
147
  # Public: Set the TZ environment variable to use the timezone specified
141
148
  #
142
149
  # timezone - the IANA Time Zone
@@ -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
- 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"
91
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
92
95
 
93
- # Private: display the source and destination folder paths
94
- #
95
- # options - A Hash of options passed to the command
96
- #
97
- # Returns nothing.
98
- def display_folder_paths(options)
99
- source = File.expand_path(options["source"])
100
- destination = File.expand_path(options["destination"])
101
- plugins_dir = File.expand_path(options["plugins_dir"])
102
- Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
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