Rake and Task Automation
# Rakefile
require "rake/clean"
CLEAN.include("tmp/**/*")
desc "Say hello"
task :hello, [:name] do |t, args|
name = args[:name] || "World"
puts "Hello, #{name}!"
end
namespace :db do
desc "Run migrations"
task migrate: :environment do
puts "Migrating..."
end
task :environment do
require_relative "config/environment"
end
end
file "build/app.js" => Dir["src/**/*.js"] do |t|
sh "esbuild src/index.js --bundle --outfile=#{t.name}"
end
directory "build"
task build: ["build", "build/app.js"]
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task default: :spec
rake -T # list tasks
rake hello[Ana]
rake db:migrate
rake # default task