bir gem’dir. • Komut satırı ortamında her projede kullanılabilir. • Domain Specific Language (DSL) için en iyi örnektir. • En güncel sürümü için `gem install rake` yeterlidir.
limitli • macOS ile birlikte `ruby` geldiği için `rake` de built-in, ek bir araca ihtiyaç yok! • Local (folder bazında) ya da Global (tüm sistem bazında) çalışan Rakefile tanımlamak mümkün • Çünkü ruby ❤
FOO is not set" unless ENV['FOO'] end desc "say hello world" task :hello_world => [:check_env] do puts "hello world with FOO: #{ENV['FOO']}" end $ rake -T rake hello_world # say hello world $ rake hello_world environment variable FOO is not set $ FOO=1 rake hello_world hello world with FOO: 1
here end file "/path/to/output" => ["/path/to/input1", "/path/to/input2"] do |t| # your code here end file "merged.txt" => ["file1", "file2"] do |t| sh "cat #{t.prerequisites.join(' ')} > #{t.name}" # cat file1 file2 > merged.txt end $ rake merged.txt
puts "create folder called: #{t.prerequisites.first}/ unless it exists" puts "name of task: #{t.name}" puts "prerequisite(s) of task: #{t.prerequisites.first}" end $ rake merged.txt mkdir -p merged_files create folder called: merged_files/ unless it exists name of task: merged.txt prerequisite(s) of task: merged_files
"All Copies Complete" end task :copy_src do puts "copy src task" end task :copy_doc do puts "copy doc task" end task :copy_bin do puts "copy bin task" end $ rake copy_files copy bin task copy src task copy doc task All Copies Complete
end task :check_virtualenv do abort "Please activate your virtual environment" unless ENV['VIRTUAL_ENV'] end task :check_django_env do abort "Please define DJANGO_ENV variable" unless ENV['DJANGO_ENV'] end task :check_settings => [:check_virtualenv, :check_django_env] do |t| puts "task #{t.name} called ..." end task :check_virtualenv do abort "Please activate your virtual environment" unless ENV['VIRTUAL_ENV'] end task :check_django_env do abort "Please define DJANGO_ENV variable" unless ENV['DJANGO_ENV'] end
[:step1, :step2] do Rake ::Task["step1"].invoke Rake ::Task["step1"].invoke Rake ::Task["step2"].invoke Rake ::Task["step2"].invoke end task :step1 do puts "step1 is called" end task :step2 do puts "step2 is called" end $ rake step1 is called step2 is called
[:step1, :step2] do Rake ::Task["step1"].execute Rake ::Task["step1"].execute Rake ::Task["step2"].execute Rake ::Task["step2"].execute end task :step1 do puts "step1 is called" end task :step2 do puts "step2 is called" end $ rake step1 is called step2 is called step1 is called step1 is called step2 is called step2 is called https://medium.com/@sampatbadhe/rake-task-invoke-or-execute-419cd689c3bd
[:db_file] do |_, args| psql = %x{ command -v psql } if psql.empty? fn = "project/db/ #{args.db_file}.sqlite3" if File.exists?(fn) puts "Deleting: #{fn}" rm(fn) else puts " #{fn} not exists ..." end else puts "Dropping and re-creating PostgreSQL database" system "dropdb #{POSTGRES_DB_NAME} --if-exists" system "createdb #{POSTGRES_DB_NAME}" end end task :delete_development_db do Rake ::Task["db:delete_db_file"].invoke('development') end end
do rm_rf %w(build dist) rm_rf Dir.glob("*.egg-info") puts "Build files are removed ..." end desc "Install package for local development purpose" task :install => [:build] do system "pip install -e ." end desc "Build package" task :build => [:clean] do system "python setup.py sdist bdist_wheel" end namespace :upload do desc "Upload package to main distro (release)" task :main => [:build] do puts "Uploading package to MAIN distro ..." system "twine upload --repository pypi dist /*" end desc "Upload package to test distro" task :test => [:build] do puts "Uploading package to TEST distro ..." system "twine upload --repository testpypi dist /*" end end AVAILABLE_REVISIONS = ["major", "minor", "patch"] desc "Bump version" task :bump, [:revision] do |t, args| args.with_defaults(revision: "patch") abort "Please provide valid revision: #{AVAILABLE_REVISIONS.join(',')}" unless AVAILABLE_REVISIONS.include?(args.revision) system "bumpversion #{args.revision}" end https://github.com/vbyazilim/django-vb-baseapp