bridgetown-core 0.14.1 → 0.15.0.beta1

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/Rakefile +3 -1
  3. data/bin/bridgetown +9 -23
  4. data/bridgetown-core.gemspec +2 -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 +95 -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 +46 -38
  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 +214 -215
  20. data/lib/bridgetown-core/generators/prototype_generator.rb +2 -0
  21. data/lib/bridgetown-core/liquid_renderer.rb +1 -0
  22. data/lib/bridgetown-core/liquid_renderer/file_system.rb +3 -1
  23. data/lib/bridgetown-core/plugin_manager.rb +4 -4
  24. data/lib/bridgetown-core/renderer.rb +28 -15
  25. data/lib/bridgetown-core/tags/include.rb +12 -0
  26. data/lib/bridgetown-core/tags/render_content.rb +27 -16
  27. data/lib/bridgetown-core/tags/with.rb +15 -0
  28. data/lib/bridgetown-core/version.rb +2 -2
  29. data/lib/bridgetown-core/watcher.rb +17 -10
  30. data/lib/site_template/Gemfile.erb +19 -0
  31. data/lib/site_template/src/_components/footer.html +3 -0
  32. data/lib/site_template/src/_components/head.html +9 -0
  33. data/lib/site_template/src/{_includes → _components}/navbar.html +0 -0
  34. data/lib/site_template/src/_layouts/default.html +3 -3
  35. data/lib/site_template/start.js +1 -1
  36. metadata +39 -19
  37. data/lib/bridgetown-core/command.rb +0 -112
  38. data/lib/bridgetown-core/commands/help.rb +0 -34
  39. data/lib/site_template/src/_components/.keep +0 -0
  40. data/lib/site_template/src/_includes/footer.html +0 -3
  41. data/lib/site_template/src/_includes/head.html +0 -9
@@ -1,187 +1,152 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "erb"
4
-
5
3
  module Bridgetown
6
4
  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
- c.option "skip-yarn", "--skip-yarn", "Skip 'yarn install'"
19
-
20
- c.action do |args, options|
21
- Bridgetown::Commands::New.process(args, options)
22
- end
23
- end
24
- end
25
-
26
- def process(args, options = {})
27
- raise ArgumentError, "You must specify a path." if args.empty?
28
-
29
- new_site_path = File.expand_path(args.join(" "), Dir.pwd)
30
- FileUtils.mkdir_p new_site_path
31
- if preserve_source_location?(new_site_path, options)
32
- Bridgetown.logger.error "Conflict:", "#{new_site_path} exists and is not empty."
33
- Bridgetown.logger.abort_with "", "Ensure #{new_site_path} is empty or else " \
34
- "try again with `--force` to proceed and overwrite any files."
35
- end
36
-
37
- Bridgetown.logger.info("Creating:".green, new_site_path)
5
+ class New < Thor::Group
6
+ include Thor::Actions
7
+ extend Summarizable
38
8
 
39
- create_site new_site_path
40
-
41
- after_install(new_site_path, args.join(" "), options)
42
- end
43
-
44
- def scaffold_post_content
45
- ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
46
- end
47
-
48
- # Internal: Gets the filename of the sample post to be created
49
- #
50
- # Returns the filename of the sample post, as a String
51
- def initialized_post_name
52
- "src/_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-bridgetown.md"
53
- end
9
+ Registrations.register do
10
+ register(New, "new", "new PATH", New.summary)
11
+ end
54
12
 
55
- private
56
-
57
- def gemfile_contents
58
- <<~RUBY
59
- source "https://rubygems.org"
60
- # Hello! This is where you manage which Bridgetown version is used to run.
61
- # When you want to use a different version, change it below, save the
62
- # file and run `bundle install`. Run Bridgetown with `bundle exec`, like so:
63
- #
64
- # bundle exec bridgetown serve
65
- #
66
- # This will help ensure the proper Bridgetown version is running.
67
- #
68
- # To install a plugin, simply run bundle add and specify the group
69
- # "bridgetown_plugins". For example:
70
- #
71
- # bundle add some-new-plugin -g bridgetown_plugins
72
- #
73
- # Happy Bridgetowning!
74
-
75
- gem "bridgetown", "~> #{Bridgetown::VERSION}"
76
-
77
- RUBY
78
- end
13
+ def self.banner
14
+ "bridgetown new PATH"
15
+ end
16
+ summary "Creates a new Bridgetown site scaffold in PATH"
17
+
18
+ class_option :apply,
19
+ aliases: "-a",
20
+ banner: "PATH|URL",
21
+ desc: "Apply an automation after creating the site scaffold"
22
+ class_option :force,
23
+ type: :boolean,
24
+ desc: "Force creation even if PATH already exists"
25
+ class_option :"skip-bundle",
26
+ type: :boolean,
27
+ desc: "Skip 'bundle install'"
28
+ class_option :"skip-yarn",
29
+ type: :boolean,
30
+ desc: "Skip 'yarn install'"
31
+
32
+ DOCSURL = "https://bridgetownrb.com/docs"
33
+
34
+ def self.exit_on_failure?
35
+ false
36
+ end
79
37
 
80
- def create_site(new_site_path)
81
- create_sample_files new_site_path
38
+ def self.source_root
39
+ File.expand_path("../../site_template", __dir__)
40
+ end
82
41
 
83
- File.open(File.expand_path(initialized_post_name, new_site_path), "w") do |f|
84
- f.write(scaffold_post_content)
85
- end
42
+ class << self
43
+ attr_accessor :created_site_dir
44
+ end
86
45
 
87
- File.open(File.expand_path("Gemfile", new_site_path), "w") do |f|
88
- f.write(gemfile_contents)
89
- end
90
- end
46
+ def new_site
47
+ raise ArgumentError, "You must specify a path." if args.empty?
91
48
 
92
- def preserve_source_location?(path, options)
93
- !options["force"] && !Dir["#{path}/**/*"].empty?
49
+ new_site_path = File.expand_path(args.join(" "), Dir.pwd)
50
+ if preserve_source_location?(new_site_path, options)
51
+ say_status :conflict, "#{new_site_path} exists and is not empty.", :red
52
+ Bridgetown.logger.abort_with "Ensure #{new_site_path} is empty or else " \
53
+ "try again with `--force` to proceed and overwrite any files."
94
54
  end
95
55
 
96
- def create_sample_files(path)
97
- FileUtils.cp_r site_template + "/.", path
98
- FileUtils.chmod_R "u+w", path
99
- FileUtils.rm File.expand_path(scaffold_path, path)
100
- end
56
+ self.destination_root = self.class.created_site_dir = new_site_path
101
57
 
102
- def site_template
103
- File.expand_path("../../site_template", __dir__)
104
- end
58
+ say_status :create, new_site_path
59
+ create_site new_site_path
60
+ after_install new_site_path, args.join(" "), options
61
+ end
105
62
 
106
- def scaffold_path
107
- "src/_posts/0000-00-00-welcome-to-bridgetown.md.erb"
108
- end
63
+ protected
109
64
 
110
- # After a new site has been created, print a success notification and
111
- # then automatically execute bundle install from within the new site dir
112
- # unless the user opts to skip 'bundle install'.
113
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength #
114
- def after_install(path, cli_path, options = {})
115
- logger = Bridgetown.logger
116
- git_init path
117
-
118
- unless options["skip-bundle"]
119
- begin
120
- require "bundler"
121
- bundle_install path
122
- rescue LoadError
123
- logger.info "Could not load Bundler. Bundle install skipped."
124
- end
125
- end
65
+ def preserve_source_location?(path, options)
66
+ !options["force"] && Dir.exist?(path)
67
+ end
126
68
 
127
- yarn_install path unless options["skip-yarn"]
69
+ def create_site(new_site_path)
70
+ directory ".", ".", exclude_pattern: %r!\.erb|DS_Store$!
71
+ FileUtils.chmod_R "u+w", new_site_path
128
72
 
129
- yarn_start = "yarn start"
73
+ template(
74
+ "src/_posts/0000-00-00-welcome-to-bridgetown.md.erb",
75
+ "src/_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-bridgetown.md"
76
+ )
77
+ template("Gemfile.erb", "Gemfile")
78
+ end
130
79
 
131
- logger.info "Success!".green, "🎉 Your new Bridgetown site was" \
132
- " generated in #{cli_path.cyan}."
133
- if options["skip-yarn"]
134
- logger.info "You can now #{"cd".cyan} #{cli_path.cyan} to get started."
135
- logger.info "You'll probably also want to #{"yarn install".cyan}" \
136
- " to load in your frontend assets."
137
- else
138
- logger.info "You can now #{"cd".cyan} and run #{yarn_start.cyan} to get started."
139
- end
140
- logger.info "Then check out our online documentation for" \
141
- " next steps: #{DOCSURL.cyan}"
142
- logger.info "Bundle install skipped." if options["skip-bundle"]
80
+ # After a new site has been created, print a success notification and
81
+ # then automatically execute bundle install from within the new site dir
82
+ # unless the user opts to skip 'bundle install'.
83
+ # rubocop:todo Metrics/CyclomaticComplexity
84
+ def after_install(path, cli_path, options = {})
85
+ git_init path
86
+
87
+ @skipped_bundle = true # is set to false if bundle install worked
88
+ bundle_install path unless options["skip-bundle"]
89
+
90
+ @skipped_yarn = true
91
+ yarn_install path unless options["skip-yarn"]
92
+
93
+ invoke(Apply, [], options) if options[:apply]
94
+
95
+ logger = Bridgetown.logger
96
+ yarn_start = "yarn start"
97
+ logger.info ""
98
+ logger.info "Success!".green, "🎉 Your new Bridgetown site was" \
99
+ " generated in #{cli_path.cyan}."
100
+ if options["skip-yarn"]
101
+ logger.info "You can now #{"cd".cyan} #{cli_path.cyan} to get started."
102
+ logger.info "You'll probably also want to #{"yarn install".cyan}" \
103
+ " to load in your frontend assets."
104
+ else
105
+ logger.info "You can now #{"cd".cyan} and run #{yarn_start.cyan} to get started."
143
106
  end
144
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength #
107
+ logger.info "Then check out our online documentation for" \
108
+ " next steps: #{DOCSURL.cyan}"
145
109
 
146
- def bundle_install(path)
147
- Bridgetown.logger.info "Running bundle install in #{path.cyan}..."
148
- Dir.chdir(path) do
149
- exe = Gem.bin_path("bundler", "bundle")
150
- process, output = Bridgetown::Utils::Exec.run("ruby", exe, "install")
151
-
152
- output.to_s.each_line do |line|
153
- Bridgetown.logger.info("Bundler:".green, line.strip) unless line.to_s.empty?
110
+ logger.info "Bundle install skipped.".yellow if @skipped_bundle
111
+ logger.info "Yarn install skipped.".yellow if @skipped_yarn
112
+ end
113
+ # rubocop:enable Metrics/CyclomaticComplexity
114
+
115
+ def bundle_install(path)
116
+ unless Bridgetown.environment == "test"
117
+ require "bundler"
118
+ Bundler.with_clean_env do
119
+ inside(path) do
120
+ run "bundle install", abort_on_failure: true
154
121
  end
155
-
156
- raise SystemExit unless process.success?
157
122
  end
158
123
  end
124
+ @skipped_bundle = false
125
+ rescue LoadError
126
+ say_status :run, "Could not load Bundler. Bundle install skipped.", :red
127
+ rescue SystemExit
128
+ say_status :run, "Problem occured while running bundle install.", :red
129
+ end
159
130
 
160
- def git_init(path)
161
- Dir.chdir(path) do
162
- _process, output = Bridgetown::Utils::Exec.run("git", "init")
163
- output.to_s.each_line do |line|
164
- Bridgetown.logger.info("Git:".green, line.strip) unless line.to_s.empty?
165
- end
131
+ def git_init(path)
132
+ unless Bridgetown.environment == "test"
133
+ inside(path) do
134
+ run "git init", abort_on_failure: true
166
135
  end
167
- rescue SystemCallError
168
136
  end
137
+ rescue SystemExit
138
+ say_status :run, "Could not load git. git init skipped.", :red
139
+ end
169
140
 
170
- def yarn_install(path)
171
- Bridgetown.logger.info "Running yarn install in #{path.cyan}..."
172
- Dir.chdir(path) do
173
- _process, output = Bridgetown::Utils::Exec.run("yarn", "install")
174
- output.to_s.each_line do |line|
175
- next if line.to_s.empty? ||
176
- line.strip.start_with?("warning ") ||
177
- line.include?("No lockfile found")
178
-
179
- Bridgetown.logger.info("Yarn:".green, line.strip)
180
- end
141
+ def yarn_install(path)
142
+ unless Bridgetown.environment == "test"
143
+ inside(path) do
144
+ run "yarn install", abort_on_failure: true
181
145
  end
182
- rescue SystemCallError
183
- Bridgetown.logger.info "Could not load yarn. yarn install skipped."
184
146
  end
147
+ @skipped_yarn = false
148
+ rescue SystemExit
149
+ say_status :run, "Could not load yarn. yarn install skipped.", :red
185
150
  end
186
151
  end
187
152
  end
@@ -2,166 +2,203 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Commands
5
- class Plugins < Command
6
- class << self
7
- def init_with_program(prog)
8
- plugins_cmd = prog.command(:plugins) do |c|
9
- c.syntax "plugins <subcommand>"
10
- c.description "List installed plugins or access plugin content"
11
-
12
- c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array,
13
- "Custom configuration file"
14
-
15
- c.action do
16
- output_supercommand_syntax(c)
17
- end
18
- end
5
+ class Plugins < Thor
6
+ include Thor::Actions
7
+ include ConfigurationOverridable
19
8
 
20
- plugins_cmd.command(:list) do |subcmd|
21
- subcmd.syntax "list"
22
- subcmd.description "List information about installed plugins"
9
+ Registrations.register do
10
+ desc "plugins <command>", "List installed plugins or access plugin content"
11
+ subcommand "plugins", Plugins
12
+ end
23
13
 
24
- subcmd.action do |_, options|
25
- list(options)
26
- end
27
- end
14
+ desc "list", "List information about installed plugins"
15
+ def list
16
+ site = Bridgetown::Site.new(configuration_with_overrides(options))
17
+ site.reset
18
+ Bridgetown::Hooks.trigger :site, :pre_read, site
28
19
 
29
- plugins_cmd.command(:cd) do |subcmd|
30
- subcmd.syntax "cd <origin/dir>"
31
- subcmd.description "Open directory (content, layouts, etc.) within the plugin origin"
20
+ pm = site.plugin_manager
32
21
 
33
- subcmd.action do |args, options|
34
- if args.empty?
35
- puts subcmd.to_s
36
- else
37
- cd(args, options)
38
- end
39
- end
40
- end
22
+ plugins_list = pm.class.registered_plugins.reject do |plugin|
23
+ plugin.to_s.end_with? "site_builder.rb"
41
24
  end
42
25
 
43
- def output_supercommand_syntax(supercmd)
44
- puts supercmd.to_s
26
+ Bridgetown.logger.info("Registered Plugins:", plugins_list.length.to_s.yellow.bold)
27
+
28
+ plugins_list.each do |plugin|
29
+ unless plugin.to_s.end_with? "site_builder.rb"
30
+ Bridgetown.logger.info("", plugin.to_s.sub(site.in_root_dir("/"), ""))
31
+ end
45
32
  end
46
33
 
47
- def list(options)
48
- site = Bridgetown::Site.new(configuration_from_options(options))
49
- site.reset
50
- Bridgetown::Hooks.trigger :site, :pre_read, site
34
+ Bridgetown.logger.info("Source Manifests:", "---") unless pm.class.source_manifests.empty?
51
35
 
52
- pm = site.plugin_manager
36
+ pm.class.source_manifests.each do |manifest|
37
+ Bridgetown.logger.info("Origin:", (manifest.origin || "n/a").to_s.green)
38
+ Bridgetown.logger.info("Components:", (manifest.components || "n/a").to_s.cyan)
39
+ Bridgetown.logger.info("Content:", (manifest.content || "n/a").to_s.cyan)
40
+ Bridgetown.logger.info("Layouts:", (manifest.layouts || "n/a").to_s.cyan)
53
41
 
54
- plugins_list = pm.class.registered_plugins.reject do |plugin|
55
- plugin.to_s.end_with? "site_builder.rb"
56
- end
42
+ Bridgetown.logger.info("", "---")
43
+ end
57
44
 
58
- Bridgetown.logger.info("Registered Plugins:", plugins_list.length.to_s.yellow.bold)
45
+ unless Bridgetown.autoload? :Builder
46
+ builders = Bridgetown::Builder.descendants
47
+ Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)
59
48
 
60
- plugins_list.each do |plugin|
61
- unless plugin.to_s.end_with? "site_builder.rb"
62
- Bridgetown.logger.info("", plugin.to_s.sub(site.in_root_dir("/"), ""))
63
- end
49
+ builders.each do |builder|
50
+ name = builder.respond_to?(:custom_name) ? builder.custom_name : builder.name
51
+ name_components = name.split("::")
52
+ last_name = name_components.pop
53
+ name_components.push last_name.magenta
54
+ Bridgetown.logger.info("", name_components.join("::"))
64
55
  end
56
+ end
65
57
 
66
- Bridgetown.logger.info("Source Manifests:", "---") unless pm.class.source_manifests.empty?
58
+ Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)
67
59
 
68
- pm.class.source_manifests.each do |manifest|
69
- Bridgetown.logger.info("Origin:", (manifest.origin || "n/a").to_s.green)
70
- Bridgetown.logger.info("Components:", (manifest.components || "n/a").to_s.cyan)
71
- Bridgetown.logger.info("Content:", (manifest.content || "n/a").to_s.cyan)
72
- Bridgetown.logger.info("Layouts:", (manifest.layouts || "n/a").to_s.cyan)
60
+ site.converters.each do |converter|
61
+ name = plugin_name_for(converter)
62
+ name_components = name.split("::")
63
+ last_name = name_components.pop
64
+ name_components.push last_name.magenta
65
+ Bridgetown.logger.info("", name_components.join("::"))
66
+ end
73
67
 
74
- Bridgetown.logger.info("", "---")
75
- end
68
+ Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)
76
69
 
77
- unless Bridgetown.autoload? :Builder
78
- builders = Bridgetown::Builder.descendants
79
- Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)
70
+ site.generators.each do |generator|
71
+ name = plugin_name_for(generator)
72
+ name_components = name.split("::")
73
+ last_name = name_components.pop
74
+ name_components.push last_name.magenta
75
+ Bridgetown.logger.info("", name_components.join("::"))
76
+ end
77
+ end
78
+
79
+ long_desc <<-DOC
80
+ Open a directory (content, layouts, etc.) within the plugin origin. \n
81
+ First run bridgetown plugins list to view source manifests currently
82
+ set up on your site.\n
83
+ Then look for the origin of the manifest and the folder you'd like to
84
+ open.\n
85
+ So for example, with an origin of SamplePlugin and a folder of
86
+ Layouts, you'd run:\n
87
+ bridgetown plugins cd SamplePlugin/Layouts
88
+ DOC
89
+ desc "cd <origin/dir>", "Open folder (content, layouts, etc.) within the plugin origin"
90
+
91
+ # This is super useful if you want to copy files out of plugins to override.
92
+ #
93
+ # Example:
94
+ # bridgetown plugins cd AwesomePlugin/layouts
95
+ # cp -r * $BRIDGETOWN_SITE/src/_layouts
96
+ #
97
+ # Now all the plugin's layouts will be in the site repo directly.
98
+ #
99
+ def cd(arg)
100
+ site = Bridgetown::Site.new(configuration_with_overrides(options))
101
+
102
+ pm = site.plugin_manager
103
+
104
+ directive = arg.split("/")
105
+ unless directive[1]
106
+ Bridgetown.logger.warn("Oops!", "Your command needs to be in the <origin/dir> format")
107
+ return
108
+ end
109
+
110
+ manifest = pm.class.source_manifests.find do |source_manifest|
111
+ source_manifest.origin.to_s == directive[0]
112
+ end
80
113
 
81
- builders.each do |builder|
82
- name = builder.respond_to?(:custom_name) ? builder.custom_name : builder.name
83
- name_components = name.split("::")
84
- last_name = name_components.pop
85
- name_components.push last_name.magenta
86
- Bridgetown.logger.info("", name_components.join("::"))
114
+ if manifest&.respond_to?(directive[1].downcase)
115
+ dir = manifest.send(directive[1].downcase)
116
+ Bridgetown.logger.info("Opening the #{dir.green} folder for" \
117
+ " #{manifest.origin.to_s.cyan}…")
118
+ Bridgetown.logger.info("Type #{"exit".yellow} when you're done to" \
119
+ " return to your site root.")
120
+ puts
121
+
122
+ Dir.chdir dir do
123
+ ENV["BRIDGETOWN_SITE"] = site.root_dir
124
+ if ENV["SHELL"]
125
+ system(ENV["SHELL"])
126
+ else
127
+ system("/bin/sh")
87
128
  end
88
129
  end
89
130
 
90
- Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)
131
+ puts
132
+ Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
133
+ else
134
+ Bridgetown.logger.warn("Oops!", "I wasn't able to find the" \
135
+ " #{directive[1]} folder for #{directive[0]}")
136
+ end
137
+ end
91
138
 
92
- site.converters.each do |converter|
93
- name = plugin_name_for(converter)
94
- name_components = name.split("::")
95
- last_name = name_components.pop
96
- name_components.push last_name.magenta
97
- Bridgetown.logger.info("", name_components.join("::"))
98
- end
139
+ desc "new NAME", "Create a new plugin NAME (please-use-dashes) by" \
140
+ " cloning the sample plugin repo"
141
+ # rubocop:disable Layout/LineLength
142
+ def new(plugin_name)
143
+ folder_name = plugin_name.underscore
144
+ name = folder_name.dasherize
145
+ module_name = folder_name.camelize
99
146
 
100
- Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)
147
+ run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
148
+ new_gemspec = "#{name}.gemspec"
101
149
 
102
- site.generators.each do |generator|
103
- name = plugin_name_for(generator)
104
- name_components = name.split("::")
105
- last_name = name_components.pop
106
- name_components.push last_name.magenta
107
- Bridgetown.logger.info("", name_components.join("::"))
108
- end
109
- end
150
+ inside name do # rubocop:todo Metrics/BlockLength
151
+ run "rm -rf .git"
152
+ run "git init"
110
153
 
111
- # This is super useful if you want to copy files out of plugins to override.
112
- #
113
- # Example:
114
- # bridgetown plugins cd AwesomePlugin/layouts
115
- # cp -r * $BRIDGETOWN_SITE/src/_layouts
116
- #
117
- # Now all the plugin's layouts will be in the site repo directly.
118
- #
119
- def cd(args, options)
120
- site = Bridgetown::Site.new(configuration_from_options(options))
121
-
122
- pm = site.plugin_manager
123
-
124
- directive = args[0].split("/")
125
- unless directive[1]
126
- Bridgetown.logger.warn("Oops!", "Your command needs to be in the <origin/dir> format")
127
- return
128
- end
154
+ run "mv bridgetown-sample-plugin.gemspec #{new_gemspec}"
155
+ gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
156
+ gsub_file new_gemspec, "bridgetown-sample-plugin", name
157
+ gsub_file new_gemspec, "sample-plugin", name
158
+ gsub_file new_gemspec, "SamplePlugin", module_name
129
159
 
130
- manifest = pm.class.source_manifests.find do |source_manifest|
131
- source_manifest.origin.to_s == directive[0]
132
- end
160
+ gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
161
+ gsub_file "package.json", "bridgetown-sample-plugin", name
133
162
 
134
- if manifest&.respond_to?(directive[1].downcase)
135
- dir = manifest.send(directive[1].downcase)
136
- Bridgetown.logger.info("Opening the #{dir.green} folder for" \
137
- " #{manifest.origin.to_s.cyan}…")
138
- Bridgetown.logger.info("Type #{"exit".yellow} when you're done to" \
139
- " return to your site root.")
140
- puts
141
-
142
- Dir.chdir dir do
143
- ENV["BRIDGETOWN_SITE"] = site.root_dir
144
- if ENV["SHELL"]
145
- system(ENV["SHELL"])
146
- else
147
- system("/bin/sh")
148
- end
149
- end
163
+ run "mv lib/sample-plugin.rb lib/#{name}.rb"
164
+ gsub_file "lib/#{name}.rb", "sample-plugin", name
165
+ gsub_file "lib/#{name}.rb", "SamplePlugin", module_name
150
166
 
151
- puts
152
- Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
153
- else
154
- Bridgetown.logger.warn("Oops!", "I wasn't able to find the" \
155
- " #{directive[1]} folder for #{directive[0]}")
156
- end
167
+ run "mv lib/sample-plugin lib/#{name}"
168
+ gsub_file "lib/#{name}/builder.rb", "SamplePlugin", module_name
169
+ gsub_file "lib/#{name}/version.rb", "SamplePlugin", module_name
170
+
171
+ run "mv spec/sample-plugin_spec.rb spec/#{name}_spec.rb"
172
+ gsub_file "spec/#{name}_spec.rb", "SamplePlugin", module_name
173
+ gsub_file "spec/spec_helper.rb", "sample-plugin", name
174
+
175
+ run "mv components/sample_plugin components/#{folder_name}"
176
+ run "mv content/sample_plugin content/#{folder_name}"
177
+ run "mv layouts/sample_plugin layouts/#{folder_name}"
178
+
179
+ gsub_file "layouts/#{folder_name}/layout.html", "sample_plugin", folder_name
180
+ gsub_file "content/#{folder_name}/example_page.md", "sample_plugin", folder_name
181
+ gsub_file "components/#{folder_name}/layout_help.liquid", "sample_plugin", folder_name
182
+
183
+ gsub_file "frontend/javascript/index.js", "bridgetown-sample-plugin", name
184
+ gsub_file "frontend/javascript/index.js", "SamplePlugin", module_name
157
185
  end
186
+ say ""
187
+ say_status "Done!", "Have fun writing your new #{name} plugin :)"
188
+ say_status "Remember:", "Don't forget to rename the SamplePlugin" \
189
+ " code identifiers and paths to your own" \
190
+ " indentifer, as well as update your README " \
191
+ " and CHANGELOG files as necessary."
192
+ end
193
+ # rubocop:enable Layout/LineLength
158
194
 
159
- def plugin_name_for(plugin)
160
- if plugin.class.respond_to?(:custom_name)
161
- plugin.class.custom_name
162
- else
163
- plugin.class.name
164
- end
195
+ protected
196
+
197
+ def plugin_name_for(plugin)
198
+ if plugin.class.respond_to?(:custom_name)
199
+ plugin.class.custom_name
200
+ else
201
+ plugin.class.name
165
202
  end
166
203
  end
167
204
  end