Skip to content

Commit

Permalink
[#473] Optimize generating flow
Browse files Browse the repository at this point in the history
  • Loading branch information
sanG-github committed Nov 13, 2023
1 parent a90ba94 commit 46ea2d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .template/addons/openapi/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
copy_file '.spectral.yml'
copy_file 'public/openapi.html'

if yes?(install_addon_prompt('Mock Server'))
if @install_mock_server
@install_mock_server = true
copy_file 'fly.toml'
copy_file 'Dockerfile.mock'
Expand Down
35 changes: 21 additions & 14 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,10 @@ def apply_template!(template_root)
DEFAULT_ADDONS.each_key do |addon|
apply ".template/addons/#{addon}/template.rb"
end

post_default_addons_install

# Add-ons - [Optional]
if yes?(install_addon_prompt('Github Action and Wiki'))
@install_github_action = true
apply '.template/addons/github/template.rb'
end
if API_VARIANT || yes?(install_addon_prompt('OpenAPI'))
@install_openapi = true
apply '.template/addons/openapi/template.rb'
end
apply '.template/addons/semaphore/template.rb' if yes?(install_addon_prompt('SemaphoreCI'))
apply '.template/addons/nginx/template.rb' if yes?(install_addon_prompt('Nginx'))
apply '.template/addons/phrase/template.rb' if yes?(install_addon_prompt('Phrase'))
apply '.template/addons/devise/template.rb' if yes?(install_addon_prompt('Devise'))
ask_for_optional_addons
apply_optional_addons

# Variants
apply '.template/variants/api/template.rb' if API_VARIANT
Expand All @@ -91,6 +79,25 @@ def apply_template!(template_root)
apply '.template/hooks/before_complete/report.rb'
end

def ask_for_optional_addons
@install_github_action = true if yes?(install_addon_prompt('Github Action and Wiki'))
@install_openapi = true if API_VARIANT || yes?(install_addon_prompt('OpenAPI'))
@install_mock_server if @install_openapi && yes?(install_addon_prompt('Mock Server'))
@install_semaphore = true if yes?(install_addon_prompt('SemaphoreCI'))
@install_nginx = true if yes?(install_addon_prompt('Nginx'))
@install_phrase = true if yes?(install_addon_prompt('Phrase'))
@install_devise = true if yes?(install_addon_prompt('Devise'))
end

def apply_optional_addons
apply '.template/addons/github/template.rb' if @install_github_action
apply '.template/addons/openapi/template.rb' if @install_openapi
apply '.template/addons/semaphore/template.rb' if @install_semaphore
apply '.template/addons/nginx/template.rb' if @install_nginx
apply '.template/addons/phrase/template.rb' if @install_phrase
apply '.template/addons/devise/template.rb' if @install_devise
end

# Set Thor::Actions source path for looking up the files
def source_paths
@source_paths
Expand Down

0 comments on commit 46ea2d2

Please sign in to comment.