Makefile can be written Ruby is installed
Makefile that can be written in Ruby
ruby 2.7.1p83
Hello Rakefile!
First, create a suitable working folder.
Here, create it with the folder name rakefile-sample
.
Create a Rakefile there and write as follows
Rakefile
task :first_task do
puts 'Hello Rakefile!'
end
Run
rakefile-sample $ rake first_task
Hello Rakefile!
Rakefile
task :run_sh do
sh %{echo Hello Rakefile sh!}
end
Run
rakefile-sample $ rake run_sh
echo Hello Rakefile sh!
Hello Rakefile sh!
Rakefile
task :task1 do
puts 'task1'
end
task :task2 do
puts 'task2'
end
# task1,Execute task3 after task2
task :task3 => [:task1, :task2] do
puts 'task3'
end
Run
rakefile-sample $ rake task3
task1
task2
task3
If file is used instead of task, it will be executed only when the target file (Gemfile in this case) does not exist.
Rakefile
file 'Gemfile' do
f = File.open('Gemfile', 'w')
f.puts("source 'https://rubygems.org'")
f.puts("gem 'rails', '~>5'")
puts 'Gemfile created'
end
Execute (correctly not executed the second time)
rakefile-sample $ rake Gemfile
Gemfile created
rakefile-sample $ rake Gemfile
rakefile-sample $
library rake Summary of basic usage of Rake How to write a File in Ruby [For beginners]
Recommended Posts