/
cli.rb
56 lines (49 loc) · 1.53 KB
/
cli.rb
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
require "thor"
module Rake
class Pipeline
class CLI < Thor
class_option :assetfile, :default => "Assetfile", :aliases => "-c"
default_task :build
desc "build", "Build the project."
method_option :pretend, :type => :boolean, :aliases => "-p"
method_option :clean, :type => :boolean, :aliases => "-C"
def build
if options[:pretend]
project.output_files.each do |file|
say_status :create, relative_path(file)
end
else
options[:clean] ? project.clean : project.cleanup_tmpdir
project.invoke
end
end
desc "clean", "Remove the pipeline's temporary and output files."
method_option :pretend, :type => :boolean, :aliases => "-p"
def clean
if options[:pretend]
project.files_to_clean.each do |file|
say_status :remove, relative_path(file)
end
else
project.clean
end
end
desc "server", "Run the Rake::Pipeline preview server."
def server
require "rake-pipeline/server"
Rake::Pipeline::Server.new.start
end
private
def project
@project ||= Rake::Pipeline::Project.new(options[:assetfile])
end
# @param [FileWrapper|String] path
# @return [String] The path to the file with the current
# directory stripped out.
def relative_path(path)
pathstr = path.respond_to?(:fullpath) ? path.fullpath : path
pathstr.sub(%r|#{Dir.pwd}/|, '')
end
end
end
end