hephaestus 0.8.11 → 0.8.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +3 -1
  5. data/bin/hephaestus +31 -13
  6. data/lib/hephaestus/app_builder.rb +23 -145
  7. data/lib/hephaestus/app_name.rb +33 -0
  8. data/lib/hephaestus/generators/app_generator.rb +70 -72
  9. data/lib/hephaestus/generators/config_generator.rb +3 -114
  10. data/lib/hephaestus/generators/core_generator.rb +18 -58
  11. data/lib/hephaestus/generators/db_generator.rb +12 -0
  12. data/lib/hephaestus/generators/deployment_generator.rb +1 -6
  13. data/lib/hephaestus/generators/lib_generator.rb +0 -10
  14. data/lib/hephaestus/generators/license_generator.rb +4 -1
  15. data/lib/hephaestus/generators/rubocop_generator.rb +1 -1
  16. data/lib/hephaestus/version.rb +1 -1
  17. data/lib/hephaestus.rb +2 -0
  18. data/templates/Dockerfile +7 -75
  19. data/templates/Gemfile +73 -0
  20. data/templates/Procfile +2 -0
  21. data/templates/app/controllers/app_controller.rb.tt +35 -0
  22. data/templates/app/controllers/application_controller.rb +1 -7
  23. data/templates/app/controllers/concerns/authable.rb.tt +50 -0
  24. data/templates/app/controllers/settings_controller.rb +5 -28
  25. data/templates/app/controllers/yetto_controller.rb +9 -10
  26. data/templates/app/lib/body_parameter/yetto_parameters.rb +8 -29
  27. data/templates/app/lib/{constants/app.rb → constants.rb} +1 -3
  28. data/templates/app/services/{http_service.rb → app_service.rb.tt} +6 -6
  29. data/templates/app/views/settings/new.json.jbuilder.tt +18 -0
  30. data/templates/bin/bundle +115 -0
  31. data/templates/bin/docker-entrypoint +20 -10
  32. data/templates/bin/foreman +27 -0
  33. data/templates/bin/jobs +7 -0
  34. data/templates/bin/rails +6 -0
  35. data/templates/bin/rake +6 -0
  36. data/templates/bin/setup +28 -0
  37. data/templates/bin/tapioca +27 -0
  38. data/templates/config/application.rb.tt +36 -0
  39. data/templates/config/boot.rb +7 -0
  40. data/templates/config/environment.rb +8 -0
  41. data/templates/config/environments/blank.rb +7 -0
  42. data/templates/config/initializers/environment.rb +2 -36
  43. data/templates/config/locales/en.yml +5 -31
  44. data/templates/config/puma.rb +5 -0
  45. data/templates/config/routes.rb.tt +28 -0
  46. data/templates/config.ru +9 -0
  47. data/templates/db/queue_schema.rb +132 -0
  48. data/templates/db/schema.rb +17 -0
  49. data/templates/lib/schemas/api/2023-03-06/components/parameters/headers/yetto.json +42 -0
  50. data/templates/lib/schemas/api/2023-03-06/components/parameters/plugInstallation.json +12 -0
  51. data/templates/lib/schemas/api/2023-03-06/components/schemas/plug.json +9 -0
  52. data/templates/lib/schemas/api/2023-03-06/components/schemas/responses.json +64 -0
  53. data/templates/lib/schemas/api/2023-03-06/components/schemas/yetto.json +116 -0
  54. data/templates/lib/schemas/api/2023-03-06/openapi.json +30 -0
  55. data/templates/lib/schemas/api/2023-03-06/paths/app.json +90 -0
  56. data/templates/lib/schemas/api/2023-03-06/paths/yetto/message_created.json +51 -0
  57. data/templates/lib/schemas/api/2023-03-06/paths/yetto/plug_installation_created.json +51 -0
  58. data/templates/script/docker-build-prod.tt +11 -0
  59. data/templates/script/docker-run.tt +8 -0
  60. data/templates/script/edit-credentials +12 -3
  61. data/templates/script/hmac_text +1 -1
  62. data/templates/script/ngrok.tt +7 -0
  63. data/templates/script/server +6 -45
  64. data/templates/test/controllers/app_controller_test.rb.tt +188 -0
  65. data/templates/test/controllers/settings_controller_test.rb.tt +125 -0
  66. data/templates/test/controllers/yetto_controller_test.rb +100 -71
  67. data/templates/test/fixtures/files/plug_installation_settings/valid.json +1 -1
  68. data/templates/test/support/rails.rb +16 -36
  69. data/templates/test/support/webmocks/app_webmock.rb.tt +29 -0
  70. data/templates/test/test_helper.rb +1 -31
  71. data/templates/vendor/fly/{fly-production.toml → fly-production.toml.tt} +24 -11
  72. data/templates/vendor/fly/{fly-staging.toml → fly-staging.toml.tt} +18 -15
  73. metadata +46 -71
  74. data/templates/Gemfile.erb +0 -120
  75. data/templates/Procfile.debug +0 -2
  76. data/templates/Procfile.dev +0 -2
  77. data/templates/app/controllers/app_controller.rb +0 -72
  78. data/templates/app/controllers/concerns/authable.rb +0 -50
  79. data/templates/app/controllers/staff_controller.rb +0 -15
  80. data/templates/app/jobs/update_yetto_job.rb +0 -26
  81. data/templates/app/lib/headers/yetto.rb +0 -19
  82. data/templates/app/lib/headers.rb +0 -5
  83. data/templates/app/lib/path_parameter/settings_parameters.rb +0 -22
  84. data/templates/app/lib/path_parameter/yetto_parameters.rb +0 -28
  85. data/templates/app/lib/path_parameter.rb +0 -8
  86. data/templates/app/lib/plug_app/http.rb +0 -37
  87. data/templates/app/lib/plug_app/middleware/malformed_request.rb +0 -110
  88. data/templates/app/lib/plug_app/middleware/openapi_validation.rb +0 -83
  89. data/templates/app/lib/plug_app/middleware/tracing_attributes.rb +0 -46
  90. data/templates/app/lib/query_parameter.rb +0 -6
  91. data/templates/app/serializers/error_serializer.rb +0 -16
  92. data/templates/app/services/yetto_service.rb +0 -51
  93. data/templates/app/views/settings/new.json.jbuilder +0 -21
  94. data/templates/compose.yml +0 -5
  95. data/templates/config/initializers/000-oj.rb +0 -6
  96. data/templates/config/initializers/cors.rb +0 -19
  97. data/templates/config/initializers/filter_parameter_logging.rb +0 -25
  98. data/templates/config/initializers/inflections.rb +0 -20
  99. data/templates/config/initializers/lograge.rb +0 -25
  100. data/templates/config/initializers/opentelemetry.rb +0 -32
  101. data/templates/config/initializers/sidekiq.rb +0 -11
  102. data/templates/config/initializers/slack_webhook_logger.rb +0 -17
  103. data/templates/config/sidekiq.yml +0 -20
  104. data/templates/script/ngrok +0 -5
  105. data/templates/test/controllers/settings_controller_test.rb +0 -27
  106. data/templates/test/fixtures/plug_installation_settings/invalid.json +0 -3
  107. data/templates/test/fixtures/plug_installation_settings/valid.json +0 -3
  108. data/templates/test/jobs/update_yetto_job_test.rb +0 -26
  109. data/templates/test/support/api.rb +0 -76
  110. data/templates/test/support/webmocks/slack_webmock.rb +0 -24
  111. data/templates/test/support/webmocks/yetto_webmock.rb +0 -119
  112. data/templates/test/support/webmocks.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fd5c6432d34e4e2eb90d9973085cd3f5c35a2e8782d5f606c1034216c38f2e4
4
- data.tar.gz: 248400d20b246514c39493ae7c7f8431c684094681031f05d366e66e73ad9fb8
3
+ metadata.gz: '06528561509ef978d2df34dc6ae67b75a91d26a67fda79fa97fbdd4dde886ab4'
4
+ data.tar.gz: eb3559c45d3a7bf42221d346a344baaabbe44880dd755c87da5ff8109da11e93
5
5
  SHA512:
6
- metadata.gz: 1838be4d97e454204df1799da18b27f39ab071641e0750836eddd6e9855c9e94545ea790a566aecb73a8b108a9935d835f2b4e056a8f6d5c56321e4a6dd9284b
7
- data.tar.gz: 30e903eefb0ceeee367ca1b07d7cdc07586b4cbc34a2500e54e5c9987c6f11e1412880f81d758cb5f095939ab2114e9c1c3f3f4a2fdb3173de87e7711fe9fd4a
6
+ metadata.gz: 56d6a0b8f9f823cc930230c9d2462d6f0fec6f801487acdbae3add9a63d7508100cf862c48c836e18bdfdcd30f7b261b77726469be194db352cb55ba90fdb119
7
+ data.tar.gz: 1ea2bffff5ee8de27ae0de2a4657775bbad4bdddb82f369787e09ebb3fc9ec541316564e69609eb3fa70e708c9970667816e6f7e57a596fd50f567071c514a3a
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.0
1
+ 3.3.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [v0.8.12] - 16-12-2024
2
+ ## What's Changed
3
+ * Update template generator by @gjtorikian in https://github.com/yettoapp/hephaestus/pull/93
4
+
5
+
6
+ **Full Changelog**: https://github.com/yettoapp/hephaestus/compare/v0.8.11...v0.8.12
1
7
  # [v0.8.11] - 11-12-2024
2
8
  **Full Changelog**: https://github.com/yettoapp/hephaestus/compare/v0.8.10...v0.8.11
3
9
  # [v0.8.10] - 10-12-2024
data/README.md CHANGED
@@ -26,11 +26,13 @@ Where `app` represents the name of the platform you'd like to interact with, lik
26
26
  If you're working on updating/testing this gem locally, you may also try:
27
27
 
28
28
  ```
29
- rm -rf plug-app && DEBUG=1 hephaestus/bin/hephaestus plug-app
29
+ rm -rf plug-app && DEBUG=1 bundle exec bin/hephaestus plug-app
30
30
  ```
31
31
 
32
32
  This way you can wipe the dir and quickly iterate on new changes.
33
33
 
34
+ If you're having trouble connecting to the Internet, you can set `HEPHAESTUS_NO_EXTERNAL=1`.
35
+
34
36
  ## Building upon the base
35
37
 
36
38
  Most of the files which Hephaestus creates for you shouldn't need much modification. The information below is part-informative, part-guidelines on how to extend the generated code for your specific plug.
data/bin/hephaestus CHANGED
@@ -34,24 +34,30 @@ if (str = ARGV.first)
34
34
  end
35
35
  end
36
36
 
37
- puts Rainbow("Checking to see if Hephaestus is the latest and greatest...").green
38
- require "net/http"
39
- begin
40
- Net::HTTP.get(URI("https://www.yetto.app"))
41
- rescue Socket::ResolutionError
42
- puts Rainbow("Unable to check for updates. Are you connected to the internet?").red
43
- exit(1)
37
+ if ENV.fetch("HEPHAESTUS_NO_EXTERNAL", "0") == "1"
38
+ puts Rainbow("Skipping Hephaestus check...").yellow
39
+ else
40
+ puts Rainbow("Checking to see if Hephaestus is the latest and greatest...").green
41
+ require "net/http"
42
+ begin
43
+ Net::HTTP.get(URI("https://www.yetto.app"))
44
+ rescue Socket::ResolutionError
45
+ puts Rainbow("Unable to check for updates. Are you connected to the internet?").red
46
+ puts Rainbow("You can also set `HEPHAESTUS_NO_EXTERNAL=1` to skip this.").red
47
+ exit(1)
48
+ end
44
49
  end
45
50
 
46
- %x(gem outdated).split("\n").each do |line|
47
- if line.include?("hephaestus")
48
- puts Rainbow("There is a new version of Hephaestus available (`#{line}`). Please run 'gem update hephaestus' to update.").red
49
- exit(1)
51
+ if ENV.fetch("HEPHAESTUS_NO_EXTERNAL", "0") != "1"
52
+ %x(gem outdated).split("\n").each do |line|
53
+ if line.include?("hephaestus")
54
+ puts Rainbow("There is a new version of Hephaestus available (`#{line}`). Please run 'gem update hephaestus' to update.").red
55
+ exit(1)
56
+ end
50
57
  end
51
58
  end
52
59
 
53
- require "rails"
54
- require "hephaestus/engine"
60
+ puts Rainbow("Looking good! Proceeding...").blue
55
61
 
56
62
  if ARGV.empty?
57
63
  puts "Please provide a path for the new application"
@@ -79,6 +85,17 @@ if path.split("-").length < 2
79
85
  exit 1
80
86
  end
81
87
 
88
+ ENGINE_ROOT = File.expand_path("..", __dir__)
89
+ ENGINE_PATH = File.expand_path("../lib/hephaestus/engine", __dir__)
90
+ APP_PATH = File.expand_path("../test/dummy/config/application", __dir__)
91
+
92
+ # Set up gems listed in the Gemfile.
93
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
94
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
95
+
96
+ require "rails/all"
97
+ require "hephaestus"
98
+
82
99
  templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
83
100
  Hephaestus::AppGenerator.source_root(templates_root)
84
101
  Hephaestus::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
@@ -88,5 +105,6 @@ ARGV.push("--no-skip-active-job")
88
105
  ARGV.push("--skip-asset-pipeline")
89
106
  ARGV.push("--skip-active-record")
90
107
  ARGV.push("--skip-docker")
108
+ ARGV.push("--skip_bundle")
91
109
 
92
110
  Hephaestus::AppGenerator.start
@@ -17,17 +17,8 @@ module Hephaestus
17
17
  copy_file("hephaestus_gitignore", ".gitignore")
18
18
  end
19
19
 
20
- # it is, apparently, extraordinarly important to keep this as an erb
21
- def gemfile
22
- template("Gemfile.erb", "Gemfile")
23
- end
24
-
25
- def raise_on_delivery_errors
26
- replace_in_file(
27
- "config/environments/development.rb",
28
- "raise_delivery_errors = false",
29
- "raise_delivery_errors = true",
30
- )
20
+ def setup_dev_environment
21
+ copy_file("config/environments/blank.rb", "config/environments/development.rb", force: true)
31
22
  end
32
23
 
33
24
  def copy_setup_scripts
@@ -35,151 +26,48 @@ module Hephaestus
35
26
  Dir.glob("script/**/*").each do |file|
36
27
  next if File.directory?(file)
37
28
 
38
- chmod(file, 0o755)
39
- end
40
- end
41
-
42
- def configure_dev_hosting
43
- config = <<~EOD
44
- # Let dev server run on GitHub Codespaces
45
- config.hosts << /[a-z0-9-]+.githubpreview.dev/
46
-
47
- # Let dev server run on ngrok domains
48
- config.hosts << /[a-z0-9-]+.ngrok.io/
49
- EOD
50
-
51
- configure_environment("development", config)
52
- end
53
-
54
- def setup_asset_host
55
- config = <<~EOD
56
- config.public_file_server.headers = {
57
- "Cache-Control" => "public, max-age=31557600",
58
- }
59
- EOD
60
-
61
- configure_environment("production", config)
62
- end
63
-
64
- def setup_background_worker
65
- config = <<~EOD
66
- # Use a real queuing backend for Active Job (and separate queues per environment).
67
- config.active_job.queue_adapter = :sidekiq
68
- EOD
69
- configure_environment("production", config)
70
- configure_environment("staging", config)
71
- end
72
-
73
- def setup_slack_logger
74
- config = <<~EOD
75
- config.after_initialize do
76
- Rails.logger.broadcast_to(SlackWebhookLogger.logger)
29
+ # Rails adds this
30
+ if file == ".keep"
31
+ remove_file(file)
32
+ next
77
33
  end
78
- EOD
79
- configure_environment("production", config)
80
- configure_environment("staging", config)
81
- configure_environment("test", config)
82
- end
83
34
 
84
- def setup_ssl
85
- ssl = <<~SSL
86
- config.force_ssl = true
87
- config.ssl_options = { hsts: { subdomains: true, preload: true, expires: 1.year } }
88
- SSL
89
-
90
- replace_in_file(
91
- "config/environments/production.rb",
92
- "# config.force_ssl = true",
93
- ssl,
94
- )
35
+ # this is because we might have *.tt templates, which aren't executable,
36
+ # so we gotta re-execute-em all
37
+ chmod(file, 0o755)
38
+ end
95
39
  end
96
40
 
97
41
  def setup_staging_environment
98
- FileUtils.cp(File.join(destination_root, "config/environments/production.rb"), File.join(destination_root, "config/environments/staging.rb"))
42
+ copy_file("config/environments/blank.rb", "config/environments/staging.rb", force: true)
99
43
  end
100
44
 
101
- def replace_gemfile
102
- template("Gemfile.erb", "Gemfile", force: true) do |content|
103
- if development_env?
104
- content.gsub(/gem .hephaestus./) { |s| %(#{s}, path: "#{root_path}") }
105
- else
106
- content
107
- end
108
- end
45
+ def setup_production_environment
46
+ copy_file("config/environments/blank.rb", "config/environments/production.rb", force: true)
109
47
  end
110
48
 
111
- def restore_gemfile
112
- replace_in_file("Gemfile", /gem "hephaestus".+/, "gem \"hephaestus\"")
49
+ def setup_test_environment
50
+ copy_file("config/environments/blank.rb", "config/environments/test.rb", force: true)
113
51
  end
114
52
 
115
53
  def ruby_version
116
54
  create_file(".ruby-version", "#{Hephaestus::RUBY_VERSION}\n")
117
55
  end
118
56
 
119
- def configure_time_formats
120
- replace_in_file("config/application.rb", /# config.time_zone = .*/, "config.time_zone = \"UTC\"")
121
- end
122
-
123
- def create_github_repo(repo_name)
124
- run("gh repo create #{repo_name}", exit_on_failure: false)
125
- end
126
-
127
- def remove_config_comment_lines
128
- config_files = [
129
- "application.rb",
130
- "environment.rb",
131
- "environments/development.rb",
132
- "environments/production.rb",
133
- "environments/test.rb",
134
- ]
135
-
136
- config_files.each do |config_file|
137
- path = Pathname(destination_root).join("config", config_file)
138
- source = Actions::StripCommentsAction.call(path.read)
139
-
140
- path.write(source)
141
- end
142
- end
57
+ def replace_generic_variables
58
+ say(set_color("Replacing generic file names...", :cyan))
143
59
 
144
- def remove_routes_comment_lines
145
- replace_in_file(
146
- "config/routes.rb",
147
- /Rails\.application\.routes\.draw do.*end/m,
148
- "Rails.application.routes.draw do\nend",
149
- )
150
- end
60
+ File.rename(File.join(destination_root, "app", "controllers", "app_controller.rb"), File.join(destination_root, "app", "controllers", "#{plug_name}_controller.rb"))
61
+ File.rename(File.join(destination_root, "app", "services", "app_service.rb"), File.join(destination_root, "app", "services", "#{plug_name}_service.rb"))
62
+ File.rename(File.join(destination_root, "test", "controllers", "app_controller_test.rb"), File.join(destination_root, "test", "controllers", "#{plug_name}_controller_test.rb"))
63
+ File.rename(File.join(destination_root, "test", "support", "webmocks", "app_webmock.rb"), File.join(destination_root, "test", "support", "webmocks", "#{plug_name}_webmock.rb"))
151
64
 
152
- def setup_test_environment
153
- remove_dir("test")
154
- source = File.join(Hephaestus::AppGenerator.source_root, "test")
155
- directory(source, "test")
156
- end
157
-
158
- def replace_generic_variables
159
- say(set_color("Replacing generic variable names...", :cyan))
160
- replace_in_files(destination_root, /App(?!lication)/, short_app_name.capitalize)
161
-
162
- replace_in_files(destination_root, %r{(?<!yetto|sw|plugs\.yetto\.)app(?!lication|/|roximate)}, short_app_name.downcase)
163
- replace_in_file("test/support/api.rb", "/app/", "/#{short_app_name.downcase}/")
164
-
165
- replace_in_files(destination_root, "PlugApp", app_name.underscore.camelcase)
166
- replace_in_files(destination_root, "plug-app", app_name.dasherize)
167
- replace_in_files("#{destination_root}/.github/workflows", "plug-app", app_name.dasherize)
168
- replace_in_files(destination_root, "PLUG_APP", app_name.underscore.upcase)
169
- replace_in_files(destination_root, "plug_app", app_name.underscore)
170
-
171
- # these are erroneously changed
172
- replace_in_file("script/server", "/usr/src/#{short_app_name.downcase}", "/usr/src/app")
173
- replace_in_file("vendor/fly/fly-production.toml", "#{short_app_name.downcase} = ", "app = ")
174
- replace_in_file("vendor/fly/fly-staging.toml", "#{short_app_name.downcase} = ", "app =")
65
+ replace_in_file(File.join("lib", "schemas", "api", "2023-03-06", "openapi.json"), %r{app/paths.json}, "#{plug_name}/paths.json")
66
+ File.rename(File.join(destination_root, "lib", "schemas", "api", "2023-03-06", "paths", "app.json"), File.join(destination_root, "lib", "schemas", "api", "2023-03-06", "paths", "#{plug_name}.json"))
175
67
  end
176
68
 
177
69
  private
178
70
 
179
- def short_app_name
180
- app_name.split("_").last
181
- end
182
-
183
71
  def root_path
184
72
  @root_path ||= Pathname(__dir__).join("..", "..").expand_path
185
73
  end
@@ -187,15 +75,5 @@ module Hephaestus
187
75
  def development_env?
188
76
  root_path.join("hephaestus.gemspec").exist?
189
77
  end
190
-
191
- def raise_on_missing_translations_in(environment)
192
- config = "config.i18n.raise_on_missing_translations = true"
193
-
194
- uncomment_lines("config/environments/#{environment}.rb", config)
195
- end
196
-
197
- def heroku_adapter
198
- @heroku_adapter ||= Adapters::Heroku.new(self)
199
- end
200
78
  end
201
79
  end
@@ -0,0 +1,33 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ module Hephaestus
5
+ module AppName
6
+ # like, `plug-slack`
7
+ def app_name
8
+ send(:original_app_name)
9
+ rescue NoMethodError # we're in the context of Rails, so we can't call the generator method
10
+ "plug-#{Rails.application.class.module_parent.name.underscore[5..-1]}"
11
+ end
12
+
13
+ # like, `slack`
14
+ def plug_name
15
+ app_name.split("-", 2).last
16
+ end
17
+
18
+ # like, `Slack`, or `html_proofer => HtmlProofer`
19
+ def capital_plug_name
20
+ plug_name.camelcase
21
+ end
22
+
23
+ # like, `SLACK`
24
+ def upcase_plug_name
25
+ plug_name.upcase
26
+ end
27
+
28
+ # like, `slack`, or `HTMLProofer => html_proofer``
29
+ def underscore_plug_name
30
+ plug_name.underscore
31
+ end
32
+ end
33
+ end
@@ -5,9 +5,11 @@ require "rails/generators"
5
5
  require "rails/generators/rails/app/app_generator"
6
6
  require "tempfile"
7
7
 
8
+ require "hephaestus/app_name"
8
9
  module Hephaestus
9
10
  class AppGenerator < Rails::Generators::AppGenerator
10
11
  include ExitOnFailure
12
+ include Hephaestus::AppName
11
13
 
12
14
  hide!
13
15
 
@@ -24,14 +26,14 @@ module Hephaestus
24
26
  desc: "Show this help message and quit"
25
27
 
26
28
  def finish_template
27
- invoke(:hephaestus_customization)
28
- super
29
+ invoke(:hephaestus_initialize)
30
+ # super
29
31
  end
30
32
 
31
- def hephaestus_customization
33
+ def hephaestus_initialize
32
34
  say(set_color("Invoking Hephaestus customizations...", :cyan))
33
35
 
34
- run("rails app:update:bin")
36
+ invoke(:init_git)
35
37
  invoke(:customize_gemfile)
36
38
 
37
39
  invoke(:copy_github_actions)
@@ -41,20 +43,25 @@ module Hephaestus
41
43
  invoke(:setup_production_environment)
42
44
  invoke(:setup_staging_environment)
43
45
  invoke(:setup_test_environment)
44
- invoke(:setup_shared_environment_logic)
45
46
 
46
47
  invoke(:configure_app)
47
- invoke(:create_github_repo)
48
+ invoke(:leftovers)
49
+ end
50
+
51
+ def init_git
52
+ run("git remote add origin https://github.com/yettoapp/#{app_name}.git")
53
+ run("git branch -m production")
48
54
  end
49
55
 
50
56
  def customize_gemfile
51
57
  say(set_color("Customizing Gemfile...", :cyan))
52
58
  build(:replace_gemfile)
53
- capture_stdout do
54
- bundle_command("install")
55
- bundle_command("update")
56
- bundle_command("binstub foreman")
57
- bundle_command("lock --add-platform x86_64-linux")
59
+ unless ENV.fetch("HEPHAESTUS_NO_EXTERNAL", "0") == "1"
60
+ capture_stdout do
61
+ bundle_command("install")
62
+ bundle_command("update")
63
+ bundle_command("lock --add-platform x86_64-linux")
64
+ end
58
65
  end
59
66
  end
60
67
 
@@ -62,7 +69,7 @@ module Hephaestus
62
69
  say(set_color("Copying GitHub Actions...", :cyan))
63
70
 
64
71
  capture_stdout do
65
- directory(Hephaestus.source_path(".github"), ".github")
72
+ directory(Hephaestus.source_path(".github"), ".github", force: true)
66
73
  end
67
74
  end
68
75
 
@@ -76,61 +83,66 @@ module Hephaestus
76
83
 
77
84
  def setup_development_environment
78
85
  say(set_color("Setting up the development environment...", :cyan))
86
+ build(:setup_dev_environment)
79
87
  capture_stdout do
80
- build(:raise_on_delivery_errors)
81
- build(:configure_dev_hosting)
82
88
  build(:copy_setup_scripts)
83
89
  end
84
90
  end
85
91
 
86
- def setup_production_environment
87
- say(set_color("Setting up the production environment...", :cyan))
92
+ def setup_staging_environment
93
+ say(set_color("Setting up the staging environment...", :cyan))
94
+ build(:setup_staging_environment)
88
95
  capture_stdout do
89
- build(:setup_asset_host)
90
- build(:setup_ssl)
91
96
  end
92
97
  end
93
98
 
94
- def setup_staging_environment
95
- say(set_color("Setting up the staging environment...", :cyan))
99
+ def setup_production_environment
100
+ say(set_color("Setting up the production environment...", :cyan))
101
+ build(:setup_production_environment)
96
102
  capture_stdout do
97
- build(:setup_staging_environment)
98
103
  end
99
104
  end
100
105
 
101
106
  def setup_test_environment
102
107
  say(set_color("Setting up the test environment...", :cyan))
103
- capture_stdout do
104
- build(:setup_test_environment)
105
- end
108
+ build(:setup_test_environment)
106
109
  end
107
110
 
108
- def setup_shared_environment_logic
111
+ def configure_app
112
+ say(set_color("Configuring app...", :cyan))
113
+
109
114
  capture_stdout do
110
- build(:setup_background_worker)
111
- build(:setup_slack_logger)
115
+ remove_dir("bin")
116
+ remove_dir("app/helpers")
117
+ remove_dir("app/models")
118
+ remove_dir("app/views/layouts")
119
+ remove_dir("lib/assets")
120
+ remove_file("lib/tasks/.keep")
112
121
  end
113
- end
114
122
 
115
- def configure_app
116
- say(set_color("Configuring app...", :cyan))
123
+ # This must be here, rather than a generator, because generators are run in a Rails environment,
124
+ # and the bootup process requires the fake PEM key file to be present.
125
+ # we do this to specify the template source, otherwise the generator wants to use its own `test` dir
126
+ source = File.join(Hephaestus::AppGenerator.source_root, "test")
127
+ directory(source, "test", force: true)
117
128
 
118
- remove_dir("app/assets")
119
- remove_dir("app/helpers")
120
- remove_dir("app/models")
121
- remove_dir("app/views/layouts")
122
- remove_dir("lib/assets")
123
- remove_dir("lib/tasks/.keep")
124
- remove_dir("test/helpers")
125
- remove_dir("test/channels")
126
- remove_dir("test/models")
129
+ # This must be here, rather than a generator, because generators are run in a Rails environment,
130
+ # and the OpenAPI middleware, which is loaded when the app boots, requires the schema files to be present.
131
+ capture_stdout do
132
+ directory("lib/schemas/api/2023-03-06", "lib/schemas/api/2023-03-06")
133
+ end
127
134
 
128
- build(:configure_time_formats)
135
+ # This is h
136
+ # we do this to specify the template source, otherwise the generator wants to use Rails own `bin` dir
137
+ source = File.join(Hephaestus::Engine.root, "templates", "bin")
138
+ directory(source, "bin", force: true)
129
139
 
130
- bundle_command("binstubs bundler")
140
+ say(set_color("\n*** All these upcoming `HEAD` errors are okay to ignore! ***\n", :cyan))
131
141
 
132
142
  capture_stdout do
133
143
  generate("hephaestus:core")
144
+
145
+ generate("hephaestus:db")
134
146
  generate("hephaestus:deployment")
135
147
  generate("hephaestus:lib")
136
148
 
@@ -139,16 +151,10 @@ module Hephaestus
139
151
  end
140
152
  end
141
153
 
142
- def create_github_repo
143
- if !options[:skip_git] && options[:github]
144
- say(set_color("Creating repository via `gh repo`...", :cyan))
145
- build(:create_github_repo, options[:github])
146
- end
147
- end
148
-
149
- # NOTE: this function name is important as it overrides
150
- # a Rails function of the same name (that function performs work
151
- # that we don't want to do)
154
+ # NOTE: this function name is important as it matches
155
+ # a Rails function of the same name (that performs work
156
+ # that we don't want to do). Think of this as the final step in the process
157
+ # started by `finish_template`.
152
158
  def leftovers
153
159
  build(:replace_generic_variables)
154
160
 
@@ -156,20 +162,22 @@ module Hephaestus
156
162
  capture_stdout do
157
163
  generate("hephaestus:license")
158
164
  end
165
+
159
166
  say(set_color("Generating `hephaestus:rubocop`...", :cyan))
160
167
  capture_stdout do
161
168
  generate("hephaestus:rubocop")
162
169
  end
163
- say(set_color("Generating `hephaestus:sorbet`...", :cyan))
164
- capture_stdout do
165
- generate("hephaestus:sorbet")
166
- end
170
+
171
+ # say(set_color("Generating `hephaestus:sorbet`...", :cyan))
172
+ # capture_stdout do
173
+ # generate("hephaestus:sorbet")
174
+ # end
175
+
167
176
  say(set_color("Creating first commit...", :cyan))
168
177
  capture_stdout do
169
178
  invoke(:commit)
170
179
  end
171
180
 
172
- build(:restore_gemfile)
173
181
  invoke(:outro)
174
182
  end
175
183
 
@@ -195,7 +203,7 @@ module Hephaestus
195
203
 
196
204
  Store this in 1Password too; you don't need the .env file for staging/production.
197
205
 
198
- For `SIGNING_SECRET` and `YETTO_PLUG_ID`, you'll need to generate those values yourself.
206
+ For `YETTO_SIGNING_SECRET` and `YETTO_PLUG_ID`, you'll need to generate those values yourself.
199
207
 
200
208
  Then, try running `bin/rails c` to ensure that everything was set up correctly.
201
209
  Running `rake test` is also a good idea.
@@ -232,22 +240,12 @@ module Hephaestus
232
240
  end
233
241
 
234
242
  private def capture_stdout
235
- # stream = "stdout"
236
- # captured_stream = Tempfile.new(stream)
237
- # stream_io = eval("$#{stream}", binding, __FILE__, __LINE__)
238
- # origin_stream = stream_io.dup
239
- # stream_io.reopen(captured_stream)
240
-
243
+ out = StringIO.new
244
+ $stdout = out
241
245
  yield
242
-
243
- # stream_io.rewind
244
- # captured_stream.read
245
-
246
- # unless captured_stream.nil?
247
- # captured_stream.close
248
- # captured_stream.unlink
249
- # end
250
- # stream_io.reopen(origin_stream) unless stream_io.nil?
246
+ out.string
247
+ ensure
248
+ $stdout = STDOUT
251
249
  end
252
250
  end
253
251
  end