|
| 1 | +# Hyperstack 1.0 ALPHA Rails Template |
| 2 | + |
| 3 | +# ----------------------------------- Commit so we have good history of these changes |
| 4 | + |
| 5 | +git :init |
| 6 | +git add: "." |
| 7 | +git commit: "-m 'Initial commit: Rails base'" |
| 8 | + |
| 9 | +# ----------------------------------- Add the gems |
| 10 | + |
| 11 | +gem 'webpacker' |
| 12 | +gem 'opal-sprockets', '~> 0.4.2.0.11.0.3.1' # to ensure we have the latest |
| 13 | +gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master" |
| 14 | +gem 'hyperloop', git: 'https://github.com/ruby-hyperloop/hyperloop', branch: 'edge' |
| 15 | +gem 'hyper-react', git: 'https://github.com/ruby-hyperloop/hyper-react', branch: 'edge' |
| 16 | +gem 'hyper-component', git: 'https://github.com/ruby-hyperloop/hyper-component', branch: 'edge' |
| 17 | +gem 'hyper-router', git: 'https://github.com/ruby-hyperloop/hyper-router', branch: 'edge' |
| 18 | +gem 'hyper-store', git: 'https://github.com/ruby-hyperloop/hyper-store', branch: 'edge' |
| 19 | +gem 'hyperloop-config', git: 'https://github.com/ruby-hyperloop/hyperloop-config', branch: 'edge' |
| 20 | +gem 'opal_hot_reloader', git: 'https://github.com/fkchang/opal-hot-reloader.git' |
| 21 | + |
| 22 | +gem_group :development do |
| 23 | + gem 'foreman' |
| 24 | +end |
| 25 | + |
| 26 | +# ----------------------------------- Create the folders |
| 27 | + |
| 28 | +run 'mkdir app/hyperloop' |
| 29 | +run 'mkdir app/hyperloop/components' |
| 30 | +run 'mkdir app/hyperloop/stores' |
| 31 | +run 'mkdir app/hyperloop/models' |
| 32 | +run 'mkdir app/hyperloop/operations' |
| 33 | + |
| 34 | +# ----------------------------------- Add .keep files |
| 35 | + |
| 36 | +run 'touch app/hyperloop/components/.keep' |
| 37 | +run 'touch app/hyperloop/stores/.keep' |
| 38 | +run 'touch app/hyperloop/models/.keep' |
| 39 | +run 'touch app/hyperloop/operations/.keep' |
| 40 | + |
| 41 | +# ----------------------------------- Create the Hyperloop config |
| 42 | + |
| 43 | +file 'config/initializers/hyperloop.rb', <<-CODE |
| 44 | +Hyperloop.configuration do |config| |
| 45 | + # config.transport = :action_cable |
| 46 | + config.import 'reactrb/auto-import' |
| 47 | + config.import 'opal_hot_reloader' |
| 48 | + config.cancel_import 'react/react-source-browser' # bring your own React and ReactRouter via Yarn/Webpacker |
| 49 | +end |
| 50 | +CODE |
| 51 | + |
| 52 | +# ----------------------------------- Add NPM modules |
| 53 | + |
| 54 | +run 'yarn add react' |
| 55 | +run 'yarn add react-dom' |
| 56 | +run 'yarn add react-router' |
| 57 | + |
| 58 | +# ----------------------------------- Create thyperstack.js |
| 59 | + |
| 60 | +file 'app/javascript/packs/hyperstack.js', <<-CODE |
| 61 | +// Import all the modules |
| 62 | +import React from 'react'; |
| 63 | +import ReactDOM from 'react-dom'; |
| 64 | +
|
| 65 | +// for opal/hyperloop modules to find React and others they must explicitly be saved |
| 66 | +// to the global space, otherwise webpack will encapsulate them locally here |
| 67 | +global.React = React; |
| 68 | +global.ReactDOM = ReactDOM; |
| 69 | +CODE |
| 70 | + |
| 71 | +# ----------------------------------- View template |
| 72 | + |
| 73 | +inject_into_file 'app/views/layouts/application.html.erb', before: %r{<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>} do |
| 74 | +<<-CODE |
| 75 | +<%= javascript_pack_tag 'hyperstack' %> |
| 76 | +CODE |
| 77 | +end |
| 78 | + |
| 79 | +# ----------------------------------- application.js |
| 80 | + |
| 81 | +inject_into_file 'app/assets/javascripts/application.js', before: %r{//= require_tree .} do |
| 82 | +<<-CODE |
| 83 | +//= require jquery |
| 84 | +//= require jquery_ujs |
| 85 | +//= require hyperloop-loader |
| 86 | +CODE |
| 87 | +end |
| 88 | + |
| 89 | +# ----------------------------------- Procfile |
| 90 | + |
| 91 | +file 'Procfile', <<-CODE |
| 92 | +web: bundle exec puma |
| 93 | +hot: opal-hot-reloader -p 25222 -d app/hyperloop/ |
| 94 | +CODE |
| 95 | + |
| 96 | +# ----------------------------------- OpalHotReloader client |
| 97 | + |
| 98 | +file 'app/hyperloop/components/hot_loader.rb', <<-CODE |
| 99 | +require 'opal_hot_reloader' |
| 100 | +OpalHotReloader.listen(25222, false) |
| 101 | +CODE |
| 102 | + |
| 103 | +# ----------------------------------- Hello World |
| 104 | + |
| 105 | +route "root 'hyperloop#HelloWorld'" |
| 106 | + |
| 107 | +file 'app/hyperloop/components/hello_world.rb', <<-CODE |
| 108 | +class HelloWorld < Hyperloop::Component |
| 109 | + render do |
| 110 | + H1 { "Hello world from Hyperstack!" } |
| 111 | + end |
| 112 | +end |
| 113 | +CODE |
| 114 | + |
| 115 | +# ----------------------------------- Commit Hyperloop setup |
| 116 | + |
| 117 | +after_bundle do |
| 118 | + run 'bundle exec rails webpacker:install' |
| 119 | + git add: "." |
| 120 | + git commit: "-m 'Hyperstack config complete'" |
| 121 | +end |
0 commit comments