rhino_project_core 0.20.0.beta.56 → 0.20.0.beta.58

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5787252bf73e3a76a3fd09cdb8ef5991357e2caf04cf822aa550a59ee1088b8
4
- data.tar.gz: c6f18aa9473aefda255d6eecefdfee3e1e763ca1a0ca73cedd06146c97d22b6d
3
+ metadata.gz: '008e81dfdd7ffb00ea6194ef3ad58b1c946e5a9e825bdc1c9f32776a6c1758eb'
4
+ data.tar.gz: 94b20856e77d2268673a8bf9fe0e9486748f14bf2b59c0c713ac9113b4220b2e
5
5
  SHA512:
6
- metadata.gz: bed302755a96c5d733291eb739ebe8ebde88b16f77f327a7330cee490f736164adf3b3f3f6c5dba42320102d1f344e1d0b418111a1bdcc501cbe636be0232ec6
7
- data.tar.gz: 1c667753820be71de76c9a046b1b9c5fdc8c765840ab0f39562397b0129b1afc3624f64cc5ee30ce075f3d28d7a53d940bc0e98ae5c6b392093054b88ed3d75b
6
+ metadata.gz: 88a76b15cf04ede26d1de6d4682dce62981d4c9893ec9139d4a0fb3ef6d79a91628f67d2041666c3f5ecd565a40b572cefc1ca8df88159cf9dfdd9585ea4f9da
7
+ data.tar.gz: b0bf7650d5c4167b4a703468b313669790ed87235025837537975b4e7c8dd4a3066cf0b40b2d2fc1a2271554a62a82011cc7eec420ca662e8c546d8806cd8b29
@@ -5,16 +5,21 @@ module Rhino
5
5
  module Dev
6
6
  # rubocop:disable Metrics/ClassLength
7
7
  class SetupGenerator < ::Rails::Generators::Base
8
- class_option :prompt, type: :boolean, default: true
9
- class_option :server_port, type: :numeric
10
- class_option :client_port, type: :numeric
11
- class_option :db_host, type: :string
12
- class_option :db_name, type: :string
13
- class_option :db_port, type: :numeric
14
- class_option :db_user, type: :string
15
- class_option :db_password, type: :string
16
- class_option :redis_port, type: :numeric
17
- class_option :redis_database, type: :numeric
8
+ DEFAULT_SERVER_PORT = 3000
9
+ DEFAULT_CLIENT_PORT = DEFAULT_SERVER_PORT + 1
10
+
11
+ class_option :prompt, type: :boolean, default: true, desc: "Prompt user for configuration options"
12
+ class_option :defaults, type: :string, enum: %w[local docker], default: "local", desc: "Use configuration defaults of type DEFAULTS"
13
+ class_option :skip_existing, type: :boolean, default: false, desc: "Skip existing env files"
14
+ class_option :server_port, type: :numeric, default: DEFAULT_SERVER_PORT, group: :server, desc: "Server port"
15
+ class_option :client_port, type: :numeric, default: DEFAULT_CLIENT_PORT, group: :client, desc: "Client port"
16
+ class_option :db_host, type: :string, group: :database
17
+ class_option :db_name, type: :string, group: :database
18
+ class_option :db_port, type: :numeric, default: 5432, group: :database
19
+ class_option :db_user, type: :string, group: :database
20
+ class_option :db_password, type: :string, group: :database
21
+ class_option :redis_port, type: :numeric, default: 6379, group: :redis
22
+ class_option :redis_database, type: :numeric, default: 0, group: :redis
18
23
 
19
24
  attr_reader :server_port,
20
25
  :client_port,
@@ -30,11 +35,19 @@ module Rhino
30
35
 
31
36
  source_root File.expand_path("templates", __dir__)
32
37
 
38
+ def check_existing
39
+ return unless options[:skip_existing] && File.exist?(server_file(".env"))
40
+
41
+ say "Skipping existing .env files"
42
+ exit(0)
43
+ end
44
+
33
45
  def setup_env
34
46
  say "Setting up local .env files"
35
47
 
36
48
  collect_env_info
37
49
 
50
+ template "env.root", project_file(".env")
38
51
  template "env.server", server_file(".env")
39
52
  template "env.client", client_file(".env")
40
53
  end
@@ -58,17 +71,19 @@ module Rhino
58
71
  end
59
72
 
60
73
  def server_port_default
61
- options[:server_port] || ENV["PORT"] || 3000
74
+ options[:server_port] || ENV["PORT"]
62
75
  end
63
76
 
64
77
  def client_port_default
65
78
  @server_port.to_i + 1
66
79
  end
67
80
 
81
+ def project_name
82
+ @project_name ||= File.basename(project_dir).sub(/[-_]?mono/, "")
83
+ end
84
+
68
85
  def db_name_default
69
- db_name =
70
- options[:db_name] || ENV["DB_NAME"] ||
71
- File.basename(project_dir).sub(/[-_]?mono/, "")
86
+ db_name = options[:db_name] || ENV["DB_NAME"] || project_name
72
87
 
73
88
  return db_name if db_name.present?
74
89
 
@@ -80,15 +95,15 @@ module Rhino
80
95
  end
81
96
 
82
97
  def db_port_default
83
- options[:db_port] || ENV["DB_PORT"] || 5432
98
+ options[:db_port] || ENV["DB_PORT"]
84
99
  end
85
100
 
86
101
  def db_user_default
87
- options[:db_user] || ENV["DB_USERNAME"] || (dockerized ? "postgres" : "")
102
+ options[:db_user] || ENV["DB_USERNAME"] || `whoami`
88
103
  end
89
104
 
90
105
  def db_password_default
91
- options[:db_password] || ENV["DB_PASSWORD"] || (dockerized ? "password" : "")
106
+ options[:db_password] || ENV["DB_PASSWORD"] || ""
92
107
  end
93
108
 
94
109
  def redis_host_default
@@ -96,15 +111,15 @@ module Rhino
96
111
  end
97
112
 
98
113
  def redis_port_default
99
- options[:redis_port] || ENV["REDIS_PORT"] || 6379
114
+ options[:redis_port] || ENV["REDIS_PORT"]
100
115
  end
101
116
 
102
117
  def redis_database_default
103
- options[:redis_database] || ENV["REDIS_DATABASE"] || 0
118
+ options[:redis_database] || ENV["REDIS_DATABASE"]
104
119
  end
105
120
 
106
121
  def dockerized_default
107
- "yN"
122
+ options[:defaults] == "docker" ? "Y" : "N"
108
123
  end
109
124
 
110
125
  def collect_env_info
@@ -118,37 +133,46 @@ module Rhino
118
133
  end
119
134
 
120
135
  def collect_docker_info
121
- @dockerized = %w[y Y].include?(ask_prompt("Run server on docker?", dockerized_default))
136
+ @dockerized = %w[y Y].include?(ask_prompt("Run with docker?", dockerized_default))
122
137
 
123
138
  return unless dockerized
124
139
 
125
140
  @db_host = "db"
141
+ @db_user = "postgres"
142
+ @db_password = "password"
143
+ @db_port = 5432
126
144
  @redis_host = "redis"
127
145
  @redis_port = 6379
146
+ @redis_database = 0
128
147
 
129
148
  puts <<~HERE
130
149
  The following docker configuration has been automatically set for you:
131
150
  Database host: #{db_host}
151
+ Database port: #{db_port}
152
+ Database user: #{db_user}
153
+ Database password: #{db_password}
132
154
  Redis host: #{redis_host}
133
155
  Redis port: #{redis_port}
156
+ Redis database: #{redis_database}
134
157
  HERE
135
158
  end
136
159
 
137
- def collect_database_info # rubocop:todo Metrics/AbcSize
160
+ def collect_database_info
138
161
  @db_name = ask_prompt("Database?", db_name_default)
139
- @db_host = ask_prompt("Database host?", db_host_default) unless dockerized
140
- @db_port = ask_prompt("Database port?", db_port_default)
141
- @db_user = ask_prompt("Database User?", db_user_default) until !dockerized || db_user.present?
142
- @db_password = ask_prompt("Database Password?", db_password_default) until !dockerized || db_password.present?
162
+ @db_host ||= ask_prompt("Database host?", db_host_default)
163
+ @db_port ||= ask_prompt("Database port?", db_port_default)
164
+ @db_user ||= ask_prompt("Database User?", db_user_default)
165
+ @db_password ||= ask_prompt("Database Password?", db_password_default)
166
+
167
+ nil
143
168
  end
144
169
 
145
170
  def collect_redis_info
146
- unless dockerized
147
- @redis_host = ask_prompt("Redis host?", redis_host_default)
148
- @redis_port = ask_prompt("Redis port?", redis_port_default)
149
- end
171
+ @redis_host ||= ask_prompt("Redis host?", redis_host_default)
172
+ @redis_port ||= ask_prompt("Redis port?", redis_port_default)
173
+ @redis_database ||= ask_prompt("Redis database?", redis_database_default)
150
174
 
151
- @redis_database = ask_prompt("Redis database?", redis_database_default)
175
+ nil
152
176
  end
153
177
 
154
178
  def project_file(file)
@@ -0,0 +1 @@
1
+ COMPOSE_PROJECT_NAME=<%= project_name %>
data/lib/rhino/version.rb CHANGED
@@ -10,7 +10,7 @@ module Rhino
10
10
  MAJOR = 0
11
11
  MINOR = 20
12
12
  TINY = 0
13
- PRE = "beta.56"
13
+ PRE = "beta.58"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhino_project_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0.beta.56
4
+ version: 0.20.0.beta.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Rosevear
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-17 00:00:00.000000000 Z
11
+ date: 2024-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -171,6 +171,7 @@ files:
171
171
  - lib/commands/rhino_command.rb
172
172
  - lib/generators/rhino/dev/setup/setup_generator.rb
173
173
  - lib/generators/rhino/dev/setup/templates/env.client.tt
174
+ - lib/generators/rhino/dev/setup/templates/env.root.tt
174
175
  - lib/generators/rhino/dev/setup/templates/env.server.tt
175
176
  - lib/generators/rhino/dev/setup/templates/prepare-commit-msg
176
177
  - lib/generators/rhino/install/install_generator.rb