-
Notifications
You must be signed in to change notification settings - Fork 2
/
new_ruby_project.sh
executable file
·139 lines (109 loc) · 3.03 KB
/
new_ruby_project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
set -u
read -p "Enter a project name:" projectname
read -p "Enter where you want the project files to be created: [default=$HOME/Desktop]" basedir
basedir=${basedir:-"$HOME/Desktop"}
echo "creating folders"
mkdir -p $basedir/$projectname/{views,config,db/migrate}
mkdir -p $basedir/$projectname/public/{css,js}
echo "creating files"
cd $basedir
bundle gem $projectname
cd $projectname
cat >Gemfile <<'EOM'
source 'https://rubygems.org'
ruby "2.4.0"
gem 'pg'
gem 'pry'
gem 'pry-byebug'
gem 'sinatra'
gem 'sinatra-activerecord'
gem 'sinatra-flash'
group :development do
gem 'sinatra-contrib'
end
group :test do
gem 'capybara'
gem 'rspec'
gem 'shoulda-matchers'
gem 'timecop'
end
gemspec
EOM
cat >./views/layout.erb <<'EOM'
<!DOCTYPE html>
<head>
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<%= yield %>
</body>
</html>
EOM
cat >app.rb <<'EOM'
require 'sinatra'
require 'sinatra/activerecord'
require 'sinatra-flash'
if development?
require 'sinatra/reloader'
also_reload('**/*.rb')
end
get('/') do
erb(:index)
end
EOM
cat >config.ru <<'EOM'
require_relative './boot'
run Sinatra::Application
EOM
cat >Procfile <<'EOM'
web: bundle exec rackup config.ru -p $PORT
EOM
cat >boot.rb <<'EOM'
require 'pry-byebug'
require 'app'
require 'rake'
require 'sinatra/activerecord/rake'
env = ENV['RACK_ENV'] || 'development'
EOM
cat >.rubocop.yml <<'EOM'
Metrics/BlockLength:
ExcludedMethods: ['describe', 'context']
EOM
cat >./config/database.yml <<EOM
development:
adapter: postgresql
database: ${projectname}_dev
test:
adapter: postgresql
database: ${projectname}_test
EOM
touch ./views/index.erb
touch ./public/{css/styles.css,js/scripts.js}
# TODO: test if rubocop is installed
rubocop -a
# if [ ! -f "$HOME/.pairs" ]; then
# echo "You should probably create a pairs file."
# fi
if [ -f "$HOME/.pre-commit-config.yaml" ]; then
cp "$HOME/.pre-commit-config.yaml" "./.pre-commit-config.yaml"
pre-commit install
fi
eslint --init
echo 'Next steps: edit the .gemspec file and then run "bundle install".'
read -n1 -p "launch atom? [Y/n]" atom
shopt -s nocasematch
if [ $atom != 'n' ]; then
atom .
fi
shopt -u nocasematch
exit 0