rails-hyperstack 1.0.alpha1.1 → 1.0.alpha1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -2
- data/Rakefile +21 -11
- data/lib/generators/hyper/component_generator.rb +3 -16
- data/lib/generators/hyper/generator_base.rb +18 -0
- data/lib/generators/hyper/router_generator.rb +3 -19
- data/lib/generators/hyper/templates/component_template.rb +19 -8
- data/lib/generators/hyper/templates/hyper_component_template.rb +10 -0
- data/lib/generators/hyper/templates/router_template.rb +4 -4
- data/lib/generators/hyperstack/install_generator.rb +137 -137
- data/lib/generators/hyperstack/install_generator_base.rb +268 -3
- data/lib/generators/install/hyperstack_generator.rb +229 -0
- data/lib/generators/install/hyperstack_generator_base.rb +102 -0
- data/lib/hyperstack/server_side_auto_require.rb +39 -0
- data/lib/hyperstack/version.rb +1 -1
- data/lib/rails-hyperstack.rb +10 -3
- data/lib/tasks/hyperstack/install.rake +32 -0
- data/rails-hyperstack.gemspec +44 -18
- data/spec/gems.rb +10 -0
- data/spec/rails_hyperstack_spec.rb +22 -16
- data/spec/server_side_sample.rb +5 -0
- metadata +78 -73
- data/Gemfile.lock +0 -431
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5c953e4e7193e6a181228ee9f26d393c2ff02d74db4ddfd723114c24058270c
|
4
|
+
data.tar.gz: fb1af29e5892577461c9872b239dfedc52b3662ae340bae24206fe425ad77a86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da214eb2d241d180c3fe25310ed3892ccb32778078ca00e6ab132609155525fed4cc3608cd81c9fccd1e40792e25b86096313dd740ef3cdb5fe0d8670fed3440
|
7
|
+
data.tar.gz: 1031939b40797726856d4cf56dbe2296e73493c82b19886f189117bf9ff81e934f5a1d96484971c5988be2bd9ed7815b3e438b45b371ca6449e567f85a1c6d3a
|
data/.gitignore
CHANGED
@@ -11,6 +11,7 @@ capybara-*.html
|
|
11
11
|
**.orig
|
12
12
|
rerun.txt
|
13
13
|
pickle-email-*.html
|
14
|
+
TestApp/
|
14
15
|
|
15
16
|
# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
|
16
17
|
config/initializers/secret_token.rb
|
@@ -46,3 +47,12 @@ bower.json
|
|
46
47
|
|
47
48
|
# ignore Idea
|
48
49
|
.idea
|
50
|
+
|
51
|
+
# ignore Gemfile.locks https://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
|
52
|
+
/spec/test_app/Gemfile.lock
|
53
|
+
/Gemfile.lock
|
54
|
+
|
55
|
+
node_modules
|
56
|
+
package.json
|
57
|
+
spec/test_app
|
58
|
+
yarn.lock
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.2
|
data/Gemfile
CHANGED
@@ -4,8 +4,8 @@ gem 'hyper-state', path: '../hyper-state'
|
|
4
4
|
gem 'hyper-component', path: '../hyper-component'
|
5
5
|
gem 'hyper-operation', path: '../hyper-operation'
|
6
6
|
gem 'hyper-model', path: '../hyper-model'
|
7
|
-
gem 'hyper-store', path: '../hyper-store'
|
8
7
|
gem 'hyper-router', path: '../hyper-router'
|
9
8
|
gem 'hyper-spec', path: '../hyper-spec'
|
10
|
-
gem '
|
9
|
+
gem 'webpacker' # TODO: figure out why these two are necessary!
|
10
|
+
gem 'turbolinks'
|
11
11
|
gemspec
|
data/Rakefile
CHANGED
@@ -1,25 +1,35 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
|
+
require 'pry'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
7
|
namespace :spec do
|
7
8
|
task :prepare do
|
9
|
+
rails_version = `bundle info rails`.match(/\* rails \((.+)\)/)[1]
|
10
|
+
opal_version = `bundle info opal`.match(/\* opal \((.+)\)/)[1]
|
8
11
|
Dir.chdir('spec') do
|
9
12
|
sh('rm -rf test_app')
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
Bundler.with_unbundled_env do
|
14
|
+
sh("rails _#{rails_version}_ new test_app -T")
|
15
|
+
end
|
16
|
+
Bundler.with_unbundled_env do
|
17
|
+
Dir.chdir('test_app') do
|
18
|
+
sh('cat ../gems.rb >> Gemfile')
|
19
|
+
sh("echo 'gem \"opal\", \"#{opal_version}\"' >> Gemfile")
|
20
|
+
sh("bundle update")
|
21
|
+
sh('spring stop')
|
22
|
+
sh('bundle exec rails g hyperstack:install')
|
23
|
+
sh('bundle exec rails generate model Sample name:string description:text')
|
24
|
+
sh('mv app/models/sample.rb app/hyperstack/models/sample.rb')
|
25
|
+
sh("cat ../server_side_sample.rb >> app/models/sample.rb")
|
26
|
+
sh('bundle exec rake db:migrate')
|
27
|
+
sh('RAILS_ENV=test bundle exec rake db:setup')
|
28
|
+
# sh('bundle exec rails dev:cache') # not tested yet...
|
29
|
+
end
|
18
30
|
end
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
22
34
|
|
23
|
-
task :default
|
24
|
-
|
25
|
-
end
|
35
|
+
task :default => :spec
|
@@ -1,20 +1,7 @@
|
|
1
|
-
require 'rails/generators'
|
2
1
|
module Hyper
|
3
|
-
class Component <
|
4
|
-
|
5
|
-
|
6
|
-
argument :components, type: :array
|
7
|
-
def create_component_file
|
8
|
-
self.components.each do |component|
|
9
|
-
component_array = component.split('::')
|
10
|
-
@modules = component_array[0..-2]
|
11
|
-
@file_name = component_array.last
|
12
|
-
@indent = 0
|
13
|
-
template 'component_template.rb',
|
14
|
-
File.join('app/hyperstack/components',
|
15
|
-
@modules.map(&:downcase).join('/'),
|
16
|
-
"#{@file_name.underscore}.rb")
|
17
|
-
end
|
2
|
+
class Component < GeneratorBase
|
3
|
+
def add_component
|
4
|
+
create_component_file 'component_template.rb'
|
18
5
|
end
|
19
6
|
end
|
20
7
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module Hyper
|
3
|
+
class GeneratorBase < Rails::Generators::Base
|
4
|
+
class << self
|
5
|
+
alias rails_inherited inherited
|
6
|
+
def inherited(child)
|
7
|
+
rails_inherited(child)
|
8
|
+
child.class_eval do
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
argument :components, type: :array
|
11
|
+
class_option 'base-class', :default => nil # will pull in value from config setting
|
12
|
+
class_option 'add-route', :default => nil
|
13
|
+
class_option 'no-help', :default => nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,23 +1,7 @@
|
|
1
|
-
require 'rails/generators'
|
2
1
|
module Hyper
|
3
|
-
class Router <
|
4
|
-
|
5
|
-
|
6
|
-
argument :component, type: :string
|
7
|
-
class_option :path, type: :string, default: '/(*other)'
|
8
|
-
def create_component_file
|
9
|
-
component_array = component.split('::')
|
10
|
-
@modules = component_array[0..-2]
|
11
|
-
@file_name = component_array.last
|
12
|
-
@indent = 0
|
13
|
-
template 'router_template.rb',
|
14
|
-
File.join('app/hyperstack/components',
|
15
|
-
@modules.map(&:downcase).join('/'),
|
16
|
-
"#{@file_name.underscore}.rb")
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_route
|
20
|
-
route "get '#{options['path']}', to: 'hyperstack##{@file_name.underscore}'"
|
2
|
+
class Router < GeneratorBase
|
3
|
+
def add_router_component
|
4
|
+
create_component_file 'router_template.rb'
|
21
5
|
end
|
22
6
|
end
|
23
7
|
end
|
@@ -1,15 +1,24 @@
|
|
1
1
|
<%- @modules.each do |module_name| %><%= " "* @indent %>module <%= module_name.camelize %><%- @indent += 1 %>
|
2
|
-
<%- end %><%=" "* @indent %>class <%= @file_name %> <
|
3
|
-
|
2
|
+
<%- end %><%=" "* @indent %>class <%= @file_name %> < <%= @component_base_class %>
|
3
|
+
<%- unless @no_help %>
|
4
4
|
<%=" "* @indent %> # param :my_param
|
5
5
|
<%=" "* @indent %> # param param_with_default: "default value"
|
6
6
|
<%=" "* @indent %> # param :param_with_default2, default: "default value" # alternative syntax
|
7
7
|
<%=" "* @indent %> # param :param_with_type, type: Hash
|
8
8
|
<%=" "* @indent %> # param :array_of_hashes, type: [Hash]
|
9
|
-
<%=" "* @indent %> #
|
9
|
+
<%=" "* @indent %> # other :attributes # collects all other params into a hash
|
10
|
+
<%=" "* @indent %> # fires :callback # creates a callback param
|
11
|
+
|
12
|
+
<%=" "* @indent %> # access params using the param name
|
13
|
+
<%=" "* @indent %> # fire a callback using the callback name followed by a !
|
14
|
+
|
15
|
+
<%=" "* @indent %> # state is kept and read as normal instance variables
|
16
|
+
<%=" "* @indent %> # but when changing state prefix the statement with `mutate`
|
17
|
+
<%=" "* @indent %> # i.e. mutate @my_state = 12
|
18
|
+
<%=" "* @indent %> # mutate @my_other_state[:bar] = 17
|
10
19
|
|
11
|
-
<%=" "* @indent %> #
|
12
|
-
<%=" "* @indent %> #
|
20
|
+
<%=" "* @indent %> # the following are the most common lifecycle call backs,
|
21
|
+
<%=" "* @indent %> # delete any that you are not using.
|
13
22
|
<%=" "* @indent %> # call backs may also reference an instance method i.e. before_mount :my_method
|
14
23
|
|
15
24
|
<%=" "* @indent %> before_mount do
|
@@ -27,12 +36,14 @@
|
|
27
36
|
<%=" "* @indent %> end
|
28
37
|
|
29
38
|
<%=" "* @indent %> before_unmount do
|
30
|
-
<%=" "* @indent %> # cleanup any thing
|
39
|
+
<%=" "* @indent %> # cleanup any thing before component is destroyed
|
40
|
+
<%=" "* @indent %> # note timers and broadcast receivers are cleaned up
|
41
|
+
<%=" "* @indent %> # automatically
|
31
42
|
<%=" "* @indent %> end
|
32
43
|
|
33
|
-
|
44
|
+
<%- end %><%=" "* @indent %> render do
|
34
45
|
<%=" "* @indent %> DIV do
|
35
|
-
<%=" "* @indent %>
|
46
|
+
<%=" "* @indent %> '<%= (@modules+[@file_name]).join('::') %>'
|
36
47
|
<%=" "* @indent %> end
|
37
48
|
<%=" "* @indent %> end
|
38
49
|
<%=" "* @indent %>end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# app/hyperstack/hyper_component.rb
|
2
|
+
class <%= @component_base_class %>
|
3
|
+
# All component classes must include Hyperstack::Component
|
4
|
+
include Hyperstack::Component
|
5
|
+
# The Observable module adds state handling
|
6
|
+
include Hyperstack::State::Observable
|
7
|
+
# The following turns on the new style param accessor
|
8
|
+
# i.e. param :foo is accessed by the foo method
|
9
|
+
param_accessor_style :accessors
|
10
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
<%- @modules.each do |module_name| %><%= " "* @indent %>module <%= module_name.camelize %><%- @indent += 1 %>
|
2
|
-
<%- end %><%=" "* @indent %>class <%= @file_name %> <
|
3
|
-
<%=" "* @indent %> include Hyperstack::
|
2
|
+
<%- end %><%=" "* @indent %>class <%= @file_name %> < <%= @component_base_class %>
|
3
|
+
<%=" "* @indent %> include Hyperstack::Router
|
4
4
|
<%=" "* @indent %> render do
|
5
5
|
<%=" "* @indent %> DIV do
|
6
6
|
<%=" "* @indent %> '<%= (@modules+[@file_name]).join('::') %>'
|
7
|
-
|
7
|
+
<%- unless @no_help %><%=" "* @indent %> # define routes using the Route psuedo component. Examples:
|
8
8
|
<%=" "* @indent %> # Route('/foo', mounts: Foo) : match the path beginning with /foo and mount component Foo here
|
9
9
|
<%=" "* @indent %> # Route('/foo') { Foo(...) } : display the contents of the block
|
10
10
|
<%=" "* @indent %> # Route('/', exact: true, mounts: Home) : match the exact path / and mount the Home component
|
11
11
|
<%=" "* @indent %> # Route('/user/:id/name', mounts: UserName) : path segments beginning with a colon will be captured in the match param
|
12
12
|
<%=" "* @indent %> # see the hyper-router gem documentation for more details
|
13
|
-
|
13
|
+
<%- end %><%=" "* @indent %> end
|
14
14
|
<%=" "* @indent %> end
|
15
15
|
<%=" "* @indent %>end
|
16
16
|
<%- @modules.each do %><%- @indent -= 1 %><%=" "* @indent %>end
|
@@ -2,178 +2,178 @@ require_relative 'install_generator_base'
|
|
2
2
|
module Hyperstack
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
|
5
|
+
class_option 'skip-hotloader', type: :boolean
|
5
6
|
class_option 'skip-webpack', type: :boolean
|
6
|
-
class_option 'skip-
|
7
|
-
class_option '
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
class_option 'skip-hyper-model', type: :boolean
|
8
|
+
class_option 'hotloader-only', type: :boolean
|
9
|
+
class_option 'webpack-only', type: :boolean
|
10
|
+
class_option 'hyper-model-only', type: :boolean
|
11
|
+
|
12
|
+
def add_hotloader
|
13
|
+
return if skip_hotloader?
|
14
|
+
unless Hyperstack.imported? 'hyperstack/hotloader'
|
15
|
+
inject_into_initializer(
|
16
|
+
"Hyperstack.import 'hyperstack/hotloader', "\
|
17
|
+
'client_only: true if Rails.env.development?'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
create_file 'Procfile', <<-TEXT
|
21
|
+
web: bundle exec rails s -b 0.0.0.0
|
22
|
+
hot-loader: bundle exec hyperstack-hotloader -p 25222 -d app/hyperstack
|
23
|
+
TEXT
|
24
|
+
gem_group :development do
|
25
|
+
gem 'foreman'
|
16
26
|
end
|
17
27
|
end
|
18
28
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
def install_webpack
|
30
|
+
return super unless skip_webpack?
|
31
|
+
|
32
|
+
inject_into_initializer(
|
33
|
+
"Hyperstack.import 'react/react-source-browser' "\
|
34
|
+
"# bring in hyperstack's copy of react, comment this out "\
|
35
|
+
"if you bring it in from webpacker\n"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_component
|
40
|
+
# add_component AFTER webpack so component generator webpack check works
|
41
|
+
if skip_adding_component?
|
42
|
+
# normally this is handled by the hyper:component
|
43
|
+
# generator, but if we are skipping it we will check it
|
44
|
+
# now.
|
45
|
+
insure_hyperstack_loader_installed
|
46
|
+
check_javascript_link_directory
|
47
|
+
else
|
48
|
+
generate 'hyper:router App --add-route'
|
24
49
|
end
|
25
50
|
end
|
26
51
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
52
|
+
def create_policies_directory
|
53
|
+
return if skip_hyper_model?
|
54
|
+
policy_file = Rails.root.join('app', 'policies', 'hyperstack', 'application_policy.rb')
|
55
|
+
unless File.exist? policy_file
|
56
|
+
create_file policy_file, <<-RUBY
|
57
|
+
# #{policy_file}
|
58
|
+
|
59
|
+
# Policies regulate access to your public models
|
60
|
+
# The following policy will open up full access (but only in development)
|
61
|
+
# The policy system is very flexible and powerful. See the documentation
|
62
|
+
# for complete details.
|
63
|
+
module Hyperstack
|
64
|
+
class ApplicationPolicy
|
65
|
+
# Allow any session to connect:
|
66
|
+
always_allow_connection
|
67
|
+
# Send all attributes from all public models
|
68
|
+
regulate_all_broadcasts { |policy| policy.send_all }
|
69
|
+
# Allow all changes to models
|
70
|
+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
|
71
|
+
end unless Rails.env.production?
|
32
72
|
end
|
33
73
|
RUBY
|
34
|
-
|
35
|
-
create_file 'app/hyperstack/stores/.keep', ''
|
36
|
-
create_file 'app/hyperstack/models/.keep', ''
|
74
|
+
end
|
37
75
|
end
|
38
76
|
|
39
77
|
def move_and_update_application_record
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
78
|
+
return if skip_hyper_model?
|
79
|
+
rails_app_record_file = Rails.root.join('app', 'models', 'application_record.rb')
|
80
|
+
hyper_app_record_file = Rails.root.join('app', 'hyperstack', 'models', 'application_record.rb')
|
81
|
+
unless File.exist? hyper_app_record_file
|
82
|
+
empty_directory Rails.root.join('app', 'hyperstack', 'models')
|
83
|
+
`mv #{rails_app_record_file} #{hyper_app_record_file}`
|
84
|
+
inject_into_file hyper_app_record_file, before: /^end/, verbose: false do
|
85
|
+
" # allow remote access to all scopes - i.e. you can count or get a list of ids\n"\
|
86
|
+
" # for any scope or relationship\n"\
|
87
|
+
" ApplicationRecord.regulate_scope :all unless Hyperstack.env.production?\n"
|
88
|
+
end
|
89
|
+
|
90
|
+
# create_file rails_app_record_file, <<-RUBY
|
91
|
+
# # #{rails_app_record_file}
|
92
|
+
# # the presence of this file prevents rails migrations from recreating application_record.rb
|
93
|
+
# # see https://github.com/rails/rails/issues/29407
|
94
|
+
#
|
95
|
+
# require 'models/application_record.rb'
|
96
|
+
# RUBY
|
48
97
|
end
|
49
98
|
end
|
50
99
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
always_allow_connection
|
62
|
-
# Send all attributes from all public models
|
63
|
-
regulate_all_broadcasts { |policy| policy.send_all }
|
64
|
-
# Allow all changes to public models
|
65
|
-
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
|
66
|
-
# allow remote access to all scopes - i.e. you can count or get a list of ids
|
67
|
-
# for any scope or relationship
|
68
|
-
ApplicationRecord.regulate_scope :all
|
69
|
-
end unless Rails.env.production?
|
100
|
+
def turn_on_transport
|
101
|
+
inject_into_initializer <<-RUBY
|
102
|
+
|
103
|
+
# transport controls how push (websocket) communications are
|
104
|
+
# implemented. The default is :none.
|
105
|
+
# Other possibilities are :action_cable, :pusher (see www.pusher.com)
|
106
|
+
# or :simple_poller which is sometimes handy during system debug.
|
107
|
+
|
108
|
+
Hyperstack.transport = :action_cable # :pusher, :simple_poller or :none
|
109
|
+
|
70
110
|
RUBY
|
71
111
|
end
|
72
112
|
|
73
|
-
def
|
74
|
-
|
113
|
+
def add_engine_route
|
114
|
+
return if skip_hyper_model?
|
115
|
+
route 'mount Hyperstack::Engine => \'/hyperstack\' # this route should be first in the routes file so it always matches'
|
75
116
|
end
|
76
117
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
append_file 'config/initializers/assets.rb' do
|
99
|
-
<<-RUBY
|
100
|
-
Rails.application.config.assets.paths << Rails.root.join('public', 'packs').to_s
|
101
|
-
RUBY
|
118
|
+
def report
|
119
|
+
say "\n\n"
|
120
|
+
unless skip_adding_component?
|
121
|
+
say '🎢 Top Level App Component successfully installed at app/hyperstack/components/app.rb 🎢', :green
|
122
|
+
end
|
123
|
+
if !new_rails_app?
|
124
|
+
say '🎢 Top Level App Component skipped, you can manually generate it later 🎢', :green
|
125
|
+
end
|
126
|
+
unless skip_webpack?
|
127
|
+
say '📦 Webpack integrated with Hyperstack. '\
|
128
|
+
'Add javascript assets to app/javascript/packs/client_only.js and /client_and_server.js 📦', :green
|
129
|
+
end
|
130
|
+
unless skip_hyper_model?
|
131
|
+
say '👩✈️ Basic development policy defined. See app/policies/application_policy.rb 👨🏽✈️', :green
|
132
|
+
say '💽 HyperModel installed. Move any Active Record models to the app/hyperstack/models to access them from the client 📀', :green
|
133
|
+
end
|
134
|
+
if File.exist?(init = Rails.root.join('config', 'initializers', 'hyperstack.rb'))
|
135
|
+
say "☑️ Check #{init} for other configuration options. ☑️", :green
|
136
|
+
end
|
137
|
+
unless skip_hotloader?
|
138
|
+
say '🚒 Hyperstack Hotloader installed - use bundle exec foreman start and visit localhost:5000 🚒', :green
|
102
139
|
end
|
103
|
-
end
|
104
140
|
|
105
|
-
|
106
|
-
return if skip_webpack?
|
107
|
-
yarn 'react', '16'
|
108
|
-
yarn 'react-dom', '16'
|
109
|
-
yarn 'react-router', '4.2'
|
110
|
-
yarn 'react-router-dom', '4.2'
|
111
|
-
yarn 'history', '4.2'
|
112
|
-
yarn 'react_ujs'
|
113
|
-
yarn 'jquery'
|
114
|
-
end
|
141
|
+
say "\n\n"
|
115
142
|
|
116
|
-
|
117
|
-
framework = options['add-framework']
|
118
|
-
return unless framework
|
119
|
-
generate "hyperstack:install_#{framework}", "--no-build"
|
143
|
+
warnings.each { |warning| say "#{warning}", :yellow }
|
120
144
|
end
|
121
145
|
|
122
|
-
|
123
|
-
system('bin/webpack')
|
124
|
-
end
|
146
|
+
private
|
125
147
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
def create_initializer
|
130
|
-
create_file 'config/initializers/hyperstack.rb', <<-RUBY
|
131
|
-
# config/initializers/hyperstack.rb
|
132
|
-
# If you are not using ActionCable, see http://hyperstack.orgs/docs/models/configuring-transport/
|
133
|
-
Hyperstack.configuration do |config|
|
134
|
-
config.transport = :action_cable # or :pusher or :simpler_poller or :none
|
135
|
-
config.prerendering = :off # or :on
|
136
|
-
#{" config.import 'jquery', client_only: true # remove this line if you don't need jquery" if skip_webpack?}
|
137
|
-
config.import 'hyperstack/component/jquery', client_only: true # remove this line if you don't need jquery
|
138
|
-
#{" config.import 'hyperstack/hotloader', client_only: true if Rails.env.development?" unless options['skip-hot-reloader']}
|
139
|
-
end
|
140
|
-
RUBY
|
148
|
+
def skip_adding_component?
|
149
|
+
options['hotloader-only'] || options['webpack-only'] || options['hyper-model-only'] || !new_rails_app?
|
141
150
|
end
|
142
151
|
|
143
|
-
def
|
144
|
-
|
145
|
-
route 'mount Hyperstack::Engine => \'/hyperstack\'' # this route should be first in the routes file so it always matches
|
152
|
+
def skip_hotloader?
|
153
|
+
options['skip-hotloader'] || options['webpack-only'] || options['hyper-model-only']
|
146
154
|
end
|
147
155
|
|
148
|
-
def
|
149
|
-
|
150
|
-
create_file 'Procfile', <<-TEXT
|
151
|
-
web: bundle exec rails s -b 0.0.0.0
|
152
|
-
hot-loader: bundle exec hyperstack-hotloader -d app/hyperstack
|
153
|
-
TEXT
|
154
|
-
gem_group :development do
|
155
|
-
gem 'foreman'
|
156
|
-
end
|
156
|
+
def skip_webpack?
|
157
|
+
options['hotloader-only'] || options['skip-webpack'] || options['hyper-model-only']
|
157
158
|
end
|
158
159
|
|
159
|
-
def
|
160
|
-
|
161
|
-
# gem 'hyper-router', Hyperstack::ROUTERVERSION
|
162
|
-
# gem 'opal-rails', '~> 0.9.4'
|
163
|
-
# gem 'opal-jquery'
|
164
|
-
# gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
|
160
|
+
def skip_hyper_model?
|
161
|
+
options['hotloader-only'] || options['webpack-only'] || options['skip-hyper-model']
|
165
162
|
end
|
166
163
|
|
167
|
-
def
|
168
|
-
|
169
|
-
|
164
|
+
def new_rails_app?
|
165
|
+
# check to see if there are any routes set up and remember it, cause we might add a route in the process
|
166
|
+
@new_rails_app ||= begin
|
167
|
+
route_file = Rails.root.join('config', 'routes.rb')
|
168
|
+
count = File.foreach(route_file).inject(0) do |c, line|
|
169
|
+
line = line.strip
|
170
|
+
next c if line.empty?
|
171
|
+
next c if line.start_with?('#')
|
172
|
+
next c if line.start_with?('mount')
|
173
|
+
c + 1
|
174
|
+
end
|
175
|
+
count <= 2
|
170
176
|
end
|
171
177
|
end
|
172
|
-
|
173
|
-
private
|
174
|
-
|
175
|
-
def skip_webpack?
|
176
|
-
options['skip-webpack'] || !defined?(Webpacker)
|
177
|
-
end
|
178
178
|
end
|
179
179
|
end
|