thredded_create_app 0.1.0 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e789f57ed0bc72c875265424613423e3e5555f42
4
- data.tar.gz: 4be5310ad208c0b2811e165759be33c79603baee
3
+ metadata.gz: 0a440b54c995a4acc228ea80bc49543584a7ace8
4
+ data.tar.gz: 783a3ef4755e06a4e49d99ce951a56c96c247195
5
5
  SHA512:
6
- metadata.gz: 786d97598b36481726f233146c2394a6dd819cb5e408322a4dc40b1dbd34bba68d3263b3599d4d0d28dff150f908fc7629bb7f7f6c89a767c93992d25e78b6f1
7
- data.tar.gz: e72055793bcf3eddc38e1937be2cd20fd0c45d7756065ea410ce7dc4262812a36d30b9640a534cdb22c7747ebe0723d7d76d15e6d32300436547964a57a92ce0
6
+ metadata.gz: 9c531f266980d0071259f18c46093356931dd95da360a5f33a64106955789a46acba83d028d26568a74ece981f4d78115a26f0644e8eff4e778cdda963c4c52e
7
+ data.tar.gz: 7879d3b6eece4346ea7cc797950f56006cc4f6ff2d39a89a7307c727491dd45f696796cf5afeee34c68c5cf66636eb3cf59d1f94207f68b1ed010026c104800d
data/README.md CHANGED
@@ -2,11 +2,6 @@
2
2
 
3
3
  Generates a Rails app with the [Thredded](https://github.com/thredded/thredded) forums engine installed.
4
4
 
5
- This generator will create a new Rails app with the following configuration:
6
-
7
- * Database: PostgreSQL.
8
- * Auth: Devise.
9
-
10
5
  See below for more information on the generated app.
11
6
 
12
7
  Example screenshots of the generated app:
@@ -25,7 +20,7 @@ Example screenshots of the generated app:
25
20
  ## Pre-requisites
26
21
 
27
22
  1. Git.
28
- 2. PostgreSQL.
23
+ 2. A supported database: PostgreSQL (recommended), MySQL v5.6.4+, or SQLite.
29
24
  3. Ruby 2.3+.
30
25
 
31
26
  ## Usage
@@ -37,6 +32,10 @@ gem install thredded_create_app
37
32
  thredded_create_app myapp
38
33
  ```
39
34
 
35
+ By default, PostgreSQL will be used as the database.
36
+ Alternatively, you can pass `--database sqlite3` for SQLite,
37
+ or `--datase mysql2` for MySQL.
38
+
40
39
  Run `thredded_create_app --help` for more information about the available
41
40
  options.
42
41
 
@@ -68,7 +67,7 @@ The app generator will do the steps below for you.
68
67
  First, the rubygems package is updated and the latest versions of
69
68
  [Rails] and [Bundler] are installed.
70
69
 
71
- Then, a Rails app is generated for use with the PostgreSQL database.
70
+ Then, a Rails app is generated for use with the selected database.
72
71
 
73
72
  Then, a [git] repository is initialized in the app directory. From here onwards,
74
73
  the app generator will commit the changes at each step.
@@ -156,8 +155,10 @@ by tweeting [@thredded]!
156
155
  The instructions below are for developing and contributing to
157
156
  the Thredded app generator itself, not for using it.
158
157
 
159
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
160
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
158
+ After checking out the repo, run `bin/setup` to install dependencies.
159
+ Then, run `rake spec` to run the tests.
160
+ You can also run `bin/console` for an interactive prompt that will allow you
161
+ to experiment.
161
162
 
162
163
  To generate an app with `thredded_create_app` at `tmp/myapp`, run:
163
164
 
@@ -165,21 +166,26 @@ To generate an app with `thredded_create_app` at `tmp/myapp`, run:
165
166
  bundle exec bin/create-tmp-myapp
166
167
  ```
167
168
 
168
- This command will clean up the previously generated app before creating a new one.
169
+ This command will clean up the previously generated app before creating
170
+ a new one.
169
171
 
170
172
  To install this gem onto your local machine, run `bundle exec rake install`.
171
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
172
- which will create a git tag for the version, push git commits and tags, and push the `.gem` file to
173
+ To release a new version, update the version number in `version.rb`, and then
174
+ run `bundle exec rake release`, which will create a git tag for the version,
175
+ push git commits and tags, and push the `.gem` file to
173
176
  [rubygems.org](https://rubygems.org).
174
177
 
175
178
  ## Contributing
176
179
 
177
- Bug reports and pull requests are welcome on GitHub at https://github.com/thredded/thredded_create_app.
178
- This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
180
+ Bug reports and pull requests are welcome on GitHub at
181
+ https://github.com/thredded/thredded_create_app.
182
+ This project is intended to be a safe, welcoming space for collaboration,
183
+ and contributors are expected to adhere to the
179
184
  [Contributor Covenant](http://contributor-covenant.org) code of conduct.
180
185
 
181
186
 
182
187
  ## License
183
188
 
184
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
189
+ The gem is available as open source under the terms of the
190
+ [MIT License](http://opensource.org/licenses/MIT).
185
191
 
@@ -5,7 +5,7 @@ require 'thredded_create_app/logging'
5
5
 
6
6
  require 'highline'
7
7
  module ThreddedCreateApp
8
- class CLI
8
+ class CLI # rubocop:disable Metrics/ClassLength
9
9
  include ThreddedCreateApp::Logging
10
10
 
11
11
  DEFAULTS = {
@@ -13,7 +13,8 @@ module ThreddedCreateApp
13
13
  verbose: false,
14
14
  install_gem_bundler_rails: true,
15
15
  start_server: true,
16
- simple_form: true
16
+ simple_form: true,
17
+ database: :postgresql
17
18
  }.freeze
18
19
 
19
20
  def self.start(argv)
@@ -83,6 +84,21 @@ module ThreddedCreateApp
83
84
  flags = Flags.new(op, options)
84
85
 
85
86
  flags.bool :auto_confirm, '-y', 'Auto-confirm all prompts'
87
+ flags.bool :simple_form, '--[no-]simple-form', 'Use simple_form'
88
+
89
+ db_adapters = %i(postgresql mysql2 sqlite3)
90
+ op.on '--database DATABASE', db_adapters,
91
+ "The database adapter, one of: #{db_adapters.join(', ')} " \
92
+ "(default: #{DEFAULTS[:database]})" do |v|
93
+ options[:database] = v.to_sym
94
+ end
95
+
96
+ flags.bool :start_server, '--[no-]start-server', 'Start the app server'
97
+
98
+ flags.bool :install_gem_bundler_rails,
99
+ '--[no-]install-gem-bundler-rails',
100
+ 'Run `gem update --system and `gem install bundler rails`'
101
+
86
102
  op.on '-v', '--version', 'Print the version' do
87
103
  puts ThreddedCreateApp::VERSION
88
104
  exit
@@ -90,12 +106,6 @@ module ThreddedCreateApp
90
106
  flags.bool :verbose, '--verbose', 'Verbose output' do
91
107
  @verbose = true
92
108
  end
93
- flags.bool :simple_form, '--[no-]simple-form', 'Use simple_form'
94
- flags.bool :install_gem_bundler_rails,
95
- '--[no-]install-gem-bundler-rails',
96
- 'Run `gem update --system and `gem install bundler rails`'
97
- flags.bool :start_server, '--[no-]start-server', 'Start the app server'
98
-
99
109
  op.on '-h', '--help', 'Show this message' do
100
110
  STDERR.puts op
101
111
  exit
@@ -65,7 +65,7 @@ module ThreddedCreateApp
65
65
  Tasks::AddDisplayNameToUsers,
66
66
  Tasks::SetupAppSkeleton,
67
67
  Tasks::ProductionConfigs,
68
- Tasks::Docker,
68
+ (Tasks::Docker if @options[:database] == :postgresql),
69
69
  Tasks::SetupDatabase
70
70
  ].compact.map { |task_class| task_class.new(@options) }
71
71
  end
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
  class AddDisplayNameToUsers < ActiveRecord::Migration[5.0]
3
3
  def up
4
- add_column :users, :display_name, :text, null: false
4
+ case connection.adapter_name.to_s
5
+ when /mysql/i
6
+ add_column :users, :display_name, :string, limit: 191
7
+ when /sqlite/i
8
+ add_column :users, :display_name, :text
9
+ change_column_null :users, :display_name, false
10
+ else
11
+ add_column :users, :display_name, :text, null: false
12
+ end
13
+
5
14
  DbTextSearch::CaseInsensitive.add_index connection, :users, :display_name,
6
15
  unique: true
7
16
  end
@@ -49,7 +49,7 @@ module ThreddedCreateApp
49
49
 
50
50
  def copy_template(src_path, target_path, process_erb: true, mode: 'w')
51
51
  src = File.read(File.expand_path(src_path, File.dirname(__FILE__)))
52
- src = ERB.new(src).result(binding) if process_erb
52
+ src = ERB.new(src, nil, '-').result(binding) if process_erb
53
53
  FileUtils.mkdir_p(File.dirname(target_path))
54
54
  File.write target_path, src, mode: mode
55
55
  end
@@ -3,9 +3,10 @@ require 'thredded_create_app/tasks/base'
3
3
  module ThreddedCreateApp
4
4
  module Tasks
5
5
  class CreateRailsApp < Base
6
- def initialize(install_gem_bundler_rails: false, **args)
6
+ def initialize(install_gem_bundler_rails:, database:, **args)
7
7
  super
8
8
  @install_gem_bundler_rails = install_gem_bundler_rails
9
+ @database = database
9
10
  end
10
11
 
11
12
  def summary
@@ -17,9 +18,10 @@ module ThreddedCreateApp
17
18
  run 'gem update --system --no-document --quiet'
18
19
  run 'gem install bundler rails --no-document'
19
20
  end
21
+ rails_database_arg = { mysql2: :mysql }.fetch(@database, @database)
20
22
  # I have no idea why this bundle exec is necessary on Travis.
21
23
  run "#{'bundle exec ' if ENV['TRAVIS']}" \
22
- 'rails new . --skip-bundle --database=postgresql ' \
24
+ "rails new . --skip-bundle --database=#{rails_database_arg} " \
23
25
  "--skip-test#{verbose? ? ' --verbose' : ' --quiet'}"
24
26
  replace 'Gemfile', /gem 'sass-rails'.*$/, "gem 'sassc-rails'"
25
27
  add_gem 'rspec-rails', groups: %i(test)
@@ -2,6 +2,7 @@
2
2
  require 'thredded_create_app/tasks/base'
3
3
  module ThreddedCreateApp
4
4
  module Tasks
5
+ # Currently only implemented for the postgresql database.
5
6
  class Docker < Base
6
7
  def summary
7
8
  'Add Docker configuration files for development'
@@ -24,6 +24,7 @@
24
24
  <hr>
25
25
  <p>Your app uses:</p>
26
26
  <ul>
27
+ <li><%%= ActiveRecord::Base.connection.adapter_name %> database.</li>
27
28
  <li>
28
29
  <a href="http://rubyonrails.org/">Ruby on Rails</a>
29
30
  v<%%= Rails::VERSION::STRING %>.
@@ -3,6 +3,12 @@ require 'thredded_create_app/tasks/base'
3
3
  module ThreddedCreateApp
4
4
  module Tasks
5
5
  class SetupDatabase < Base
6
+ # @param [:postgresql, :mysql2, :sqlite3] database the DB db_adapter name.
7
+ def initialize(database:, **_args)
8
+ super
9
+ @db_adapter = database
10
+ end
11
+
6
12
  def summary
7
13
  'Create the database user, configure database.yml, and run migrations'
8
14
  end
@@ -19,15 +25,22 @@ module ThreddedCreateApp
19
25
  private
20
26
 
21
27
  def create_db_user
28
+ return if @db_adapter == :sqlite3
22
29
  log_info "Creating #{dev_user} local database user"
23
30
  run 'bash',
24
31
  File.join(File.dirname(__FILE__), 'setup_database',
25
- 'create_postgresql_user.sh'),
32
+ 'create_database_user.sh'),
33
+ @db_adapter.to_s,
34
+ app_name,
26
35
  dev_user,
27
36
  dev_user_password,
37
+ ENV['TRAVIS'] || '',
28
38
  log: false
29
39
  end
30
40
 
41
+ # @return [Symbol]
42
+ attr_reader :db_adapter
43
+
31
44
  def dev_user
32
45
  "#{app_name}_dev"
33
46
  end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env bash
2
+ DB="$1"
3
+ APP_NAME="$2"
4
+ USER="$3"
5
+ PASS="$4"
6
+ TRAVIS="$5"
7
+
8
+ BLUE='\033[1;34m'
9
+ RESET_COLOR='\033[0m'
10
+ log() { if [ -t 1 ]; then echo -e >&2 "${BLUE} $@${RESET_COLOR}"; else echo >&2 "$@"; fi }
11
+
12
+ set -e
13
+
14
+ create_postgresql_user() {
15
+ if PGPASSWORD="$PASS" psql -h 127.0.0.1 postgres -U $USER -c '' 2>/dev/null; then return; fi
16
+ log "Creating Postgres '$USER' user."
17
+ local cmd='psql postgres'
18
+ if ! $cmd -c '' 2>/dev/null; then
19
+ log 'Using sudo'
20
+ cmd="sudo -u ${PG_DAEMON_USER:-postgres} psql postgres"
21
+ fi
22
+ $cmd --quiet <<SQL
23
+ CREATE ROLE $USER LOGIN PASSWORD '$PASS';
24
+ ALTER ROLE $USER CREATEDB;
25
+ SQL
26
+ }
27
+
28
+ create_mysql_user() {
29
+ if mysql -s -u"$USER" -p"$PASS" -e '' 2>/dev/null ; then return; fi
30
+ log "Creating MySQL '$USER' user. MySQL root password required."
31
+ local mysql_flags='-p'
32
+ if [ -n "$TRAVIS" ]; then
33
+ mysql_flags=''
34
+ fi
35
+ mysql --verbose -uroot $mysql_flags <<SQL
36
+ GRANT ALL PRIVILEGES ON \`${APP_NAME}_dev\`.* TO '$USER'@'localhost' IDENTIFIED BY '$PASS';
37
+ GRANT ALL PRIVILEGES ON \`${APP_NAME}_test\`.* TO '$USER'@'localhost';
38
+ SQL
39
+ }
40
+
41
+ if [ "$DB" = 'mysql2' ]; then
42
+ create_mysql_user || echo 'Error'
43
+ elif [ "$DB" = 'postgresql' ]; then
44
+ create_postgresql_user || echo 'Error'
45
+ fi
@@ -1,6 +1,8 @@
1
1
  <%%
2
+ <% if db_adapter != :sqlite3 -%>
2
3
  db_host = ENV.fetch('DB_HOST', ENV.fetch('<%= app_name.upcase %>_DB_1_PORT_5432_TCP_ADDR', 'localhost'))
3
- db_port = ENV['<%= app_name.upcase %>_DB_1_PORT_5432_TCP_PORT'] || ENV['DB_PORT'] || 5432
4
+ db_port = ENV['<%= app_name.upcase %>_DB_1_PORT_5432_TCP_PORT'] || ENV['DB_PORT'] || <%= {postgresql: 5432, mysql2: 3306}[db_adapter] %>
5
+ <% end -%>
4
6
  require 'etc'
5
7
  pool_size =
6
8
  # Web: max workers * max threads
@@ -11,26 +13,37 @@ ERB
11
13
  %>
12
14
 
13
15
  defaults: &defaults
14
- host: <%%= db_host %>
15
- port: <%%= db_port %>
16
- adapter: postgresql
17
- encoding: utf8
16
+ adapter: <%= db_adapter %>
18
17
  min_messages: WARNING
19
18
  pool: <%%= pool_size %>
19
+ <% if db_adapter == :sqlite3 -%>
20
+ timeout: 5000
21
+ <% else -%>
22
+ host: <%%= db_host %>
23
+ port: <%%= db_port %>
20
24
  username: <%%= ENV.fetch('DB_USERNAME', '<%= dev_user %>').inspect %>
21
25
  password: <%%= ENV.fetch('DB_PASSWORD', <%= dev_user_password.inspect %>).inspect %>
26
+ <% end -%>
27
+ <% if db_adapter == :mysql2 -%>
28
+ encoding: utf8mb4
29
+ charset: utf8mb4
30
+ collation: utf8mb4_unicode_ci
31
+ <% else -%>
32
+ encoding: utf8
33
+ <% end -%>
22
34
 
23
35
  development:
24
36
  <<: *defaults
25
- database: <%= "#{app_name}_dev" %>
37
+ database: <%= db_adapter == :sqlite3 ? 'db/development.sqlite3' : "#{app_name}_dev" %>
26
38
 
27
39
  test:
28
40
  <<: *defaults
29
- database: <%= "#{app_name}_test" %>
41
+ database: <%= db_adapter == :sqlite3 ? 'db/test.sqlite3' : "#{app_name}_test" %>
42
+
30
43
 
31
44
  production:
32
45
  <<: *defaults
33
46
  encoding: utf8
34
47
  min_messages: WARNING
35
48
  url: <%%= ENV['DATABASE_URL'].inspect if ENV['DATABASE_URL'] %>
36
- database: <%%= '<%= "#{app_name}_prod" %>' unless ENV['DATABASE_URL'] %>
49
+ database: <%%= '<%= (db_adapter == :sqlite3 ? 'db/production.sqlite3' : "#{app_name}_prod") %>' unless ENV['DATABASE_URL'] %>
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ThreddedCreateApp
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.2'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thredded_create_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Mazovetskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-13 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -145,7 +145,7 @@ files:
145
145
  - lib/thredded_create_app/tasks/setup_app_skeleton/spec/features/homepage_spec.rb
146
146
  - lib/thredded_create_app/tasks/setup_app_skeleton/users_show.html.erb
147
147
  - lib/thredded_create_app/tasks/setup_database.rb
148
- - lib/thredded_create_app/tasks/setup_database/create_postgresql_user.sh
148
+ - lib/thredded_create_app/tasks/setup_database/create_database_user.sh
149
149
  - lib/thredded_create_app/tasks/setup_database/database.yml.erb
150
150
  - lib/thredded_create_app/version.rb
151
151
  homepage: https://github.com/thredded/thredded_create_app
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env bash
2
- USER="$1"
3
- PASS="$2"
4
-
5
- BLUE='\033[1;34m'
6
- RESET_COLOR='\033[0m'
7
- log() { if [ -t 1 ]; then echo -e >&2 "${BLUE} $@${RESET_COLOR}"; else echo >&2 "$@"; fi }
8
-
9
- set -e
10
-
11
- create_postgresql_user() {
12
- if PGPASSWORD="$PASS" psql -h 127.0.0.1 postgres -U $USER -c '' 2>/dev/null; then return; fi
13
- log "Creating Postgres '$USER' user."
14
- local cmd='psql postgres'
15
- if ! $cmd -c '' 2>/dev/null; then
16
- log 'Using sudo'
17
- cmd="sudo -u ${PG_DAEMON_USER:-postgres} psql postgres"
18
- fi
19
- $cmd --quiet <<SQL
20
- CREATE ROLE $USER LOGIN PASSWORD '$PASS';
21
- ALTER ROLE $USER CREATEDB;
22
- SQL
23
- }
24
-
25
- create_postgresql_user