lib/yamg/cli.rb in yamg-0.0.9 vs lib/yamg/cli.rb in yamg-0.3.0
- old
+ new
@@ -1,79 +1,98 @@
module YAMG
# Command line interface
class CLI
- attr_accessor :works
+ attr_accessor :works, :scope
def initialize(argv)
puts
puts Rainbow(' Y A M G').red
puts
-
+ if argv.join =~ /debug/
+ YAMG.debug = true
+ puts Rainbow('!!! DEBUG !!!').red
+ argv.delete('debug')
+ end
return YAMG.init if argv.join =~ /init/
YAMG.load_config # (argv)
@works = YAMG.config['compile']
+ @scope = argv.empty? ? nil : argv.join
end
def setup_for(opts)
case opts
- when Hash then opts
+ when Hash then { 'path' => './export/' }.merge(opts)
when String then { 'path' => opts }
- when TrueClass then { 'path' => './media' }
+ when TrueClass then { 'path' => './export/' }
else fail
end
end
+ def home_for(asset, setup)
+ path = setup['path']
+ FileUtils.mkdir_p path unless File.exist?(path)
+ File.join(path, asset)
+ end
+
+ def compile_media(i, size, setup)
+ end
+
def compile_icon(i, size, setup)
folder = setup['icon'] || YAMG.config['icon']['path']
- round = setup['rounded'] || YAMG.config['icon']['rounded']
- icon = Icon.new(folder, size, setup).image
- to = File.join(setup['path'], i)
- YAMG.write_out(icon, to)
- # puts Rainbow("Icon #{size}px #{i} #{setup['path']}").black
- print Rainbow('I').black
+ # Don' use || here, we are after false
+ round = setup['rounded']
+ round = YAMG.config['icon']['rounded'] if round.nil?
+ Icon.new(folder, size, round).image(home_for(i, setup))
+ print Rainbow(round ? '(i)' : '[i]').black
+ YAMG.info("Icon #{size}px -> #{setup['path']}#{i} ", :black)
end
def compile_splash(s, size, setup)
path = setup['splash'] || YAMG.config['splash']['path']
- splash = Splash.new(path, size, YAMG.config['splash']['background']).image
- to = File.join(setup['path'], s)
- YAMG.write_out(splash, to)
- # puts Rainbow("Splash #{size.join('x')}px #{s} -> #{setup['path']}").black
- print Rainbow('S').black
+ background = YAMG.config['splash']['background']
+ Splash.new(path, size, background).image(home_for(s, setup))
+ print Rainbow('{S}').black
+ YAMG.info("Splash #{size.join('x')}px #{setup['path']}#{s}", :black)
end
- def compile_work(scope, opts)
+ def compile_work(template, opts)
setup = setup_for(opts)
- if (task = YAMG::TEMPLATES[scope])
- #Thread.new do # 200% speed up with 8 cores
- task['icons'].each { |i, d| Thread.new { compile_icon(i, d, setup) }}
- return unless task['splash']
- task['splash'].each { |s, d| Thread.new { compile_splash(s, d, setup) }}
- #end
+ if (task = YAMG::TEMPLATES[template])
+ %w(icon splash media).each do |key|
+ next unless (work = task[key])
+ work.each do |i, d|
+ #Thread.new do # 200% speed up with 8 cores
+ send(:"compile_#{key}", i, d, setup)
+ #end
+ end
+ end
else
# puts 'Custom job!'
end
end
- def compile(scope = nil)
- works.select! { |w| w =~ scope } if scope
+ def compile
+ works.select! { |k,_v| k =~ /#{scope}/ } if scope
+ puts Rainbow("Tasks: #{works.keys.join(', ')}").yellow
works.each { |out, opts| compile_work(out, opts) }
- works.select! { |w| w =~ scope } if scope
- puts Rainbow("Working on #{works.keys.join(', ')}").yellow
end
def screenshot
YAMG.config['screenshots'].each do |ss|
- Thread.new { Screenshot.new(ss).work('./media') }
+ Thread.new do
+ Screenshot.new(ss).work('./export')
+ puts Rainbow("[o]SS #{ss[0]} #{ss[1]}").black
+ end
end
end
def work!
time = Time.now
compile
- screenshot
- puts Rainbow(Thread.list.size.to_s + ' jobs').black
+ screenshot if scope.nil? || scope =~ /ss|shot|screen/
+ puts
+ puts Rainbow(Thread.list.size.to_s + ' jobs to go').black
Thread.list.reject { |t| t == Thread.current }.each(&:join)
puts Rainbow('-' * 59).black
puts Rainbow("Done compile #{Time.now - time}").red
end
end