-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add bun support #12
Merged
Merged
Add bun support #12
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c02cda
Add bun support
megatux c084524
Use version constant to download & install js
megatux 5a87452
Rename method to follow convention
megatux 29f0e07
Use defined version constant to download & install the library
megatux 1fa9e6b
Add constant to make clear usage
megatux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ class InstallGenerator < ::Rails::Generators::Base | |
|
||
# Setup HTMX | ||
def setup | ||
if importmap? | ||
if bun_configured? | ||
setup_bun | ||
elsif importmap? | ||
setup_importmap | ||
elsif webpacker? | ||
setup_webpacker | ||
|
@@ -24,6 +26,10 @@ def setup | |
|
||
private | ||
|
||
def bun_configured? | ||
Pathname.new(destination_root).join('bun.config.js').exist? | ||
end | ||
|
||
def webpacker? | ||
!!defined?(Webpacker) | ||
end | ||
|
@@ -40,38 +46,34 @@ def manifest(javascript_dir) | |
Pathname.new(destination_root).join(javascript_dir, 'application.js') | ||
end | ||
|
||
def setup_importmap | ||
run 'bin/importmap pin htmx.org' | ||
|
||
manifest = manifest('app/javascript') | ||
|
||
def add_to_manifest(manifest, text) | ||
if manifest.exist? | ||
append_file manifest, "\n#{IMPORTMAP_SETUP}" | ||
append_file manifest, "\n#{text}" | ||
else | ||
create_file manifest, IMPORTMAP_SETUP | ||
create_file manifest, text | ||
end | ||
end | ||
|
||
def setup_sprockets | ||
manifest = manifest('app/assets/javascripts') | ||
def setup_bun | ||
run 'bun add htmx.org' | ||
megatux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if manifest.exist? | ||
append_file manifest, "\n#{SPROCKETS_SETUP}" | ||
else | ||
create_file manifest, SPROCKETS_SETUP | ||
end | ||
add_to_manifest(manifest('app/javascript'), IMPORTMAP_SETUP) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a new constant |
||
end | ||
|
||
def setup_importmap | ||
run 'bin/importmap pin htmx.org' | ||
|
||
add_to_manifest(manifest('app/javascript'), IMPORTMAP_SETUP) | ||
end | ||
|
||
def setup_sprockets | ||
add_to_manifest(manifest('app/assets/javascripts'), SPROCKETS_SETUP) | ||
end | ||
|
||
def setup_webpacker | ||
run 'yarn add htmx.org' | ||
|
||
manifest = manifest(webpack_source_path) | ||
|
||
if manifest.exist? | ||
append_file(manifest, "\n#{WEBPACKER_SETUP}") | ||
else | ||
create_file(manifest, WEBPACKER_SETUP) | ||
end | ||
add_to_manifest(manifest(webpack_source_path), WEBPACKER_SETUP) | ||
end | ||
|
||
def webpack_source_path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To follow up the method naming style, can we rename to
bun?