Skip to content

Commit

Permalink
Added js installer
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerldixon committed Nov 8, 2024
1 parent 294b7cd commit 963544e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Boilerplate comes with the following modules...
| RobotsTxt | Disable OpenAI's GPTBot web crawler in the `robots.txt` file |
| RemoveTrailingSlashes | Removes trailing slashes from urls (https://tosbourn.com/ruby-on-rails-seo/#remove-trailing-slashes) |
| GoodJob | a PostgreSQL backed ActiveJob backend. Installs the dashboard too, authenticated for admins only |
| Seeds | Adds a test admin account to the `seeds.rb` file with the username `[email protected]` and password `test1234test` |
| Seeds | Adds a test admin account to the `seeds.rb` file with the username `[email protected]` and password `test1234` |
| Gitignore | Adds sensible defaults to the `.gitignore` file |

### Coming soon / In Progress
Expand Down
11 changes: 6 additions & 5 deletions bin/boilerplate
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ require 'boilerplate'
require 'optparse'

TEMPLATES_PATH = File.join(Gem.loaded_specs["boilerplate"].full_gem_path, "lib", "boilerplate", "templates")
MODULES_PATH = File.join(Gem.loaded_specs["boilerplate"].full_gem_path, "lib", "boilerplate", "modules")

options = {}

OptionParser.new do |opts|
opts.on("--omakase") do |v|
options[:omakase] = true
end
end.parse!
end.parse

puts <<-TEXT
Expand All @@ -28,13 +29,13 @@ case ARGV
in ["new", name, *args]
if options[:omakase]
# Silent omakase install
system("rails new #{name} -d postgresql -c tailwind -m #{TEMPLATES_PATH}/omakase.rb --boilerplate-silent=true")
system("rails new #{name} -d postgresql -c tailwind -m #{TEMPLATES_PATH}/omakase.rb --boilerplate-silent=true #{args.join(' ')}")
else
# Prompted custom install
system("rails new #{name} -d postgresql -c tailwind -m #{TEMPLATES_PATH}/omakase.rb")
system("rails new #{name} -c tailwind -m #{TEMPLATES_PATH}/omakase.rb #{args.join(' ')}")
end
# in ["app:template", "-x", module_name]
# system("rails app:template LOCATION=boilerplate/modules/#{module_name}.rb")
in ["app:template", "-x", module_name]
system("rails app:template LOCATION=#{TEMPLATES_PATH}/#{module_name}.rb")
else
puts <<-TEXT
USAGE:
Expand Down
8 changes: 5 additions & 3 deletions lib/boilerplate/helpers/js_installer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module JsInstaller
def install_package_with(package_manager=:importmaps, package_name)
case package_manager
when :importmaps do
case package_manager.to_sym
when :importmaps then
run "./bin/importmap pin #{package_name}"
when :bun do
when :bun then
run "bun install #{package_name}"
when :npm then
run "npm install #{package_name}"
end
end
end
12 changes: 4 additions & 8 deletions lib/boilerplate/modules/font_awesome.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
require "tty-prompt"
require "boilerplate/helpers/js_installer.rb"

module FontAwesome
include JsInstaller

def install_font_awesome(silent: false, javascript:, **)
prompt = TTY::Prompt.new(quiet: true)

after_bundle do
if silent || prompt.yes?("Install FontAwesome?")
case javascript.to_sym
when :importmap
run "./bin/importmap pin @fortawesome/fontawesome-free"
when :bun
run "bun add @fortawesome/fontawesome-free"
else
run "npm install @fortawesome/fontawesome-free"
end
install_package_with(javascript.to_sym, "@fortawesome/fontawesome-free")

append_to_file 'app/javascript/application.js' do
<<-eos
Expand Down
1 change: 0 additions & 1 deletion lib/boilerplate/modules/gitignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def install_gitignore(silent: false, **)
prompt = TTY::Prompt.new(quiet: true)

if silent || prompt.yes?("Extend gitignore to ignore database dumps, per environment credential keys, and macos default files?")
# Install metatags
append_to_file '.gitignore' do
<<-eos
.env
Expand Down
4 changes: 3 additions & 1 deletion lib/boilerplate/templates/omakase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
require 'boilerplate/modules/robots.rb'
require 'boilerplate/modules/remove_trailing_slashes.rb'
require 'boilerplate/modules/good_job.rb'
require 'boilerplate/modules/seeds.rb'
require 'boilerplate/modules/gitignore.rb'
require 'pp'

# List modules in the order they should be applied

MODULES = %w(
DaisyUi
Devise
Expand All @@ -28,7 +31,6 @@

# Since this file runs in the context of the rails generator, get the config from the main scope of our cli (bin/boilerplate)


class Omakase
def initialize(generator:)
@generator = generator
Expand Down

0 comments on commit 963544e

Please sign in to comment.