Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StimulusReflex 3.5 installer #610

Merged
merged 108 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
2ee4005
first pass installer, webpacker
leastbad Sep 23, 2022
dbf121e
esbuild support
leastbad Sep 24, 2022
1bb65de
tweaked append_file verbosity
leastbad Sep 24, 2022
c2431de
fussy, obscure Rubocop rule pleasing
leastbad Sep 25, 2022
fca2958
temporarily commented StimulusReflexGeneratorTest
leastbad Sep 25, 2022
fc5bffa
removed trailing comma typo
leastbad Sep 26, 2022
e9e26ef
first pass importmap support
leastbad Sep 26, 2022
f6f2685
removed unnecessary braces
leastbad Sep 27, 2022
b22ade0
Update lib/generators/stimulus_reflex/templates/app/javascript/applic…
leastbad Sep 28, 2022
dad8562
Update lib/generators/stimulus_reflex/templates/app/javascript/config…
leastbad Sep 28, 2022
95a7508
Update lib/generators/stimulus_reflex/templates/app/javascript/contro…
leastbad Sep 28, 2022
5715fcc
Update lib/generators/stimulus_reflex/templates/app/javascript/applic…
leastbad Sep 28, 2022
1e7c3fc
no need to create entrypoint pack file
leastbad Sep 29, 2022
b2ee0fb
half too clever
leastbad Oct 5, 2022
984c2d5
Update test/generators/stimulus_reflex_generator_test.rb
leastbad Oct 5, 2022
62a00fb
restore StimulusReflexGeneratorTest
leastbad Oct 5, 2022
ab96317
not all heroes wear capes
leastbad Oct 6, 2022
f3bacea
create add/remove gem with bundle step, split development/redis into …
leastbad Oct 6, 2022
1882207
Update lib/generators/stimulus_reflex/templates/app/javascript/contro…
leastbad Oct 6, 2022
79ebaa4
standardrb
leastbad Oct 6, 2022
ef4ad1c
CLI options
leastbad Oct 31, 2022
c06b483
standardrb
leastbad Nov 1, 2022
8f2f31c
accept bundler option in any position
leastbad Nov 1, 2022
42fa189
bundle can't run in rake task
leastbad Nov 1, 2022
3447646
missed Debug import
leastbad Nov 1, 2022
1481251
shakapacker support for Rails 6.1 and 7
leastbad Nov 6, 2022
59069e1
Vite support for Rails 6.1 and 7
leastbad Nov 7, 2022
eb73b9a
Rails.logger
leastbad Nov 9, 2022
0c16f4f
stimulus_reflex generator now supports destroy
leastbad Nov 13, 2022
2676ca6
text example_path exists
leastbad Nov 13, 2022
d25a5e8
configure Action View to generate remote forms by default
leastbad Nov 19, 2022
f80a634
create action_cable.rb initializer and silence logger
leastbad Nov 19, 2022
9213a44
standardrb
leastbad Nov 20, 2022
11a0633
add optional step to enable permessage-deflate compression for WS tra…
leastbad Nov 21, 2022
7919b4a
installer now downloads step templates from GH before falling back to…
leastbad Nov 22, 2022
f7eca77
prepend CableReady::Broadcaster into StateMachines::Machine
leastbad Nov 24, 2022
258df3a
add local mode CLI flag
leastbad Nov 25, 2022
2176088
convert config files that would provoke Bundler to new working folder…
leastbad Nov 26, 2022
41f773b
yank CR mascot out of rake task
leastbad Nov 26, 2022
93a4851
redis-session-store 0.11.5
leastbad Nov 28, 2022
fc66b4f
removed development caching requirement from SR
leastbad Nov 28, 2022
2bcd38c
removed ambiguity re Action Cable initializer working copy
leastbad Nov 29, 2022
4b8bb9b
standardrb
leastbad Nov 29, 2022
d8e489b
no longer need to install redis gem specifically
leastbad Dec 4, 2022
81cafa5
install action-cable-redis-backport gem
leastbad Dec 4, 2022
34d25af
example is now examples
leastbad Dec 10, 2022
81d0841
reworked installer to support remote fetch and new installer.rb commo…
leastbad Dec 18, 2022
2f40a6c
fix bug with fetch path
leastbad Dec 18, 2022
3410009
fix fetch timeout
leastbad Dec 18, 2022
4e55be9
fetch paths resolve properly
leastbad Dec 18, 2022
2525c9f
fetch will be the end of me
leastbad Dec 19, 2022
2783e81
timeout needs to be an integer
leastbad Dec 19, 2022
32cfd95
standardrb
leastbad Dec 19, 2022
054a735
entrypoint must be a Pathname
leastbad Dec 19, 2022
bc8c0da
ingested CableReady example into SR
leastbad Dec 20, 2022
0350690
fixed issue with step_path
leastbad Dec 22, 2022
d1f17b9
tweak example to chill if Turbo isn't defined
leastbad Dec 22, 2022
141b0ee
ERB problems
leastbad Dec 22, 2022
44411f9
omfg ERB diaf
leastbad Dec 22, 2022
8c49782
add branch option
leastbad Dec 25, 2022
61ec15a
add Current and helpers examples to ApplicationReflex template
leastbad Dec 25, 2022
abf4dea
tweaks discovered finalizing CR installer
leastbad Dec 26, 2022
a932185
remove unnecessary initializer generator
leastbad Dec 26, 2022
022c2c8
modified generator to pin if using importmaps
leastbad Dec 27, 2022
c949351
standardrb
leastbad Dec 27, 2022
3086482
mrujs not installed warning
leastbad Dec 27, 2022
736ab98
bump bundler to 2.4.1 and add copy to example page
leastbad Dec 28, 2022
89c8e3f
backup method needs to return early if file doesn't exist
leastbad Dec 28, 2022
903ee72
update Gemfile.lock
leastbad Dec 28, 2022
2a6bcaa
tweak example view; remove superfluous importmap include
leastbad Jan 3, 2023
e1b7696
tweaking standardrb warnings, making ActiveRecord and ActiveModel opt…
leastbad Jan 3, 2023
bba8335
stash jsdelivr url
leastbad Jan 4, 2023
bfe0f6f
add default queue option to CR initializer
leastbad Jan 4, 2023
180c37f
update JS test matrix
leastbad Jan 4, 2023
f86607d
standardrb
leastbad Jan 4, 2023
cc2d33c
Properly handle incomplete HTML5 fragments (#622)
cmer Jan 10, 2023
8266370
Merge branch 'master' into new_installer
marcoroth Feb 15, 2023
4aae1f1
update Gemfile.lock
marcoroth Feb 15, 2023
5f348c8
Update install and sync changes from CableReady installer
marcoroth Feb 15, 2023
48c26cb
Merge branch 'master' into new_installer
marcoroth Feb 15, 2023
5589fbf
bring importmap config back
marcoroth Feb 15, 2023
a1aa06a
Consitently use ⏩ and ✅ throughout the install process
marcoroth Feb 15, 2023
78390a4
Update stimulus_reflex generated example
marcoroth Feb 15, 2023
e53f004
standardize
marcoroth Feb 15, 2023
da775f5
add content for channels index for importmaps
marcoroth Feb 15, 2023
b532ef8
remove example controller
marcoroth Feb 15, 2023
e30e432
cleanup stimulus_reflex generator
marcoroth Feb 15, 2023
ae55938
more skipping messages
marcoroth Feb 15, 2023
874911c
sync more changes from the CableReady installer
marcoroth Feb 16, 2023
f845b1b
Update example
marcoroth Feb 18, 2023
97bcc8f
Merge branch 'main' into new_installer
marcoroth Feb 18, 2023
642eae4
Merge branch 'main' into new_installer
marcoroth Feb 18, 2023
0b33b16
Update README.md
marcoroth Feb 18, 2023
2de22a4
Update actions badges in README.md
marcoroth Feb 18, 2023
7ada3f6
fix typo
marcoroth Feb 19, 2023
0bd62b8
run `rails dev:cache` in `development` installer
marcoroth Feb 19, 2023
efc748d
`WS` -> `websocket`
marcoroth Feb 19, 2023
beb514a
fix wrong installer import
marcoroth Feb 19, 2023
889b561
make bundlers more consistent between each other
marcoroth Feb 19, 2023
898a766
copy
marcoroth Feb 19, 2023
21f34c3
remove check for statemachines in broadcaster import
marcoroth Feb 19, 2023
f12dd55
Don't run broadcaster if all classes already include the broadcaster
marcoroth Feb 19, 2023
88990e0
use `inject_into_file` over File.write
marcoroth Feb 19, 2023
1d17e01
`verbose: false`
marcoroth Feb 19, 2023
4e7435f
use inject_into_class where appropiate
marcoroth Feb 19, 2023
e9cbb01
bring back example controller
marcoroth Feb 19, 2023
0392b2b
force exit in stimulus_reflex:install:step command if it doesn't exists
marcoroth Feb 19, 2023
a08fa4a
rftm -> guide
marcoroth Feb 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<p align="center">
<img src="https://github.com/stimulusreflex/stimulus_reflex/blob/7dae7694577c6237601afa0a9ab81120c2a1dfb7/assets/stimulus-reflex-logo-with-copy.png" width="360" />
<img src="https://github.com/stimulusreflex/stimulus_reflex/blob/main/assets/stimulus-reflex-logo-with-copy.png?raw=1" width="360" />
<h1 align="center">Welcome to StimulusReflex 👋</h1>
<p align="center">
<img src="https://img.shields.io/gem/v/stimulus_reflex.svg?color=red" />
<img src="https://img.shields.io/npm/v/stimulus_reflex.svg?color=blue" />
<a href="https://www.npmjs.com/package/stimulus_reflex">
<img alt="downloads" src="https://img.shields.io/npm/dm/stimulus_reflex.svg?color=blue" target="_blank" />
</a>
<a href="https://github.com/stimulusreflex/stimulus_reflex/blob/main/LICENSE">
<a href="https://github.com/stimulusreflex/stimulus_reflex/blob/main/LICENSE.txt">
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg" target="_blank" />
</a>
<a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/" target="_blank">
<img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-2190-brightgreen.svg?style=flat" />
</a>
<a href="https://docs.stimulusreflex.com/" target="_blank">
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
</a>
Expand All @@ -27,16 +24,13 @@
<img alt="JavaScript Code Style" src="https://img.shields.io/badge/JavaScript_Code_Style-prettier_standard-ff69b4.svg" />
</a>
<br />
<a href="https://www.codacy.com/manual/hopsoft/stimulus_reflex/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=hopsoft/stimulus_reflex&amp;utm_campaign=Badge_Grade" target="_blank">
<img alt="Code Quality" src="https://app.codacy.com/project/badge/Grade/d1d72a7060f5467b8696884351cf477f"/>
</a>
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/workflows/Prettier-Standard/badge.svg">
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/actions/workflows/prettier-standard.yml">
<img src="https://github.com/stimulusreflex/stimulus_reflex/workflows/Prettier-Standard/badge.svg" alt="Prettier-Standard" style="max-width:100%;">
</a>
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/workflows/StandardRB/badge.svg">
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/actions/workflows/standardrb.yml">
<img src="https://github.com/stimulusreflex/stimulus_reflex/workflows/StandardRB/badge.svg" alt="StandardRB" style="max-width:100%;">
</a>
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/workflows/Tests/badge.svg">
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/actions/workflows/tests.yml">
<img src="https://github.com/stimulusreflex/stimulus_reflex/workflows/Tests/badge.svg" alt="Tests">
</a>
</p>
Expand Down Expand Up @@ -72,7 +66,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
- [Build a Twitter Clone in 10 Minutes](https://youtu.be/F5hA79vKE_E) (video)
- [BeastMode](https://beastmode.leastbad.com/) - faceted search, with filtering, sorting and pagination
- [StimulusReflex Patterns](https://www.stimulusreflexpatterns.com/patterns/) - single-file SR apps hosted on Glitch
- [BoxDrop](https://dropbox-clone-rails.herokuapp.com/) - a Dropbox-inspired [concept demo](https://github.com/marcoroth/boxdrop/)
- [Boxdrop](https://www.boxdrop.io) - a Dropbox-inspired [concept demo](https://github.com/marcoroth/boxdrop/)

## 👩‍👩‍👧 Discord Community

Expand All @@ -84,7 +78,7 @@ Stop by #newcomers and introduce yourselves!

## 💙 Support

Your best bet is to ask for help on Discord before filing an issue on Github. We are happy to help, and we ask people who need help to come with all relevant code to look at. A git repo is preferred, but Gists are fine, too. If you need an MVCE template, try [this](https://github.com/leastbad/stimulus_reflex_harness).
Your best bet is to ask for help on Discord before filing an issue on GitHub. We are happy to help, and we ask people who need help to come with all relevant code to look at. A git repo is preferred, but Gists are fine, too. If you need a template for reproducing your issue, try [this](https://github.com/leastbad/stimulus_reflex_harness).

Please note that we are not actively providing support on Stack Overflow. If you post there, we likely won't see it.

Expand Down
14 changes: 0 additions & 14 deletions lib/generators/stimulus_reflex/initializer_generator.rb

This file was deleted.

79 changes: 72 additions & 7 deletions lib/generators/stimulus_reflex/stimulus_reflex_generator.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,92 @@
# frozen_string_literal: true

require "rails/generators"
require "stimulus_reflex/version"

class StimulusReflexGenerator < Rails::Generators::NamedBase
source_root File.expand_path("templates", __dir__)

argument :name, type: :string, required: true, banner: "NAME"
argument :actions, type: :array, default: [], banner: "action action"
class_options skip_stimulus: false, skip_app_reflex: false, skip_reflex: false, skip_app_controller: false
class_options skip_stimulus: false, skip_reflex: false

def execute
actions.map!(&:underscore)

copy_application_files if behavior == :invoke
cached_entrypoint = Rails.root.join("tmp/stimulus_reflex_installer/entrypoint")
if cached_entrypoint.exist?
entrypoint = File.read(cached_entrypoint)
else
entrypoint = [
Rails.root.join("app/javascript"),
Rails.root.join("app/frontend")
].find(&:exist?) || "app/javascript"
puts "Where do JavaScript files live in your app? Our best guess is: \e[1#{entrypoint}\e[22m 🤔"
puts "Press enter to accept this, or type a different path."
print "> "
input = Rails.env.test? ? "tmp/app/javascript" : $stdin.gets.chomp
entrypoint = input unless input.blank?
end

template "app/reflexes/%file_name%_reflex.rb" unless options[:skip_reflex]
template "app/javascript/controllers/%file_name%_controller.js" unless options[:skip_stimulus]
if !options[:skip_stimulus] && entrypoint.blank?
puts "❌ You must specify a valid JavaScript entrypoint."
exit
end

reflex_entrypoint = Rails.env.test? ? "tmp/app/reflexes" : "app/reflexes"
reflex_src = fetch("/app/reflexes/%file_name%_reflex.rb.tt")
reflex_path = Rails.root.join(reflex_entrypoint, "#{file_name}_reflex.rb")
stimulus_controller_src = fetch("/app/javascript/controllers/%file_name%_controller.js.tt")
stimulus_controller_path = Rails.root.join(entrypoint, "controllers/#{file_name}_controller.js")

template(reflex_src, reflex_path) unless options[:skip_reflex]
template(stimulus_controller_src, stimulus_controller_path) unless options[:skip_stimulus]

if file_name == "example"
controller_src = fetch("/app/controllers/examples_controller.rb.tt")
controller_path = Rails.root.join("app/controllers/examples_controller.rb")
template(controller_src, controller_path)

view_src = fetch("/app/views/examples/show.html.erb.tt")
view_path = Rails.root.join("app/views/examples/show.html.erb")
template(view_src, view_path)

example_path = Rails.root.join("app/views/examples")
FileUtils.remove_dir(example_path) if behavior == :revoke && example_path.exist? && Dir.empty?(example_path)

route "resource :example, constraints: -> { Rails.env.development? }"

importmap_path = Rails.root.join("config/importmap.rb")

if importmap_path.exist?
importmap = importmap_path.read

if behavior == :revoke
if importmap.include?("pin \"fireworks-js\"")
importmap_path.write importmap_path.readlines.reject { |line| line.include?("pin \"fireworks-js\"") }.join
say "✅ unpin fireworks-js"
else
say "⏩ fireworks-js not pinned. Skipping."
end
end

if behavior == :invoke
if importmap.include?("pin \"fireworks-js\"")
say "⏩ fireworks-js already pinnned. Skipping."
else
append_file(importmap_path, <<~RUBY, verbose: false)
pin "fireworks-js", to: "https://ga.jspm.io/npm:fireworks-js@2.10.0/dist/index.es.js"
RUBY
say "✅ pin fireworks-js"
end
end
end
end
end

private

def copy_application_files
template "app/reflexes/application_reflex.rb" unless options[:skip_app_reflex]
template "app/javascript/controllers/application_controller.js" unless options[:skip_app_controller]
def fetch(file)
source_paths.first + file
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ExamplesController < ApplicationController
layout false

def show
respond_to do |format|
format.html
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.

import { createConsumer } from '@rails/actioncable'

export default createConsumer()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Load all the channels within this directory and all subdirectories.
// Channel files must be named *_channel.js.

import './**/*_channel.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// app/channels/index.js
// Importmaps don't require anything here
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Load all the channels within this directory and all subdirectories.
// Channel files must be named *_channel.js.

const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const channels = import.meta.globEager('./**/*_channel.js')
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Load all the channels within this directory and all subdirectories.
// Channel files must be named *_channel.js.

const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import consumer from '../channels/consumer'
import CableReady from 'cable_ready'

CableReady.initialize({ consumer })
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './cable_ready'
import './stimulus_reflex'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import CableReady from "cable_ready"
import mrujs from "mrujs"
import { CableCar } from "mrujs/plugins"

mrujs.start({
plugins: [
new CableCar(CableReady)
]
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { application } from "../controllers/application"
import controller from "../controllers/application_controller"
import StimulusReflex from "stimulus_reflex"

StimulusReflex.initialize(application, { controller, isolate: true })
Loading