Class: Hephaestus::AppGenerator

Inherits:
Rails::Generators::AppGenerator
  • Object
show all
Includes:
ExitOnFailure
Defined in:
lib/hephaestus/generators/app_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExitOnFailure

#bundle_command

Class Method Details



219
220
221
# File 'lib/hephaestus/generators/app_generator.rb', line 219

def banner
  "hephaestus #{arguments.map(&:usage).join(" ")} [options]"
end

Instance Method Details

#commitObject



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_appObject



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_actionsObject



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_settingsObject



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_repoObject



142
143
144
145
146
147
# File 'lib/hephaestus/generators/app_generator.rb', line 142

def create_github_repo
  if !options[:skip_git] && options[:github]
    say(set_color("Creating repository via `gh repo`...", :cyan))
    build(:create_github_repo, options[:github])
  end
end

#customize_gemfileObject



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_templateObject



26
27
28
29
# File 'lib/hephaestus/generators/app_generator.rb', line 26

def finish_template
  invoke(:hephaestus_customization)
  super
end

#hephaestus_customizationObject



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

#leftoversObject

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

#outroObject



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_environmentObject



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_environmentObject



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_logicObject



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_environmentObject



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_environmentObject



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