From 7c3a2891037e4a1c1298065a77d8b0224a578a80 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Thu, 26 Apr 2018 14:34:01 +0800 Subject: [PATCH] Add bootstrapping rake tasks (bs:init & bs:reset) --- .rubocop.yml | 9 +++++++++ Rakefile | 2 +- lib/tasks/bootstrap.rake | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/bootstrap.rake diff --git a/.rubocop.yml b/.rubocop.yml index 4420a6b76..c33b2835f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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" diff --git a/Rakefile b/Rakefile index 9e4caa9ae..e633ef71c 100755 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/lib/tasks/bootstrap.rake b/lib/tasks/bootstrap.rake new file mode 100644 index 000000000..7b3f7df87 --- /dev/null +++ b/lib/tasks/bootstrap.rake @@ -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