Class: Hephaestus::AppGenerator
- Inherits:
-
Rails::Generators::AppGenerator
- Object
- Rails::Generators::AppGenerator
- Hephaestus::AppGenerator
- Includes:
- ExitOnFailure
- Defined in:
- lib/hephaestus/generators/app_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #commit ⇒ Object
- #configure_app ⇒ Object
- #copy_github_actions ⇒ Object
- #copy_vscode_settings ⇒ Object
- #create_github_repo ⇒ Object
- #customize_gemfile ⇒ Object
- #finish_template ⇒ Object
- #hephaestus_customization ⇒ Object
-
#leftovers ⇒ Object
NOTE: this function name is important as it overrides a Rails function of the same name (that function performs work that we donโt want to do).
- #outro ⇒ Object
- #setup_development_environment ⇒ Object
- #setup_production_environment ⇒ Object
- #setup_shared_environment_logic ⇒ Object
- #setup_staging_environment ⇒ Object
- #setup_test_environment ⇒ Object
Methods included from ExitOnFailure
Class Method Details
.banner ⇒ Object
219 220 221 |
# File 'lib/hephaestus/generators/app_generator.rb', line 219 def "hephaestus #{arguments.map(&:usage).join(" ")} [options]" end |
Instance Method Details
#commit ⇒ Object
176 177 178 179 |
# File 'lib/hephaestus/generators/app_generator.rb', line 176 def commit run("git add .") run("git commit -m 'Initial commit'", capture: true) end |
#configure_app ⇒ Object
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 140 |
# File 'lib/hephaestus/generators/app_generator.rb', line 115 def configure_app say(set_color("Configuring app...", :cyan)) remove_dir("app/assets") remove_dir("app/helpers") remove_dir("app/models") remove_dir("app/views/layouts") remove_dir("lib/assets") remove_dir("lib/tasks/.keep") remove_dir("test/helpers") remove_dir("test/channels") remove_dir("test/models") build(:configure_time_formats) bundle_command("binstubs bundler") capture_stdout do generate("hephaestus:core") generate("hephaestus:deployment") generate("hephaestus:lib") # keep this at the end generate("hephaestus:config") end end |
#copy_github_actions ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/hephaestus/generators/app_generator.rb', line 61 def copy_github_actions say(set_color("Copying GitHub Actions...", :cyan)) capture_stdout do directory(Hephaestus.source_path(".github"), ".github") end end |
#copy_vscode_settings ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/hephaestus/generators/app_generator.rb', line 69 def copy_vscode_settings say(set_color("Copying .vscode/...", :cyan)) capture_stdout do directory(Hephaestus.source_path(".vscode"), ".vscode") end end |
#create_github_repo ⇒ Object
142 143 144 145 146 147 |
# File 'lib/hephaestus/generators/app_generator.rb', line 142 def create_github_repo if ![:skip_git] && [:github] say(set_color("Creating repository via `gh repo`...", :cyan)) build(:create_github_repo, [:github]) end end |
#customize_gemfile ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hephaestus/generators/app_generator.rb', line 50 def customize_gemfile say(set_color("Customizing Gemfile...", :cyan)) build(:replace_gemfile) capture_stdout do bundle_command("install") bundle_command("update") bundle_command("binstub foreman") bundle_command("lock --add-platform x86_64-linux") end end |
#finish_template ⇒ Object
26 27 28 29 |
# File 'lib/hephaestus/generators/app_generator.rb', line 26 def finish_template invoke(:hephaestus_customization) super end |
#hephaestus_customization ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hephaestus/generators/app_generator.rb', line 31 def hephaestus_customization say(set_color("Invoking Hephaestus customizations...", :cyan)) run("rails app:update:bin") invoke(:customize_gemfile) invoke(:copy_github_actions) invoke(:copy_vscode_settings) invoke(:setup_development_environment) invoke(:setup_production_environment) invoke(:setup_staging_environment) invoke(:setup_test_environment) invoke(:setup_shared_environment_logic) invoke(:configure_app) invoke(:create_github_repo) end |
#leftovers ⇒ Object
NOTE: this function name is important as it overrides a Rails function of the same name (that function performs work that we donโt want to do)
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/hephaestus/generators/app_generator.rb', line 152 def leftovers build(:replace_generic_variables) say(set_color("Generating `hephaestus:license`...", :cyan)) capture_stdout do generate("hephaestus:license") end say(set_color("Generating `hephaestus:rubocop`...", :cyan)) capture_stdout do generate("hephaestus:rubocop") end say(set_color("Generating `hephaestus:sorbet`...", :cyan)) capture_stdout do generate("hephaestus:sorbet") end say(set_color("Creating first commit...", :cyan)) capture_stdout do invoke(:commit) end build(:restore_gemfile) invoke(:outro) end |
#outro ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/hephaestus/generators/app_generator.rb', line 181 def outro say(<<~OUTPUT) #{set_color("Congratulations!", :green)} You just made a Yetto plug. You'll need to `cd #{ARGV.first}` and run the following commands--I can't do it for you! * `bin/rails credentials:edit --environment development` #{set_color("WAIT!", :red)} After running this command, note that Rails credited a file called development.key in the config/credentials directory. Store this in 1Password, then change the .env file to use this value. Generate keys for staging/production, too: * `bin/rails credentials:edit --environment staging` `bin/rails credentials:edit --environment production` Store this in 1Password too; you don't need the .env file for staging/production. For `SIGNING_SECRET` and `YETTO_PLUG_ID`, you'll need to generate those values yourself. Then, try running `bin/rails c` to ensure that everything was set up correctly. Running `rake test` is also a good idea. #{set_color("Also, after pushing to GitHub:", :yellow)} * Set `settings/branches` to protect `production` * โ Require status checks to pass before merging * ๐๏ธ Status checks that are required: `ruby / test_without_services`, `docker / test-build`, `ruby / brakeman`, `ruby / bundle-audit`. You can only set those ๐ after you've opened the first PR on GitHub. Crazy, I know!! But, doing so is *essential* for automerge to function properly. * In `/settings`: * โ Allow auto-merge * โ Automatically delete head branches OUTPUT end |
#setup_development_environment ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/hephaestus/generators/app_generator.rb', line 77 def setup_development_environment say(set_color("Setting up the development environment...", :cyan)) capture_stdout do build(:raise_on_delivery_errors) build(:configure_dev_hosting) build(:copy_setup_scripts) end end |
#setup_production_environment ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/hephaestus/generators/app_generator.rb', line 86 def setup_production_environment say(set_color("Setting up the production environment...", :cyan)) capture_stdout do build(:setup_asset_host) build(:setup_ssl) end end |
#setup_shared_environment_logic ⇒ Object
108 109 110 111 112 113 |
# File 'lib/hephaestus/generators/app_generator.rb', line 108 def setup_shared_environment_logic capture_stdout do build(:setup_background_worker) build(:setup_slack_logger) end end |
#setup_staging_environment ⇒ Object
94 95 96 97 98 99 |
# File 'lib/hephaestus/generators/app_generator.rb', line 94 def setup_staging_environment say(set_color("Setting up the staging environment...", :cyan)) capture_stdout do build(:setup_staging_environment) end end |
#setup_test_environment ⇒ Object
101 102 103 104 105 106 |
# File 'lib/hephaestus/generators/app_generator.rb', line 101 def setup_test_environment say(set_color("Setting up the test environment...", :cyan)) capture_stdout do build(:setup_test_environment) end end |