Add bootstrapping rake tasks (bs:init & bs:reset)

This commit is contained in:
Ryan Lue 2018-04-26 14:34:01 +08:00
parent 8d4b4a0152
commit 7c3a289103
3 changed files with 37 additions and 1 deletions

View file

@ -109,6 +109,9 @@ Layout/EmptyLinesAroundModuleBody:
Description: "Keeps track of empty lines around module bodies."
Enabled: false
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented_relative_to_receiver
Style/MultilineBlockChain:
Description: 'Avoid multi-line chains of blocks.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
@ -226,3 +229,9 @@ Lint/AmbiguousBlockAssociation:
Exclude:
- "**/*_spec.rb"
- "**/*_examples.rb"
# Special exceptions
Style/HashSyntax:
Exclude:
- "**/*.rake"

View file

@ -2,6 +2,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('config/application', __dir__)
require_relative 'config/application'
Zammad::Application.load_tasks

27
lib/tasks/bootstrap.rake Normal file
View file

@ -0,0 +1,27 @@
namespace :bs do
desc 'Bootstrap the application'
task :init => %i[db:create db:migrate db:seed] do
run_auto_wizard
end
desc 'Reset the application to its initial state'
task :reset => %i[db:reset] do
flush_cache_and_logs
run_auto_wizard
end
end
APP_CACHE = Dir.glob(Rails.root.join('tmp', 'cache*'))
SERVER_LOG = Rails.root.join('log', Rails.env)
AUTO_WIZARD = { source: Rails.root.join('contrib', 'auto_wizard_test.json'),
destination: Rails.root.join('auto_wizard.json') }.freeze
def flush_cache_and_logs
FileUtils.rm_rf(APP_CACHE)
File.write(SERVER_LOG, '')
end
def run_auto_wizard
FileUtils.ln(AUTO_WIZARD[:source], AUTO_WIZARD[:destination], force: true)
system('rails runner "AutoWizard.setup"')
end