这个脚本是用来搭建开发环境的,监测目录下文件变动,然后相应地将".coffee"和".slim"编译成 html 和 js 文件。代码写得比较糟糕,求助坛子里的大虾指导
require 'fssm'
FILE_PATH = '/home/miao/tmp'
def compile_coffee(path)
puts "coffee -c #{path}"
`coffee -c #{path}`
end
def compile_slim(path)
puts "slimrb -p #{path.sub(/\.slim$/,'.html')}"
`slimrb -p #{path} #{path.sub(/\.slim$/,'.html')}`
end
coffee_monitor = FSSM::Monitor.new
slim_monitor = FSSM::Monitor.new
coffee_monitor.path FILE_PATH,'**/*.coffee' do
update {|base, relative| compile_coffee "#{base}/#{relative}"}
delete {|base, relative| system "rm #{base}/#{relative}".sub(/\.coffee$/,'.js')}
create {|base, relative| compile_coffee "#{base}/#{relative}"}
end
slim_monitor.path FILE_PATH,'**/*.slim' do
update {|base, relative| compile_slim "#{base}/#{relative}"}
delete {|base, relative| system "rm #{base}/#{relative}".sub(/\.slim$/,'.html')}
create {|base, relative| compile_slim "#{base}/#{relative}"}
end
slim_thread = Thread.new {slim_monitor.run}
coffee_thread = Thread.new {coffee_monitor.run}
slim_thread.join
coffee_thread.join