-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
61 lines (48 loc) · 1.44 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require "fileutils"
desc "Create the default structure for one day of AOC"
task :scaffold_day, [:day_number] => [:create_example_and_input, :create_shared_file, :create_part_files]
task :make_directory_if_not_there do |t, args|
Dir.mkdir args.day_number unless Dir.exist? args.day_number
end
task :change_to_correct_directory => [:make_directory_if_not_there] do |t, args|
Dir.chdir args.day_number
end
task :create_example_and_input => [:change_to_correct_directory] do
["example", "input"].each do |file|
puts "create\t#{file}"
FileUtils.touch file
end
end
task :create_shared_file => [:change_to_correct_directory] do |t, args|
shared_file_contents = <<~RUBY
# frozen_string_literal: true
require_relative '../common'
require 'pry-rescue'
DAY = "#{args.day_number}"
module Shared
end
RUBY
puts "create\tshared.rb"
File.write("shared.rb", shared_file_contents)
end
task :create_part_files => [:change_to_correct_directory] do
{ "PartA" => "part-a.rb", "PartB" => "part-b.rb" }.each do |klass, file|
contents = <<~RUBY
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative './shared'
class #{klass}
def self.run
input = Common::InputReader.example
end
private
end
if __FILE__ == $0
#{klass}.run
end
RUBY
puts "create\t#{file}"
File.write(file, contents)
FileUtils.chmod 'u+x', file
end
end