-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from NYDrewReynolds/feature/add-installation-…
…rake-task Create an install generator with helpful output
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Description: | ||
Creates or adds import of NPM package to your application + additional installation steps. | ||
|
||
Example: | ||
rails generate polaris_view_components:install |
35 changes: 35 additions & 0 deletions
35
lib/generators/polaris_view_components/install_generator.rb
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails/generators/active_record' | ||
|
||
module PolarisViewComponents | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
def add_npm_package | ||
say "Adding NPM package", :green | ||
run "yarn add polaris-view-components" | ||
end | ||
|
||
def add_to_stimulus_controller | ||
say "Adding import to to Stimulus controller", :green | ||
dir_path = "app/javascript/controllers" | ||
empty_directory('app/javascript') | ||
empty_directory(dir_path) | ||
|
||
file_path = "#{dir_path}/index.js" | ||
|
||
unless File.exist?(file_path) | ||
copy_file 'stimulus_index.js', file_path | ||
end | ||
|
||
append_to_file file_path do | ||
"import { registerPolarisControllers } from 'polaris-view-components'\nregisterPolarisControllers(application)" | ||
end | ||
end | ||
|
||
def show_readme | ||
readme 'README' | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
=============================================================================== | ||
|
||
Some manual setup is still required: | ||
|
||
1. Setup Polaris styles in your layouts <head> tag: | ||
|
||
<link rel="stylesheet" href="https://unpkg.com/@shopify/[email protected]/dist/styles.css" /> | ||
<%= stylesheet_link_tag 'polaris_view_components' %> | ||
|
||
2. Define Polaris style on your <body> tag: | ||
|
||
<body style="<%= polaris_body_styles %>"> | ||
|
||
=============================================================================== |
7 changes: 7 additions & 0 deletions
7
lib/generators/polaris_view_components/templates/stimulus_index.js
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Application } from 'stimulus' | ||
import { definitionsFromContext } from 'stimulus/webpack-helpers' | ||
|
||
const application = Application.start(document.documentElement) | ||
const context = require.context('.', true, /_controller\.js$/) | ||
application.load(definitionsFromContext(context)) | ||
|