react-rails-api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a8e040cc4f348c9b64edcdc489d99f33ec3a6a86ada5d03fda56dd1f166d17b7
4
+ data.tar.gz: 339ea45fa23108317cf96be0d3158cd5cbf6882bfbe560c5bf82ce326c7b9f0b
5
+ SHA512:
6
+ metadata.gz: ba8f977ef5d5abe841a7bdc9740f14aea92647cc94e9be1cf265e0e455ab14b52df2afd7184700549f1d37f96bf88dc8e7fca0d7a82b4ca0adaacd355de297b4
7
+ data.tar.gz: b22775270e2e52638178ed3b6d62beca19ecb0dc33f212ce93b4906e80c1f2f9212302267f80347b3af0061c5e8400c189a221c85dfda6dc04ea3ce26f44a5ff
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Edwin Onuonga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,44 @@
1
+ [![Ruby Version](https://img.shields.io/badge/ruby-~%3E%202.5-red.svg)]()
2
+ [![Gem](https://img.shields.io/gem/v/react-rails-api.svg)](https://rubygems.org/gems/react-rails-api)
3
+ [![License](https://img.shields.io/github/license/eonu/react-rails-api.svg)](https://github.com/eonu/react-rails-api/blob/master/LICENSE)
4
+
5
+ # React-Rails API
6
+
7
+ All-in-one application generator enabling the integration of a React front-end and a Ruby-on-Rails API back-end with a CMS via ActiveAdmin.
8
+
9
+ ---
10
+
11
+ <p align="center">
12
+ <img width="600px" src="https://i.ibb.co/9y3jyBK/react-rails-api.png">
13
+ <p align="center"><em>Image courtesy of <a href="https://heroku.com">Heroku</a>.</em></p>
14
+ </p>
15
+
16
+ This is an easy-to-use generator to implement the modern web application stack described [here](https://blog.heroku.com/a-rock-solid-modern-web-stack), by Heroku designer Charlie Gleason.
17
+
18
+ ## Requirements
19
+
20
+ - [**Ruby**](https://www.ruby-lang.org/en/) `~> 2.5`
21
+ - [**Rails**](https://rubyonrails.org/) `~> 5.2`
22
+ - [**Node**](https://nodejs.org/en/) `11.11.0`: *Recommend installing this with [NVM](https://github.com/creationix/nvm).*
23
+ - [**Yarn**](https://yarnpkg.com/en/) `1.13.0`: *Recommend installing Node separately from this, rather than as a dependency.*
24
+
25
+ ## Installation
26
+
27
+ ```
28
+ $ gem install react-rails-api
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```bash
34
+ $ react-rails
35
+
36
+ Commands:
37
+ react-rails new [PATH] # Initialise a React/Rails API application.
38
+
39
+ Options:
40
+ [--database], [--no-database] # Integrate ActiveRecord (and Postgres).
41
+ # Default: true
42
+ ```
43
+
44
+ If the `--database` flag is set to true (which is the default), a prompt will also ask if you'd like to integrate [ActiveAdmin](https://activeadmin.info/) into the application.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'react-rails-api'
3
+ ReactRailsAPI::CLI.start
@@ -0,0 +1,2 @@
1
+ require "react-rails-api/version"
2
+ require 'react-rails-api/cli'
@@ -0,0 +1,59 @@
1
+ require 'thor'
2
+ require_relative 'version'
3
+
4
+ class ReactRailsAPI::CLI < Thor
5
+ TEMPLATE = File.join __dir__, 'template.rb'
6
+
7
+ class_option :database, type: :boolean, :desc => "Integrate ActiveRecord (and Postgres).", default: true
8
+
9
+ desc 'new [PATH]', "\e[90mInitialise a React/Rails API application.\e[0m"
10
+ def new(path)
11
+ opts = default_options
12
+ opts << '--database=postgresql' if options[:database]
13
+ opts << '--skip-active-record' if !options[:database]
14
+ opts << "--template=#{TEMPLATE}"
15
+ exec "rails new #{path} #{opts.join ' '}"
16
+ end
17
+
18
+ map %w[--version -v] => :version
19
+ desc 'version, -v', "\e[90mDisplay installed react-rails version.\e[0m"
20
+ def version
21
+ puts ReactRailsAPI::VERSION
22
+ end
23
+
24
+ def self.help(shell, subcommand = false)
25
+ list = printable_commands(true, subcommand)
26
+ Thor::Util.thor_classes_in(self).each do |klass|
27
+ list += klass.printable_commands(false)
28
+ end
29
+ list.sort! { |a, b| a[0] <=> b[0] }
30
+ list.reject! { |e| /.*help.*/.match? e.first }
31
+ list.map! {|c| c.map {|s| s.gsub('decrypt', ?d).gsub('encrypt', ?e)} }
32
+
33
+ if defined?(@package_name) && @package_name
34
+ shell.say "#{@package_name} commands:"
35
+ else
36
+ shell.say "Commands:"
37
+ end
38
+
39
+ shell.print_table(list, :indent => 2, :truncate => true)
40
+ shell.say
41
+ class_options_help(shell)
42
+ end
43
+
44
+ no_tasks do
45
+ def default_options
46
+ %w[
47
+ --webpack=react
48
+ --api
49
+ --skip-coffee
50
+ --skip-action-cable
51
+ --skip-action-mailer
52
+ --skip-turbolinks
53
+ --skip-test
54
+ --skip-bootsnap
55
+ --no-bundle
56
+ ]
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,115 @@
1
+ # Loads a template from ./templates
2
+ def template(name)
3
+ File.open(File.join __dir__, 'templates', name).read
4
+ end
5
+
6
+ database = !ARGV.include?('--skip-active-record')
7
+ active_admin = database ? yes?("\nUse ActiveAdmin? (Y/n):") : false
8
+ puts if database
9
+
10
+ gem_group :development, :test do
11
+ gem 'rspec-rails'
12
+ gem 'sqlite3', '~> 1.3.6'
13
+ end
14
+
15
+ gem_group :production do
16
+ gem 'pg', '>= 0.18', '< 2.0'
17
+ gsub_file 'Gemfile', "# Use postgresql as the database for Active Record\ngem 'pg', '>= 0.18', '< 2.0'\n", ''
18
+ end
19
+
20
+ if active_admin
21
+ # Add Devise and ActiveAdmin gems to Gemfile
22
+ gem 'devise'
23
+ gem 'activeadmin'
24
+ inject_into_file 'Gemfile', "# ActiveAdmin\n", before: "gem 'devise'"
25
+ end
26
+
27
+ after_bundle do
28
+ # Stop spring from running
29
+ run 'spring stop'
30
+
31
+ # Integrate RSpec into the application
32
+ generate 'rspec:install'
33
+
34
+ # Add db/*.sqlite and db/*.sqlite-journal files to .gitignore
35
+ append_to_file '.gitignore', "\n# Ignore the default SQLite database.\n/db/*.sqlite\n/db/*.sqlite-journal\n"
36
+
37
+ inside File.join('app', 'controllers') do
38
+ # Make ApplicationController inherit from ActionController::Base
39
+ gsub_file 'application_controller.rb', 'ActionController::API', 'ActionController::Base'
40
+
41
+ # Add protect_from_forgery and inheritance comment
42
+ inject_into_file 'application_controller.rb', template('application_controller.rb.tt'), before: /^end/
43
+
44
+ # Generate the API base controller (ApiController)
45
+ generate :controller, 'API', *%w[
46
+ --skip-routes
47
+ --no-helper
48
+ --no-assets
49
+ --no-controller-specs
50
+ --no-view-specs
51
+ --no-helper-specs
52
+ --no-javascripts
53
+ --no-stylesheets
54
+ ]
55
+
56
+ # Make ApiController inherit from ActionController::API
57
+ gsub_file 'api_controller.rb', 'ApplicationController', 'ActionController::API'
58
+ inject_into_file 'api_controller.rb', " # New controllers should inherit from this controller, not ApplicationController.\n", before: /^end/
59
+ end
60
+
61
+ inside 'config' do
62
+ # Include the railtie for sprockets
63
+ uncomment_lines 'application.rb', /require \"sprockets\/railtie\"/
64
+
65
+ # Add ActiveAdmin configuration on config/application.rb
66
+ inject_into_file 'application.rb', template('application.rb.tt'), before: /^ end/ if active_admin
67
+
68
+ # Write config/database.yml template
69
+ file 'database.yml', template('database.yml.tt'), force: true if database
70
+
71
+ # Add /api scope in config/routes.rb
72
+ inject_into_file 'routes.rb', template('routes.rb.tt'), before: /^end/
73
+ end
74
+
75
+ if database
76
+ if active_admin
77
+ # Integrate ActiveAdmin and Devise CMS into the application
78
+ generate 'active_admin:install'
79
+ generate 'devise:views'
80
+ end
81
+
82
+ # Run a database migration and seed the database
83
+ rails_command 'db:migrate'
84
+ rails_command 'db:seed'
85
+ end
86
+
87
+ # Create a development Procfile for running both processes
88
+ file 'Procfile.dev', template('Procfile.dev.tt')
89
+
90
+ # Create a production Procfile for running the application
91
+ file 'Procfile', template('Procfile.tt')
92
+ inject_into_file 'Procfile', 'release: bundle exec rake db:migrate', after: "\n" if database
93
+
94
+ # Create a rake task for starting the application in the development environment
95
+ inside File.join('lib', 'tasks') do
96
+ file 'start.rake', template('start.rake.tt')
97
+ end
98
+
99
+ # Create a top-level package.json that tells Heroku how to compile the Create React App
100
+ file 'package.json', template('package.json.tt')
101
+
102
+ # Create the React application (client)
103
+ run 'yarn create react-app client'
104
+
105
+ inside 'client' do
106
+ # Add a proxy for the Rails API server (on the client)
107
+ inject_into_file 'package.json', " \"proxy\": \"http://localhost:3001\",\n", after: "\"version\": \"0.1.0\",\n"
108
+ end
109
+
110
+ # Add environment variable for skipping preflight checks
111
+ file '.env', template('.env.tt')
112
+
113
+ # Prevent out-of-date yarn package errors
114
+ run 'yarn install --check-files'
115
+ end
@@ -0,0 +1 @@
1
+ SKIP_PREFLIGHT_CHECK=true
@@ -0,0 +1,2 @@
1
+ web: PORT=3000 yarn --cwd client start
2
+ api: PORT=3001 bundle exec rails s
@@ -0,0 +1 @@
1
+ web: bundle exec rails s
@@ -0,0 +1,9 @@
1
+
2
+ # Middleware for ActiveAdmin
3
+ config.middleware.use Rack::MethodOverride
4
+ config.middleware.use ActionDispatch::Flash
5
+ config.middleware.use ActionDispatch::Cookies
6
+ config.middleware.use ActionDispatch::Session::CookieStore
7
+
8
+ # Use regular scaffolding process
9
+ config.app_generators.scaffold_controller = :scaffold_controller
@@ -0,0 +1,2 @@
1
+ # New controllers should inherit from ApiController, not this controller.
2
+ protect_from_forgery with: :exception
@@ -0,0 +1,17 @@
1
+ default: &default
2
+ adapter: sqlite3
3
+ encoding: unicode
4
+ pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
5
+ timeout: 5000
6
+
7
+ development:
8
+ <<: *default
9
+ database: db/development.sqlite
10
+
11
+ test:
12
+ <<: *default
13
+ database: db/test.sqlite
14
+
15
+ production:
16
+ adapter: postgresql
17
+ url: <%= ENV['DATABASE_URL'] %>
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "api",
3
+ "license": "MIT",
4
+ "engines": {
5
+ "node": "11.11.0",
6
+ "yarn": "1.13.0"
7
+ },
8
+ "scripts": {
9
+ "build": "yarn --cwd client install && yarn --cwd client build",
10
+ "deploy": "cp -a client/build/. public/",
11
+ "heroku-postbuild": "yarn build && yarn deploy"
12
+ }
13
+ }
@@ -0,0 +1,6 @@
1
+
2
+ scope '/api' do
3
+ # Register your API resources here after scaffolding them e.g.
4
+ # resources :products
5
+ # resources :customers
6
+ end
@@ -0,0 +1,8 @@
1
+ namespace :start do
2
+ task :development do
3
+ exec 'heroku local -f Procfile.dev'
4
+ end
5
+ end
6
+
7
+ desc 'Start development server'
8
+ task :start => 'start:development'
@@ -0,0 +1,8 @@
1
+ module ReactRailsAPI
2
+ VERSION = {
3
+ major: 0,
4
+ minor: 1,
5
+ patch: 0,
6
+ meta: nil
7
+ }.values.reject(&:nil?).map(&:to_s)*?.
8
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'react-rails-api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'react-rails-api'
7
+ spec.version = ReactRailsAPI::VERSION
8
+ spec.authors = ['Edwin Onuonga', 'Charlie Gleason']
9
+ spec.email = ['edwinonuonga@gmail.com', 'hi@charliegleason.com']
10
+ spec.license = 'MIT'
11
+
12
+ spec.summary = %q{All-in-one application generator enabling the integration of a React front-end and a Ruby-on-Rails API back-end with ActiveAdmin CMS.}
13
+ spec.homepage = 'https://github.com/eonu/react-rails-api'
14
+
15
+ spec.files = Dir.glob('lib/**/*', File::FNM_DOTMATCH) + %w[Gemfile LICENSE README.md react-rails-api.gemspec bin/react-rails]
16
+ spec.bindir = 'bin'
17
+ spec.executables = 'react-rails'
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.required_ruby_version = "~> 2.5"
21
+
22
+ spec.add_runtime_dependency 'thor', '~> 0.20'
23
+ spec.add_runtime_dependency 'rails', '~> 5.2'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 2.0'
26
+ spec.add_development_dependency 'rake', '~> 12.3'
27
+
28
+ spec.metadata = {'source_code_uri' => spec.homepage}
29
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: react-rails-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Edwin Onuonga
8
+ - Charlie Gleason
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-03-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.20'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.20'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.2'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '5.2'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '12.3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '12.3'
70
+ description:
71
+ email:
72
+ - edwinonuonga@gmail.com
73
+ - hi@charliegleason.com
74
+ executables:
75
+ - react-rails
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - bin/react-rails
83
+ - lib/react-rails-api.rb
84
+ - lib/react-rails-api/cli.rb
85
+ - lib/react-rails-api/template.rb
86
+ - lib/react-rails-api/templates/.env.tt
87
+ - lib/react-rails-api/templates/Procfile.dev.tt
88
+ - lib/react-rails-api/templates/Procfile.tt
89
+ - lib/react-rails-api/templates/application.rb.tt
90
+ - lib/react-rails-api/templates/application_controller.rb.tt
91
+ - lib/react-rails-api/templates/database.yml.tt
92
+ - lib/react-rails-api/templates/package.json.tt
93
+ - lib/react-rails-api/templates/routes.rb.tt
94
+ - lib/react-rails-api/templates/start.rake.tt
95
+ - lib/react-rails-api/version.rb
96
+ - react-rails-api.gemspec
97
+ homepage: https://github.com/eonu/react-rails-api
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ source_code_uri: https://github.com/eonu/react-rails-api
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.5'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.0.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: All-in-one application generator enabling the integration of a React front-end
121
+ and a Ruby-on-Rails API back-end with ActiveAdmin CMS.
122
+ test_files: []