-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
127 lines (105 loc) · 3.78 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
require 'pathname'
require File.join(File.dirname(__FILE__), 'lib', 'tasks', 'rakefiles', 'support')
include LoomTasks
def available_tasks_dir()
File.join(File.dirname(__FILE__), 'lib', 'tasks')
end
def installed_tasks_dir()
File.join(Dir.home, '.loom', 'tasks')
end
def installed_rakefiles_dir()
File.join(installed_tasks_dir, 'rakefiles')
end
def installed_templates_dir()
File.join(installed_tasks_dir, 'templates')
end
task :default => :list_targets
task :list_targets do |t, args|
a = "loomtasks v#{VERSION} Rakefile"
b = "running on Ruby #{RUBY_VERSION}"
puts "#{a} #{b}"
system("rake -T")
end
desc [
"installs rake task files for Loom",
"files will be installed to #{installed_tasks_dir}"
].join("\n")
task :install do |t, args|
Dir.mkdir(installed_tasks_dir) unless Dir.exists?(installed_tasks_dir)
Dir.mkdir(installed_rakefiles_dir) unless Dir.exists?(installed_rakefiles_dir)
Dir.mkdir(installed_templates_dir) unless Dir.exists?(installed_templates_dir)
FileUtils.cp_r(Dir.glob(File.join('lib', 'tasks', '*.rake')), installed_tasks_dir)
FileUtils.cp_r(Dir.glob(File.join('lib', 'tasks', 'rakefiles', '*.rake')), installed_rakefiles_dir)
FileUtils.cp_r(Dir.glob(File.join('lib', 'tasks', 'rakefiles', '*.rb')), installed_rakefiles_dir)
FileUtils.cp_r(Dir.glob(File.join('lib', 'tasks', 'templates', '*')), installed_templates_dir)
puts "[#{t.name}] task completed, tasks installed to #{installed_tasks_dir}"
end
desc [
"shows usage and project info, optionally for a specific command",
"usage: rake help",
" or: rake help <command>",
].join("\n")
task :help do |t, args|
# avoid rake errors about undefined tasks; we want to pull args ourselves
ARGV.each do |a|
task a.to_sym do ; end
Rake::Task[a.to_sym].clear
end
cmd = ARGV.fetch(1, nil)
if (cmd)
system("rake -D #{cmd}")
else
system("rake -D")
puts "Log bugs to: https://github.com/pixeldroid/loomtasks/issues"
puts "Project home page: https://github.com/pixeldroid/loomtasks"
puts ''
puts "Please see the README for additional details."
end
end
desc [
"reports loomtasks version (v#{VERSION})",
].join("\n")
task :version do |t, args|
puts "loomtasks v#{VERSION}"
end
namespace :list do
desc [
"lists loomtasks files available to install",
"files from this project are in #{available_tasks_dir}"
].join("\n")
task :available do |t, args|
if Dir.exists?(available_tasks_dir)
puts("files available in #{available_tasks_dir}:")
project_root = Pathname.new(available_tasks_dir)
Dir.glob(File.join("#{available_tasks_dir}", '**', '*')).reject { |f| File.directory?(f) }.each do |f|
puts(Pathname.new(f).relative_path_from(project_root).to_s)
end
else
puts "[#{t.name}] no files are available at #{available_tasks_dir}"
end
end
desc [
"lists currently installed task files",
"installed task files are in #{installed_tasks_dir}"
].join("\n")
task :installed do |t, args|
if Dir.exists?(installed_tasks_dir)
puts("files installed in #{installed_tasks_dir}:")
project_root = Pathname.new(installed_tasks_dir)
Dir.glob(File.join("#{installed_tasks_dir}", '**', '*')).reject { |f| File.directory?(f) }.each do |f|
puts(Pathname.new(f).relative_path_from(project_root).to_s)
end
else
puts "[#{t.name}] no files are installed at #{installed_tasks_dir}"
end
end
end
desc [
"removes the tasks folder from the Loom home directory",
"the task folder is #{installed_tasks_dir}",
"the entire tasks folder will be removed, so use with caution if you added anything in there",
].join("\n")
task :uninstall do |t, args|
FileUtils.rm_r(installed_tasks_dir) if Dir.exists?(installed_tasks_dir)
puts "[#{t.name}] task completed, #{installed_tasks_dir} was removed"
end