bridgetown-core 0.18.4 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +6 -0
  3. data/bridgetown-core.gemspec +3 -3
  4. data/lib/bridgetown-core.rb +24 -2
  5. data/lib/bridgetown-core/commands/apply.rb +4 -3
  6. data/lib/bridgetown-core/commands/concerns/actions.rb +0 -5
  7. data/lib/bridgetown-core/commands/configure.rb +62 -0
  8. data/lib/bridgetown-core/commands/new.rb +28 -1
  9. data/lib/bridgetown-core/commands/plugins.rb +1 -0
  10. data/lib/bridgetown-core/configurations/.keep +0 -0
  11. data/lib/bridgetown-core/configurations/bt-postcss.rb +26 -0
  12. data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +21 -0
  13. data/lib/bridgetown-core/configurations/minitesting.rb +95 -0
  14. data/lib/bridgetown-core/configurations/netlify.rb +6 -0
  15. data/lib/bridgetown-core/configurations/netlify/netlify.sh +14 -0
  16. data/lib/bridgetown-core/configurations/netlify/netlify.toml +44 -0
  17. data/lib/bridgetown-core/configurations/purgecss.rb +49 -0
  18. data/lib/bridgetown-core/configurations/stimulus.rb +49 -0
  19. data/lib/bridgetown-core/configurations/swup.rb +37 -0
  20. data/lib/bridgetown-core/configurations/tailwindcss.rb +29 -0
  21. data/lib/bridgetown-core/configurations/tailwindcss/css_imports.css +4 -0
  22. data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +12 -0
  23. data/lib/bridgetown-core/configurations/turbo.rb +16 -0
  24. data/lib/bridgetown-core/converters/erb_templates.rb +6 -13
  25. data/lib/bridgetown-core/filters.rb +3 -3
  26. data/lib/bridgetown-core/generator.rb +2 -1
  27. data/lib/bridgetown-core/page_without_a_file.rb +3 -0
  28. data/lib/bridgetown-core/plugin.rb +2 -26
  29. data/lib/bridgetown-core/ruby_template_view.rb +9 -2
  30. data/lib/bridgetown-core/utils/ruby_exec.rb +4 -4
  31. data/lib/bridgetown-core/version.rb +2 -2
  32. data/lib/site_template/README.md +70 -0
  33. data/lib/site_template/frontend/javascript/index.js.erb +11 -0
  34. data/lib/site_template/frontend/styles/index.css +19 -0
  35. data/lib/site_template/{package.json → package.json.erb} +16 -9
  36. data/lib/site_template/postcss.config.js.erb +11 -0
  37. data/lib/site_template/src/_components/footer.liquid +1 -1
  38. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  39. data/lib/site_template/{webpack.config.js → webpack.config.js.erb} +24 -0
  40. metadata +41 -23
  41. data/lib/site_template/frontend/javascript/index.js +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12935850728bd01e8b6aff21631a0ca38e62c1c3be5dfc94c7918ba49ff3a9b7
4
- data.tar.gz: c85c38dc8c902d8fe774b98263d71c0845f301ed2793a61d71c700d77434173e
3
+ metadata.gz: 82771f9cc6fa2993f61010025de7fab09c2be37d9dfb3f365d728a6dd3ed5b3a
4
+ data.tar.gz: ab1cfb7e45eac85bb80852b33ab4ca1f5cc69b52f6a1bde70ea1c70c39859005
5
5
  SHA512:
6
- metadata.gz: 10082e9084ea89ed6e2cae0da189ba8a2e81dfe22501c32622db5ba0c83a447351789c9f73e28fc53210500dc56f73689f7021d25239df663010e14b2041589b
7
- data.tar.gz: b934861ac81add8ac716ada0156af33b9cdd93228cab17cad968d8a0a3cbdf1749d72467b4ef51d2da7db100aaa5916a7d2d4b0bd4643c735185ceae66087357
6
+ metadata.gz: 67ea143f786bf6825f6db8ffa4ba1ce336e5d20e6746bbb24a754df40e0ba5084c3a5a04b0965f7ee080de67f2312b79d0251f34d76174fd55ca3ba379667928
7
+ data.tar.gz: 2ad31567525e3b3633c4620088df104d2fe5ae65010ffadab04baa33982c960640430f16f13eeab6718c27ec2e66574e5aeeb30be90086ab2707a9f465e9d9c5
data/bin/bridgetown CHANGED
@@ -5,6 +5,12 @@ STDOUT.sync = true
5
5
 
6
6
  $LOAD_PATH.unshift File.expand_path("../../bridgetown/lib", __dir__)
7
7
 
8
+ # Used by commands/automations
9
+ require "active_support"
10
+ require "active_support/core_ext/array/extract_options"
11
+ require "active_support/core_ext/string/strip"
12
+ require "active_support/core_ext/string/indent"
13
+
8
14
  require "bridgetown"
9
15
 
10
16
  Bridgetown::PluginManager.require_from_bundler
@@ -42,14 +42,14 @@ Gem::Specification.new do |s|
42
42
  s.add_runtime_dependency("i18n", "~> 1.0")
43
43
  s.add_runtime_dependency("kramdown", "~> 2.1")
44
44
  s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
45
- s.add_runtime_dependency("liquid", "~> 4.0")
45
+ s.add_runtime_dependency("liquid", "~> 5.0")
46
46
  s.add_runtime_dependency("liquid-component", ">= 0.1")
47
- s.add_runtime_dependency("liquid-render-tag", "~> 0.2")
48
47
  s.add_runtime_dependency("listen", "~> 3.0")
49
48
  s.add_runtime_dependency("pathutil", "~> 0.9")
50
49
  s.add_runtime_dependency("rouge", "~> 3.0")
51
50
  s.add_runtime_dependency("safe_yaml", "~> 1.0")
52
51
  s.add_runtime_dependency("terminal-table", "~> 1.8")
53
- s.add_runtime_dependency("thor", "~> 1.0")
52
+ s.add_runtime_dependency("thor", "~> 1.1")
54
53
  s.add_runtime_dependency("tilt", "~> 2.0")
54
+ s.add_runtime_dependency("webrick", "~> 1.7")
55
55
  end
@@ -29,14 +29,18 @@ require "csv"
29
29
  require "json"
30
30
 
31
31
  # 3rd party
32
+ require "active_support"
33
+ require "active_support/core_ext/hash/keys"
32
34
  require "active_support/core_ext/object/blank"
33
35
  require "active_support/core_ext/string/inflections"
36
+ require "active_support/core_ext/string/inquiry"
37
+ require "active_support/core_ext/string/starts_ends_with"
38
+ require "active_support/descendants_tracker"
34
39
  require "hash_with_dot_access"
35
40
  require "pathutil"
36
41
  require "addressable/uri"
37
42
  require "safe_yaml/load"
38
43
  require "liquid"
39
- require "liquid-render-tag"
40
44
  require "liquid-component"
41
45
  require "kramdown"
42
46
  require "colorator"
@@ -44,12 +48,30 @@ require "i18n"
44
48
  require "faraday"
45
49
  require "thor"
46
50
 
51
+ module HashWithDotAccess
52
+ class Hash # :nodoc:
53
+ def to_liquid
54
+ to_h.to_liquid
55
+ end
56
+ end
57
+ end
58
+
47
59
  SafeYAML::OPTIONS[:suppress_warnings] = true
48
60
 
49
61
  # Create our little String subclass for Ruby Front Matter
50
62
  class Rb < String; end
51
63
  SafeYAML::OPTIONS[:whitelisted_tags] = ["!ruby/string:Rb"]
52
64
 
65
+ if RUBY_VERSION.start_with?("3.0")
66
+ # workaround for Ruby 3 preview 2, maybe can remove later
67
+ # rubocop:disable Style/GlobalVars
68
+ old_verbose = $VERBOSE
69
+ $VERBOSE = nil
70
+ SafeYAML::SafeToRubyVisitor.const_set(:INITIALIZE_ARITY, 2)
71
+ $verbose = old_verbose
72
+ # rubocop:enable Style/GlobalVars
73
+ end
74
+
53
75
  module Bridgetown
54
76
  # internal requires
55
77
  autoload :Cleaner, "bridgetown-core/cleaner"
@@ -118,7 +140,7 @@ module Bridgetown
118
140
  # Tells you which Bridgetown environment you are building in so
119
141
  # you can skip tasks if you need to.
120
142
  def environment
121
- ENV["BRIDGETOWN_ENV"] || "development"
143
+ (ENV["BRIDGETOWN_ENV"] || "development").inquiry
122
144
  end
123
145
  alias_method :env, :environment
124
146
 
@@ -26,6 +26,7 @@ module Bridgetown
26
26
 
27
27
  def apply_automation
28
28
  @source_paths = [Dir.pwd]
29
+ @logger = Bridgetown.logger
29
30
 
30
31
  if options[:apply]
31
32
  apply_after_new_command
@@ -33,9 +34,9 @@ module Bridgetown
33
34
  apply_in_pwd
34
35
  end
35
36
  rescue SystemExit => e
36
- Bridgetown.logger.error "Problem occurred while running automation:"
37
+ @logger.error "Problem occurred while running automation:"
37
38
  e.backtrace[0..3].each do |backtrace_line|
38
- Bridgetown.logger.info backtrace_line if backtrace_line.include?(":in `apply'")
39
+ @logger.info backtrace_line if backtrace_line.include?(":in `apply'")
39
40
  end
40
41
  raise e
41
42
  end
@@ -66,7 +67,7 @@ module Bridgetown
66
67
  apply_from_url automation_command
67
68
  end
68
69
  rescue ArgumentError => e
69
- Bridgetown.logger.warn "Oops!", e.message
70
+ @logger.warn "Oops!", e.message
70
71
  end
71
72
  end
72
73
  end
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Mostly not used here, but may come in handy in new automations
4
- require "active_support/core_ext/array/extract_options"
5
- require "active_support/core_ext/string/strip"
6
- require "active_support/core_ext/string/indent"
7
-
8
3
  module Bridgetown
9
4
  module Commands
10
5
  module Actions
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Configure < Thor::Group
6
+ include Thor::Actions
7
+ extend Summarizable
8
+
9
+ Registrations.register do
10
+ register(Configure, "configure", "configure CONFIGURATION", Configure.summary)
11
+ end
12
+
13
+ def self.banner
14
+ "bridgetown configure CONFIGURATION(S)"
15
+ end
16
+ summary "Set up bundled Bridgetown configurations"
17
+
18
+ def self.exit_on_failure?
19
+ true
20
+ end
21
+
22
+ def perform_configurations
23
+ logger = Bridgetown.logger
24
+ list_configurations if args.empty?
25
+
26
+ args.each do |configuration|
27
+ configure configuration
28
+ rescue Thor::Error
29
+ logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
30
+ end
31
+ end
32
+
33
+ def self.source_root
34
+ File.expand_path("../configurations", __dir__)
35
+ end
36
+
37
+ protected
38
+
39
+ def configure(configuration)
40
+ configuration_file = find_in_source_paths("#{configuration}.rb")
41
+
42
+ inside(New.created_site_dir || Dir.pwd) do
43
+ Apply.new.invoke(:apply_automation, [configuration_file])
44
+ end
45
+ end
46
+
47
+ def list_configurations
48
+ say "Please specify a valid packaged configuration from the below list:\n\n"
49
+ configurations.each do |configuration|
50
+ configuration = set_color configuration, :blue, :bold
51
+ say configuration
52
+ end
53
+ end
54
+
55
+ def configurations
56
+ inside self.class.source_root do
57
+ return Dir.glob("*.rb").map { |file| file.sub(".rb", "") }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -19,6 +19,10 @@ module Bridgetown
19
19
  aliases: "-a",
20
20
  banner: "PATH|URL",
21
21
  desc: "Apply an automation after creating the site scaffold"
22
+ class_option :configure,
23
+ aliases: "-c",
24
+ banner: "CONFIGURATION(S)",
25
+ desc: "Comma separated list of bundled configurations to perform"
22
26
  class_option :force,
23
27
  type: :boolean,
24
28
  desc: "Force creation even if PATH already exists"
@@ -28,6 +32,9 @@ module Bridgetown
28
32
  class_option :"skip-yarn",
29
33
  type: :boolean,
30
34
  desc: "Skip 'yarn install'"
35
+ class_option :"use-postcss",
36
+ type: :boolean,
37
+ desc: "Create an empty PostCSS configuration instead of using Sass"
31
38
 
32
39
  DOCSURL = "https://bridgetownrb.com/docs"
33
40
 
@@ -47,6 +54,8 @@ module Bridgetown
47
54
  raise ArgumentError, "You must specify a path." if args.empty?
48
55
 
49
56
  new_site_path = File.expand_path(args.join(" "), Dir.pwd)
57
+ @site_name = new_site_path.split(File::SEPARATOR).last
58
+
50
59
  if preserve_source_location?(new_site_path, options)
51
60
  say_status :conflict, "#{new_site_path} exists and is not empty.", :red
52
61
  Bridgetown.logger.abort_with "Ensure #{new_site_path} is empty or else " \
@@ -67,7 +76,7 @@ module Bridgetown
67
76
  end
68
77
 
69
78
  def create_site(new_site_path)
70
- directory ".", ".", exclude_pattern: %r!\.erb|DS_Store$!
79
+ directory ".", ".", exclude_pattern: %r!\.erb|DS_Store$|\.(s[ac]|c)ss$!
71
80
  FileUtils.chmod_R "u+w", new_site_path
72
81
 
73
82
  template(
@@ -75,12 +84,27 @@ module Bridgetown
75
84
  "src/_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-bridgetown.md"
76
85
  )
77
86
  template("Gemfile.erb", "Gemfile")
87
+ template("package.json.erb", "package.json")
88
+ template("webpack.config.js.erb", "webpack.config.js")
89
+ template("frontend/javascript/index.js.erb", "frontend/javascript/index.js")
90
+
91
+ options["use-postcss"] ? configure_postcss : configure_sass
92
+ end
93
+
94
+ def configure_sass
95
+ copy_file("frontend/styles/index.scss")
96
+ end
97
+
98
+ def configure_postcss
99
+ template("postcss.config.js.erb", "postcss.config.js")
100
+ copy_file("frontend/styles/index.css")
78
101
  end
79
102
 
80
103
  # After a new site has been created, print a success notification and
81
104
  # then automatically execute bundle install from within the new site dir
82
105
  # unless the user opts to skip 'bundle install'.
83
106
  # rubocop:todo Metrics/CyclomaticComplexity
107
+ # rubocop:disable Metrics/PerceivedComplexity
84
108
  def after_install(path, cli_path, options = {})
85
109
  git_init path
86
110
 
@@ -91,6 +115,7 @@ module Bridgetown
91
115
  yarn_install path unless options["skip-yarn"]
92
116
 
93
117
  invoke(Apply, [], options) if options[:apply]
118
+ invoke(Configure, options[:configure].split(","), {}) if options[:configure]
94
119
 
95
120
  logger = Bridgetown.logger
96
121
  yarn_start = "yarn start"
@@ -111,6 +136,7 @@ module Bridgetown
111
136
  logger.info "Yarn install skipped.".yellow if @skipped_yarn
112
137
  end
113
138
  # rubocop:enable Metrics/CyclomaticComplexity
139
+ # rubocop:enable Metrics/PerceivedComplexity
114
140
 
115
141
  def bundle_install(path)
116
142
  unless Bridgetown.environment == "test"
@@ -132,6 +158,7 @@ module Bridgetown
132
158
  unless Bridgetown.environment == "test"
133
159
  inside(path) do
134
160
  run "git init", abort_on_failure: true
161
+ run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
135
162
  end
136
163
  end
137
164
  rescue SystemExit
@@ -150,6 +150,7 @@ module Bridgetown
150
150
  inside name do # rubocop:todo Metrics/BlockLength
151
151
  run "rm -rf .git"
152
152
  run "git init"
153
+ run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
153
154
 
154
155
  run "mv bridgetown-sample-plugin.gemspec #{new_gemspec}"
155
156
  gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
File without changes
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable all
4
+
5
+ TEMPLATE_PATH = File.expand_path("./bt-postcss", __dir__)
6
+
7
+ begin
8
+ find_in_source_paths("postcss.config.js")
9
+ rescue Thor::Error
10
+ error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
11
+
12
+ @logger.error "\nError:".red, "🚨 #{error_message}"
13
+ @logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
14
+
15
+ return
16
+ end
17
+
18
+ plugins = %w(postcss-easy-import postcss-mixins postcss-color-function cssnano)
19
+
20
+ say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
21
+ run "yarn add -D #{plugins.join(' ')}"
22
+
23
+ remove_file "postcss.config.js"
24
+ copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
25
+
26
+ # rubocop:enable all
@@ -0,0 +1,21 @@
1
+ module.exports = {
2
+ plugins: {
3
+ 'postcss-easy-import': {},
4
+ 'postcss-mixins': {},
5
+ 'postcss-color-function': {},
6
+ 'postcss-flexbugs-fixes': {},
7
+ 'postcss-preset-env': {
8
+ autoprefixer: {
9
+ flexbox: 'no-2009'
10
+ },
11
+ stage: 2,
12
+ features: {
13
+ 'nesting-rules': true,
14
+ 'custom-media-queries': true
15
+ },
16
+ },
17
+ 'cssnano' : {
18
+ preset: 'default'
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable all
4
+
5
+ say_status :minitesting, "Adding test gems, package.json scripts, and examples"
6
+
7
+ append_to_file "Gemfile" do
8
+ <<~GEMS
9
+ \n
10
+ group :test, optional: true do
11
+ gem "nokogiri"
12
+ gem "minitest"
13
+ gem "minitest-profile"
14
+ gem "minitest-reporters"
15
+ gem "shoulda"
16
+ gem "rails-dom-testing"
17
+ end
18
+ GEMS
19
+ end
20
+
21
+ new_scripts = ' "test": "BRIDGETOWN_ENV=test yarn build",'
22
+ new_scripts += "\n" + ' "deploy:test": "bundle install --with test && yarn deploy"'
23
+ package_json = "package.json"
24
+ script_regex = %r{"scripts": \{(\s+".*,?)*}
25
+ inject_into_file(package_json, ",\n" + new_scripts, after: script_regex)
26
+
27
+ create_file "test/helper.rb" do
28
+ <<~RUBY
29
+ require "nokogiri"
30
+ require "minitest/autorun"
31
+ require "minitest/reporters"
32
+ require "minitest/profile"
33
+ require "shoulda"
34
+ require "rails-dom-testing"
35
+ # Report with color.
36
+ Minitest::Reporters.use! [
37
+ Minitest::Reporters::DefaultReporter.new(
38
+ color: true
39
+ ),
40
+ ]
41
+ Minitest::Test.class_eval do
42
+ include Rails::Dom::Testing::Assertions
43
+ def site
44
+ @site ||= Bridgetown.sites.first
45
+ end
46
+ def nokogiri(input)
47
+ input.respond_to?(:output) ? Nokogiri::HTML(input.output) : Nokogiri::HTML(input)
48
+ end
49
+ def document_root(root)
50
+ @document_root = root.is_a?(Nokogiri::XML::Document) ? root : nokogiri(root)
51
+ end
52
+ def document_root_element
53
+ if @document_root.nil?
54
+ raise "Call `document_root' with a Nokogiri document before testing your assertions"
55
+ end
56
+ @document_root
57
+ end
58
+ end
59
+ RUBY
60
+ end
61
+
62
+ create_file "test/test_homepage.rb" do
63
+ <<~RUBY
64
+ require_relative "./helper"
65
+ class TestHomepage < Minitest::Test
66
+ context "homepage" do
67
+ setup do
68
+ page = site.pages.find { |doc| doc.url == "/" }
69
+ document_root page
70
+ end
71
+ should "exist" do
72
+ assert_select "body"
73
+ end
74
+ end
75
+ end
76
+ RUBY
77
+ end
78
+
79
+ create_file "plugins/test_output.rb" do
80
+ <<~RUBY
81
+ unless Bridgetown.environment == "development"
82
+ Bridgetown::Hooks.register :site, :post_write do
83
+ # Load test suite to run on exit
84
+ require "nokogiri"
85
+ Dir["test/**/*.rb"].each { |file| require_relative("../\#{file}") }
86
+ rescue LoadError
87
+ Bridgetown.logger.warn "Testing:", "To run tests, you must first run \`bundle install --with test\`"
88
+ end
89
+ end
90
+ RUBY
91
+ end
92
+
93
+ say_status :minitesting, "All set! To get started, look at test/test_homepage.rb and then run \`yarn test\`"
94
+
95
+ # rubocop:enable all