bridgetown-core 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +42 -0
  3. data/bridgetown-core.gemspec +46 -0
  4. data/lib/bridgetown-core.rb +202 -0
  5. data/lib/bridgetown-core/cache.rb +190 -0
  6. data/lib/bridgetown-core/cleaner.rb +111 -0
  7. data/lib/bridgetown-core/collection.rb +279 -0
  8. data/lib/bridgetown-core/command.rb +106 -0
  9. data/lib/bridgetown-core/commands/build.rb +96 -0
  10. data/lib/bridgetown-core/commands/clean.rb +43 -0
  11. data/lib/bridgetown-core/commands/console.rb +56 -0
  12. data/lib/bridgetown-core/commands/doctor.rb +172 -0
  13. data/lib/bridgetown-core/commands/help.rb +34 -0
  14. data/lib/bridgetown-core/commands/new.rb +148 -0
  15. data/lib/bridgetown-core/commands/serve.rb +273 -0
  16. data/lib/bridgetown-core/commands/serve/servlet.rb +68 -0
  17. data/lib/bridgetown-core/configuration.rb +323 -0
  18. data/lib/bridgetown-core/converter.rb +54 -0
  19. data/lib/bridgetown-core/converters/identity.rb +39 -0
  20. data/lib/bridgetown-core/converters/markdown.rb +108 -0
  21. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +132 -0
  22. data/lib/bridgetown-core/converters/smartypants.rb +69 -0
  23. data/lib/bridgetown-core/convertible.rb +237 -0
  24. data/lib/bridgetown-core/deprecator.rb +50 -0
  25. data/lib/bridgetown-core/document.rb +475 -0
  26. data/lib/bridgetown-core/drops/bridgetown_drop.rb +32 -0
  27. data/lib/bridgetown-core/drops/collection_drop.rb +20 -0
  28. data/lib/bridgetown-core/drops/document_drop.rb +69 -0
  29. data/lib/bridgetown-core/drops/drop.rb +215 -0
  30. data/lib/bridgetown-core/drops/excerpt_drop.rb +19 -0
  31. data/lib/bridgetown-core/drops/page_drop.rb +14 -0
  32. data/lib/bridgetown-core/drops/site_drop.rb +62 -0
  33. data/lib/bridgetown-core/drops/static_file_drop.rb +14 -0
  34. data/lib/bridgetown-core/drops/unified_payload_drop.rb +26 -0
  35. data/lib/bridgetown-core/drops/url_drop.rb +132 -0
  36. data/lib/bridgetown-core/entry_filter.rb +108 -0
  37. data/lib/bridgetown-core/errors.rb +20 -0
  38. data/lib/bridgetown-core/excerpt.rb +202 -0
  39. data/lib/bridgetown-core/external.rb +62 -0
  40. data/lib/bridgetown-core/filters.rb +467 -0
  41. data/lib/bridgetown-core/filters/date_filters.rb +110 -0
  42. data/lib/bridgetown-core/filters/grouping_filters.rb +64 -0
  43. data/lib/bridgetown-core/filters/url_filters.rb +79 -0
  44. data/lib/bridgetown-core/frontmatter_defaults.rb +238 -0
  45. data/lib/bridgetown-core/generator.rb +5 -0
  46. data/lib/bridgetown-core/hooks.rb +103 -0
  47. data/lib/bridgetown-core/layout.rb +57 -0
  48. data/lib/bridgetown-core/liquid_extensions.rb +22 -0
  49. data/lib/bridgetown-core/liquid_renderer.rb +71 -0
  50. data/lib/bridgetown-core/liquid_renderer/file.rb +67 -0
  51. data/lib/bridgetown-core/liquid_renderer/table.rb +75 -0
  52. data/lib/bridgetown-core/log_adapter.rb +151 -0
  53. data/lib/bridgetown-core/log_writer.rb +60 -0
  54. data/lib/bridgetown-core/mime.types +867 -0
  55. data/lib/bridgetown-core/page.rb +214 -0
  56. data/lib/bridgetown-core/page_without_a_file.rb +14 -0
  57. data/lib/bridgetown-core/path_manager.rb +31 -0
  58. data/lib/bridgetown-core/plugin.rb +80 -0
  59. data/lib/bridgetown-core/plugin_manager.rb +60 -0
  60. data/lib/bridgetown-core/publisher.rb +23 -0
  61. data/lib/bridgetown-core/reader.rb +185 -0
  62. data/lib/bridgetown-core/readers/collection_reader.rb +22 -0
  63. data/lib/bridgetown-core/readers/data_reader.rb +75 -0
  64. data/lib/bridgetown-core/readers/layout_reader.rb +48 -0
  65. data/lib/bridgetown-core/readers/page_reader.rb +24 -0
  66. data/lib/bridgetown-core/readers/post_reader.rb +74 -0
  67. data/lib/bridgetown-core/readers/static_file_reader.rb +24 -0
  68. data/lib/bridgetown-core/regenerator.rb +195 -0
  69. data/lib/bridgetown-core/related_posts.rb +52 -0
  70. data/lib/bridgetown-core/renderer.rb +261 -0
  71. data/lib/bridgetown-core/site.rb +469 -0
  72. data/lib/bridgetown-core/static_file.rb +205 -0
  73. data/lib/bridgetown-core/tags/component.rb +34 -0
  74. data/lib/bridgetown-core/tags/highlight.rb +111 -0
  75. data/lib/bridgetown-core/tags/include.rb +220 -0
  76. data/lib/bridgetown-core/tags/link.rb +41 -0
  77. data/lib/bridgetown-core/tags/post_url.rb +107 -0
  78. data/lib/bridgetown-core/url.rb +164 -0
  79. data/lib/bridgetown-core/utils.rb +367 -0
  80. data/lib/bridgetown-core/utils/ansi.rb +57 -0
  81. data/lib/bridgetown-core/utils/exec.rb +26 -0
  82. data/lib/bridgetown-core/utils/internet.rb +37 -0
  83. data/lib/bridgetown-core/utils/platforms.rb +80 -0
  84. data/lib/bridgetown-core/utils/thread_event.rb +31 -0
  85. data/lib/bridgetown-core/utils/win_tz.rb +75 -0
  86. data/lib/bridgetown-core/version.rb +5 -0
  87. data/lib/bridgetown-core/watcher.rb +139 -0
  88. data/lib/site_template/.gitignore +6 -0
  89. data/lib/site_template/bridgetown.config.yml +21 -0
  90. data/lib/site_template/frontend/javascript/index.js +3 -0
  91. data/lib/site_template/frontend/styles/index.scss +17 -0
  92. data/lib/site_template/package.json +23 -0
  93. data/lib/site_template/src/404.html +9 -0
  94. data/lib/site_template/src/_data/site_metadata.yml +11 -0
  95. data/lib/site_template/src/_includes/footer.html +3 -0
  96. data/lib/site_template/src/_includes/head.html +9 -0
  97. data/lib/site_template/src/_includes/navbar.html +4 -0
  98. data/lib/site_template/src/_layouts/default.html +15 -0
  99. data/lib/site_template/src/_layouts/home.html +7 -0
  100. data/lib/site_template/src/_layouts/page.html +7 -0
  101. data/lib/site_template/src/_layouts/post.html +7 -0
  102. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +26 -0
  103. data/lib/site_template/src/about.md +11 -0
  104. data/lib/site_template/src/index.md +7 -0
  105. data/lib/site_template/webpack.config.js +60 -0
  106. data/rake/release.rake +30 -0
  107. metadata +106 -1
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
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
13
+
14
+ add_build_options(c)
15
+
16
+ c.action do |_, options|
17
+ options["serving"] = false
18
+ process_with_graceful_fail(c, options, self)
19
+ end
20
+ end
21
+ end
22
+
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)
28
+
29
+ Bridgetown.logger.info "#", "Your Bridgetown #{Bridgetown::VERSION}" \
30
+ " build is about to begin…"
31
+
32
+ options = configuration_from_options(options)
33
+ site = Bridgetown::Site.new(options)
34
+
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(site, options)
40
+ end
41
+
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(site, options)
47
+ else
48
+ Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
49
+ end
50
+ end
51
+
52
+ # Build your Bridgetown site.
53
+ #
54
+ # site - the Bridgetown::Site instance to build
55
+ # options - A Hash of options passed to the command
56
+ #
57
+ # Returns nothing.
58
+ def build(site, options)
59
+ t = Time.now
60
+ source = File.expand_path(options["source"])
61
+ destination = File.expand_path(options["destination"])
62
+ incremental = options["incremental"]
63
+ Bridgetown.logger.info "Source:", source
64
+ Bridgetown.logger.info "Destination:", destination
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 in #{(Time.now - t).round(3)} seconds."
70
+ end
71
+
72
+ # Private: Watch for file changes and rebuild the site.
73
+ #
74
+ # site - A Bridgetown::Site instance
75
+ # options - A Hash of options passed to the command
76
+ #
77
+ # Returns nothing.
78
+ def watch(site, 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
89
+
90
+ # External.require_with_graceful_fail "bridgetown-watch"
91
+ Bridgetown::Watcher.watch(options, site)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Clean < Command
6
+ class << self
7
+ def init_with_program(prog)
8
+ prog.command(:clean) do |c|
9
+ c.syntax "clean [subcommand]"
10
+ c.description "Clean the site " \
11
+ "(removes site output and metadata file) without building."
12
+
13
+ add_build_options(c)
14
+
15
+ c.action do |_, options|
16
+ Bridgetown::Commands::Clean.process(options)
17
+ end
18
+ end
19
+ end
20
+
21
+ def process(options)
22
+ options = configuration_from_options(options)
23
+ destination = options["destination"]
24
+ metadata_file = File.join(options["source"], ".bridgetown-metadata")
25
+ cache_dir = File.join(options["source"], options["cache_dir"])
26
+
27
+ remove(destination, :checker_func => :directory?)
28
+ remove(metadata_file, :checker_func => :file?)
29
+ remove(cache_dir, :checker_func => :directory?)
30
+ end
31
+
32
+ def remove(filename, checker_func: :file?)
33
+ if File.public_send(checker_func, filename)
34
+ Bridgetown.logger.info "Cleaner:", "Removing #{filename}..."
35
+ FileUtils.rm_rf(filename)
36
+ else
37
+ Bridgetown.logger.info "Cleaner:", "Nothing to do for #{filename}."
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "irb"
4
+
5
+ module Bridgetown
6
+ module Commands
7
+ class Console < Command
8
+ class << self
9
+ def init_with_program(prog)
10
+ prog.command(:console) do |c|
11
+ c.syntax "console"
12
+ c.description "Invoke an IRB console with the site loaded"
13
+ c.alias :c
14
+
15
+ c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array,
16
+ "Custom configuration file"
17
+
18
+ c.action do |_, options|
19
+ Bridgetown::Commands::Console.process(options)
20
+ end
21
+ end
22
+ end
23
+
24
+ # TODO: is there a way to add a unit test for this command?
25
+ # rubocop:disable Style/GlobalVars, Metrics/AbcSize, Metrics/MethodLength
26
+ def process(options)
27
+ Bridgetown.logger.info "Starting Bridgetown #{Bridgetown::VERSION} console…"
28
+ site = Bridgetown::Site.new(configuration_from_options(options))
29
+ Bridgetown.logger.info "Loading site…"
30
+ site.reset
31
+ site.read
32
+ site.generate
33
+
34
+ $BRIDGETOWN_SITE = site
35
+ IRB.setup(nil)
36
+ workspace = IRB::WorkSpace.new
37
+ irb = IRB::Irb.new(workspace)
38
+ IRB.conf[:MAIN_CONTEXT] = irb.context
39
+ eval("site = $BRIDGETOWN_SITE", workspace.binding, __FILE__, __LINE__)
40
+ Bridgetown.logger.info "", "Now loaded as " + "site".cyan + " variable."
41
+
42
+ trap("SIGINT") do
43
+ irb.signal_handle
44
+ end
45
+
46
+ begin
47
+ catch(:IRB_EXIT) do
48
+ irb.eval_input
49
+ end
50
+ end
51
+ end
52
+ # rubocop:enable Style/GlobalVars, Metrics/AbcSize, Metrics/MethodLength
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Doctor < Command
6
+ class << self
7
+ def init_with_program(prog)
8
+ prog.command(:doctor) do |c|
9
+ c.syntax "doctor"
10
+ c.description "Search site and print specific deprecation warnings"
11
+
12
+ c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array,
13
+ "Custom configuration file"
14
+
15
+ c.action do |_, options|
16
+ Bridgetown::Commands::Doctor.process(options)
17
+ end
18
+ end
19
+ end
20
+
21
+ def process(options)
22
+ site = Bridgetown::Site.new(configuration_from_options(options))
23
+ site.reset
24
+ site.read
25
+ site.generate
26
+
27
+ if healthy?(site)
28
+ Bridgetown.logger.info "Your test results", "are in. Everything looks fine."
29
+ else
30
+ abort
31
+ end
32
+ end
33
+
34
+ def healthy?(site)
35
+ [
36
+ fsnotify_buggy?(site),
37
+ !deprecated_relative_permalinks(site),
38
+ !conflicting_urls(site),
39
+ !urls_only_differ_by_case(site),
40
+ proper_site_url?(site),
41
+ properly_gathered_posts?(site),
42
+ ].all?
43
+ end
44
+
45
+ def properly_gathered_posts?(site)
46
+ return true if site.config["collections_dir"].empty?
47
+
48
+ posts_at_root = site.in_source_dir("_posts")
49
+ return true unless File.directory?(posts_at_root)
50
+
51
+ Bridgetown.logger.warn "Warning:",
52
+ "Detected '_posts' directory outside custom `collections_dir`!"
53
+ Bridgetown.logger.warn "",
54
+ "Please move '#{posts_at_root}' into the custom directory at " \
55
+ "'#{site.in_source_dir(site.config["collections_dir"])}'"
56
+ false
57
+ end
58
+
59
+ def deprecated_relative_permalinks(site)
60
+ if site.config["relative_permalinks"]
61
+ Bridgetown::Deprecator.deprecation_message "Your site still uses relative permalinks," \
62
+ " which was removed in Bridgetown v0.1"
63
+ true
64
+ end
65
+ end
66
+
67
+ def conflicting_urls(site)
68
+ conflicting_urls = false
69
+ urls = {}
70
+ urls = collect_urls(urls, site.pages, site.dest)
71
+ urls = collect_urls(urls, site.posts.docs, site.dest)
72
+ urls.each do |url, paths|
73
+ next unless paths.size > 1
74
+
75
+ conflicting_urls = true
76
+ Bridgetown.logger.warn "Conflict:", "The URL '#{url}' is the destination" \
77
+ " for the following pages: #{paths.join(", ")}"
78
+ end
79
+ conflicting_urls
80
+ end
81
+
82
+ def fsnotify_buggy?(_site)
83
+ return true unless Utils::Platforms.osx?
84
+
85
+ if Dir.pwd != `pwd`.strip
86
+ Bridgetown.logger.error " " + <<-STR.strip.gsub(%r!\n\s+!, "\n ")
87
+ We have detected that there might be trouble using fsevent on your
88
+ operating system, you can read https://github.com/thibaudgg/rb-fsevent/wiki/no-fsevents-fired-(OSX-bug)
89
+ for possible work arounds or you can work around it immediately
90
+ with `--force-polling`.
91
+ STR
92
+
93
+ false
94
+ end
95
+
96
+ true
97
+ end
98
+
99
+ def urls_only_differ_by_case(site)
100
+ urls_only_differ_by_case = false
101
+ urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
102
+ urls.each_value do |real_urls|
103
+ next unless real_urls.uniq.size > 1
104
+
105
+ urls_only_differ_by_case = true
106
+ Bridgetown.logger.warn "Warning:", "The following URLs only differ" \
107
+ " by case. On a case-insensitive file system one of the URLs" \
108
+ " will be overwritten by the other: #{real_urls.join(", ")}"
109
+ end
110
+ urls_only_differ_by_case
111
+ end
112
+
113
+ def proper_site_url?(site)
114
+ url = site.config["url"]
115
+ [
116
+ url_exists?(url),
117
+ url_valid?(url),
118
+ url_absolute(url),
119
+ ].all?
120
+ end
121
+
122
+ private
123
+
124
+ def collect_urls(urls, things, destination)
125
+ things.each do |thing|
126
+ dest = thing.destination(destination)
127
+ if urls[dest]
128
+ urls[dest] << thing.path
129
+ else
130
+ urls[dest] = [thing.path]
131
+ end
132
+ end
133
+ urls
134
+ end
135
+
136
+ def case_insensitive_urls(things, destination)
137
+ things.each_with_object({}) do |thing, memo|
138
+ dest = thing.destination(destination)
139
+ (memo[dest.downcase] ||= []) << dest
140
+ end
141
+ end
142
+
143
+ def url_exists?(url)
144
+ return true unless url.nil? || url.empty?
145
+
146
+ Bridgetown.logger.warn "Warning:", "You didn't set an URL in the config file, "\
147
+ "you may encounter problems with some plugins."
148
+ false
149
+ end
150
+
151
+ def url_valid?(url)
152
+ Addressable::URI.parse(url)
153
+ true
154
+ # Addressable::URI#parse only raises a TypeError
155
+ # https://git.io/vFfbx
156
+ rescue TypeError
157
+ Bridgetown.logger.warn "Warning:", "The site URL does not seem to be valid, "\
158
+ "check the value of `url` in your config file."
159
+ false
160
+ end
161
+
162
+ def url_absolute(url)
163
+ return true if url.is_a?(String) && Addressable::URI.parse(url).absolute?
164
+
165
+ Bridgetown.logger.warn "Warning:", "Your site URL does not seem to be absolute, "\
166
+ "check the value of `url` in your config file."
167
+ false
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Help < Command
6
+ class << self
7
+ def init_with_program(prog)
8
+ prog.command(:help) do |c|
9
+ c.syntax "help [subcommand]"
10
+ c.description "Show the help message, optionally for a given subcommand."
11
+
12
+ c.action do |args, _|
13
+ cmd = (args.first || "").to_sym
14
+ if args.empty?
15
+ Bridgetown.logger.info prog.to_s
16
+ elsif prog.has_command? cmd
17
+ Bridgetown.logger.info prog.commands[cmd].to_s
18
+ else
19
+ invalid_command(prog, cmd)
20
+ abort
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def invalid_command(prog, cmd)
27
+ Bridgetown.logger.error "Error:",
28
+ "Hmm... we don't know what the '#{cmd}' command is."
29
+ Bridgetown.logger.info "Valid commands:", prog.commands.keys.join(", ")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ module Bridgetown
6
+ module Commands
7
+ class New < Command
8
+ class << self
9
+ DOCSURL = "https://bridgetownrb.com/docs"
10
+
11
+ def init_with_program(prog)
12
+ prog.command(:new) do |c|
13
+ c.syntax "new PATH"
14
+ c.description "Creates a new Bridgetown site scaffold in PATH"
15
+
16
+ c.option "force", "--force", "Force creation even if PATH already exists"
17
+ c.option "skip-bundle", "--skip-bundle", "Skip 'bundle install'"
18
+
19
+ c.action do |args, options|
20
+ Bridgetown::Commands::New.process(args, options)
21
+ end
22
+ end
23
+ end
24
+
25
+ def process(args, options = {})
26
+ raise ArgumentError, "You must specify a path." if args.empty?
27
+
28
+ new_site_path = File.expand_path(args.join(" "), Dir.pwd)
29
+ FileUtils.mkdir_p new_site_path
30
+ if preserve_source_location?(new_site_path, options)
31
+ Bridgetown.logger.error "Conflict:", "#{new_site_path} exists and is not empty."
32
+ Bridgetown.logger.abort_with "", "Ensure #{new_site_path} is empty or else " \
33
+ "try again with `--force` to proceed and overwrite any files."
34
+ end
35
+
36
+ create_site new_site_path
37
+
38
+ after_install(new_site_path, args.join(" "), options)
39
+ end
40
+
41
+ def scaffold_post_content
42
+ ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
43
+ end
44
+
45
+ # Internal: Gets the filename of the sample post to be created
46
+ #
47
+ # Returns the filename of the sample post, as a String
48
+ def initialized_post_name
49
+ "src/_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-bridgetown.md"
50
+ end
51
+
52
+ private
53
+
54
+ def gemfile_contents
55
+ <<~RUBY
56
+ source "https://rubygems.org"
57
+ # Hello! This is where you manage which Bridgetown version is used to run.
58
+ # When you want to use a different version, change it below, save the
59
+ # file and run `bundle install`. Run Bridgetown with `bundle exec`, like so:
60
+ #
61
+ # bundle exec bridgetown serve
62
+ #
63
+ # This will help ensure the proper Bridgetown version is running.
64
+ #
65
+ # To install a plugin, simply run bundle add and specify the group
66
+ # "bridgetown_plugins". For example:
67
+ #
68
+ # bundle add some-new-plugin -g bridgetown_plugins
69
+ #
70
+ # Happy Bridgetowning!
71
+
72
+ gem "bridgetown", "~> #{Bridgetown::VERSION}"
73
+
74
+ RUBY
75
+ end
76
+
77
+ def create_site(new_site_path)
78
+ create_sample_files new_site_path
79
+
80
+ File.open(File.expand_path(initialized_post_name, new_site_path), "w") do |f|
81
+ f.write(scaffold_post_content)
82
+ end
83
+
84
+ File.open(File.expand_path("Gemfile", new_site_path), "w") do |f|
85
+ f.write(gemfile_contents)
86
+ end
87
+ end
88
+
89
+ def preserve_source_location?(path, options)
90
+ !options["force"] && !Dir["#{path}/**/*"].empty?
91
+ end
92
+
93
+ def create_sample_files(path)
94
+ FileUtils.cp_r site_template + "/.", path
95
+ FileUtils.chmod_R "u+w", path
96
+ FileUtils.rm File.expand_path(scaffold_path, path)
97
+ end
98
+
99
+ def site_template
100
+ File.expand_path("../../site_template", __dir__)
101
+ end
102
+
103
+ def scaffold_path
104
+ "src/_posts/0000-00-00-welcome-to-bridgetown.md.erb"
105
+ end
106
+
107
+ # After a new blog has been created, print a success notification and
108
+ # then automatically execute bundle install from within the new blog dir
109
+ # unless the user opts to generate a blank blog or skip 'bundle install'.
110
+ # rubocop:disable Metrics/AbcSize #
111
+ def after_install(path, cli_path, options = {})
112
+ unless options["blank"] || options["skip-bundle"]
113
+ begin
114
+ require "bundler"
115
+ bundle_install path
116
+ rescue LoadError
117
+ Bridgetown.logger.info "Could not load Bundler. Bundle install skipped."
118
+ end
119
+ end
120
+
121
+ Bridgetown.logger.info "Success! 🎉 Your new Bridgetown site was" \
122
+ " generated in #{cli_path.cyan}."
123
+ Bridgetown.logger.info "Execute cd #{cli_path.cyan} to get started."
124
+ Bridgetown.logger.info "You'll probably also want to #{"yarn install".cyan}" \
125
+ " to load in your frontend assets."
126
+ Bridgetown.logger.info "Check out our online documentation for" \
127
+ " next steps: #{DOCSURL.cyan}"
128
+ Bridgetown.logger.info "Bundle install skipped." if options["skip-bundle"]
129
+ end
130
+ # rubocop:enable Metrics/AbcSize #
131
+
132
+ def bundle_install(path)
133
+ Bridgetown.logger.info "Running bundle install in #{path.cyan}..."
134
+ Dir.chdir(path) do
135
+ exe = Gem.bin_path("bundler", "bundle")
136
+ process, output = Bridgetown::Utils::Exec.run("ruby", exe, "install")
137
+
138
+ output.to_s.each_line do |line|
139
+ Bridgetown.logger.info("Bundler:".green, line.strip) unless line.to_s.empty?
140
+ end
141
+
142
+ raise SystemExit unless process.success?
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end