Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 055c78c

Browse files
authored
Merge pull request #6 from TwilioDevEd/upgrade-structure
Update structure and add webpacker
2 parents 3d55632 + 94614f5 commit 055c78c

33 files changed

+17339
-58
lines changed

.browserslistrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaults

.github/workflows/ruby.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ jobs:
4949
gem install bundler
5050
bundle config path vendor/bundle
5151
bundle install --jobs 4 --retry 3
52+
- name: Setup Node
53+
uses: actions/setup-node@v1
54+
with:
55+
node-version: 12.13.1
56+
- name: Install packages
57+
run: |
58+
npm install
5259
- name: Run tests
5360
run: |
5461
cp .env.example .env

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,10 @@ build-iPhoneSimulator/
8585
.rvmrc
8686

8787
.tool-versions
88+
89+
/public/packs
90+
/public/packs-test
91+
/node_modules
92+
/yarn-error.log
93+
yarn-debug.log*
94+
.yarn-integrity

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ COPY Gemfile ./
66

77
COPY Makefile ./
88

9-
RUN make install
10-
11-
COPY . .
12-
139
# Install a Javascript environment in the container to avoid ExecJS::RuntimeUnavailable
1410
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
1511
&& apt install -y nodejs
1612

13+
RUN make install
14+
15+
COPY . .
16+
1717
RUN make database
1818

1919
EXPOSE 3000

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ end
5959

6060
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
6161
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
62+
63+
gem "webpacker"

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ GEM
111111
puma (4.3.5)
112112
nio4r (~> 2.0)
113113
rack (2.2.3)
114+
rack-proxy (0.6.5)
115+
rack
114116
rack-test (1.1.0)
115117
rack (>= 1.0, < 3)
116118
rails (6.0.3.2)
@@ -153,6 +155,7 @@ GEM
153155
sprockets (> 3.0)
154156
sprockets-rails
155157
tilt
158+
semantic_range (2.3.0)
156159
spring (2.1.0)
157160
spring-watcher-listen (2.0.1)
158161
listen (>= 2.7, < 4.0)
@@ -184,6 +187,11 @@ GEM
184187
activemodel (>= 6.0.0)
185188
bindex (>= 0.4.0)
186189
railties (>= 6.0.0)
190+
webpacker (5.1.1)
191+
activesupport (>= 5.2)
192+
rack-proxy (>= 0.6.1)
193+
railties (>= 5.2)
194+
semantic_range (>= 2.3.0)
187195
websocket-driver (0.7.2)
188196
websocket-extensions (>= 0.1.0)
189197
websocket-extensions (0.1.5)
@@ -212,6 +220,7 @@ DEPENDENCIES
212220
tzinfo-data
213221
uglifier (>= 4.2.0)
214222
web-console (>= 4.0.1)
223+
webpacker
215224

216225
BUNDLED WITH
217226
2.1.4

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
.PHONY: install database serve
33

44
install:
5-
bundle install
5+
bundle install; \
6+
npm install;
67

78
database:
89
bundle exec rails db:migrate

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
![](https://github.com/TwilioDevEd/verify-v2-quickstart-rails/workflows/Ruby/badge.svg)
88

9-
> We are currently in the process of updating this sample template. If you are encountering any issues with the sample, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues) and we'll try to help you.
9+
> This template is part of Twilio CodeExchange. If you encounter any issues with this code, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues).
1010
1111
## About
1212

@@ -25,7 +25,8 @@ Implementations in other languages:
2525
### Requirements
2626

2727
- [Ruby](https://www.ruby-lang.org/) **2.6.x** version.
28-
- [Sqlite3](https://www.sqlite.org/)
28+
- [Sqlite3](https://www.sqlite.org/).
29+
- [Node.js](https://nodejs.org/en/) **10.x** or **12.x** version.
2930

3031
### Twilio Account Settings
3132

app/javascript/packs/application.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint no-console:0 */
2+
// This file is automatically compiled by Webpack, along with any other files
3+
// present in this directory. You're encouraged to place your actual application logic in
4+
// a relevant structure within app/javascript and only use these pack files to reference
5+
// that code so it'll be compiled.
6+
//
7+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8+
// layout file, like app/views/layouts/application.html.erb
9+
10+
11+
// Uncomment to copy all static images under ../images to the output folder and reference
12+
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
13+
// or the `imagePath` JavaScript helper below.
14+
//
15+
// const images = require.context('../images', true)
16+
// const imagePath = (name) => images(name, true)
17+
18+
console.log('Hello World from Webpacker')

babel.config.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = function(api) {
2+
var validEnv = ['development', 'test', 'production']
3+
var currentEnv = api.env()
4+
var isDevelopmentEnv = api.env('development')
5+
var isProductionEnv = api.env('production')
6+
var isTestEnv = api.env('test')
7+
8+
if (!validEnv.includes(currentEnv)) {
9+
throw new Error(
10+
'Please specify a valid `NODE_ENV` or ' +
11+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
12+
'"test", and "production". Instead, received: ' +
13+
JSON.stringify(currentEnv) +
14+
'.'
15+
)
16+
}
17+
18+
return {
19+
presets: [
20+
isTestEnv && [
21+
'@babel/preset-env',
22+
{
23+
targets: {
24+
node: 'current'
25+
}
26+
}
27+
],
28+
(isProductionEnv || isDevelopmentEnv) && [
29+
'@babel/preset-env',
30+
{
31+
forceAllTransforms: true,
32+
useBuiltIns: 'entry',
33+
corejs: 3,
34+
modules: false,
35+
exclude: ['transform-typeof-symbol']
36+
}
37+
]
38+
].filter(Boolean),
39+
plugins: [
40+
'babel-plugin-macros',
41+
'@babel/plugin-syntax-dynamic-import',
42+
isTestEnv && 'babel-plugin-dynamic-import-node',
43+
'@babel/plugin-transform-destructuring',
44+
[
45+
'@babel/plugin-proposal-class-properties',
46+
{
47+
loose: true
48+
}
49+
],
50+
[
51+
'@babel/plugin-proposal-object-rest-spread',
52+
{
53+
useBuiltIns: true
54+
}
55+
],
56+
[
57+
'@babel/plugin-transform-runtime',
58+
{
59+
helpers: false,
60+
regenerator: true,
61+
corejs: false
62+
}
63+
],
64+
[
65+
'@babel/plugin-transform-regenerator',
66+
{
67+
async: false
68+
}
69+
]
70+
].filter(Boolean)
71+
}
72+
}

bin/rails

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#!/usr/bin/env ruby
2-
begin
3-
load File.expand_path('../spring', __FILE__)
4-
rescue LoadError => e
5-
raise unless e.message.include?('spring')
6-
end
72
APP_PATH = File.expand_path('../config/application', __dir__)
83
require_relative '../config/boot'
94
require 'rails/commands'

bin/rake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#!/usr/bin/env ruby
2-
begin
3-
load File.expand_path('../spring', __FILE__)
4-
rescue LoadError => e
5-
raise unless e.message.include?('spring')
6-
end
72
require_relative '../config/boot'
83
require 'rake'
94
Rake.application.run

bin/setup

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env ruby
22
require 'fileutils'
3-
include FileUtils
43

54
# path to your application root.
65
APP_ROOT = File.expand_path('..', __dir__)
@@ -9,24 +8,25 @@ def system!(*args)
98
system(*args) || abort("\n== Command #{args} failed ==")
109
end
1110

12-
chdir APP_ROOT do
13-
# This script is a starting point to setup your application.
11+
FileUtils.chdir APP_ROOT do
12+
# This script is a way to setup or update your development environment automatically.
13+
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
1414
# Add necessary setup steps to this file.
1515

1616
puts '== Installing dependencies =='
1717
system! 'gem install bundler --conservative'
1818
system('bundle check') || system!('bundle install')
1919

20-
# Install JavaScript dependencies if using Yarn
20+
# Install JavaScript dependencies
2121
# system('bin/yarn')
2222

2323
# puts "\n== Copying sample files =="
2424
# unless File.exist?('config/database.yml')
25-
# cp 'config/database.yml.sample', 'config/database.yml'
25+
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
2626
# end
2727

2828
puts "\n== Preparing database =="
29-
system! 'bin/rails db:setup'
29+
system! 'bin/rails db:prepare'
3030

3131
puts "\n== Removing old logs and tempfiles =="
3232
system! 'bin/rails log:clear tmp:clear'

bin/webpack

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "bundler/setup"
11+
12+
require "webpacker"
13+
require "webpacker/webpack_runner"
14+
15+
APP_ROOT = File.expand_path("..", __dir__)
16+
Dir.chdir(APP_ROOT) do
17+
Webpacker::WebpackRunner.run(ARGV)
18+
end

bin/webpack-dev-server

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "bundler/setup"
11+
12+
require "webpacker"
13+
require "webpacker/dev_server_runner"
14+
15+
APP_ROOT = File.expand_path("..", __dir__)
16+
Dir.chdir(APP_ROOT) do
17+
Webpacker::DevServerRunner.run(ARGV)
18+
end

config/cable.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ development:
22
adapter: async
33

44
test:
5-
adapter: async
5+
adapter: test
66

77
production:
88
adapter: redis
99
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10-
channel_prefix: verify-v2-quickstart-rails_production
10+
channel_prefix: verify_v2_quickstart_rails_production

config/environments/development.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# Run rails dev:cache to toggle caching.
1717
if Rails.root.join('tmp', 'caching-dev.txt').exist?
1818
config.action_controller.perform_caching = true
19+
config.action_controller.enable_fragment_cache_logging = true
1920

2021
config.cache_store = :memory_store
2122
config.public_file_server.headers = {
@@ -27,7 +28,7 @@
2728
config.cache_store = :null_store
2829
end
2930

30-
# Store uploaded files on the local file system (see config/storage.yml for options)
31+
# Store uploaded files on the local file system (see config/storage.yml for options).
3132
config.active_storage.service = :local
3233

3334
# Don't care if the mailer can't send.
@@ -52,7 +53,7 @@
5253
# Suppress logger output for asset requests.
5354
config.assets.quiet = true
5455

55-
# Raises error for missing translations
56+
# Raises error for missing translations.
5657
# config.action_view.raise_on_missing_translations = true
5758

5859
# Use an evented file watcher to asynchronously detect changes in source code,

0 commit comments

Comments
 (0)