socialforge/lib/tasks/wechat.rake

33 lines
846 B
Ruby
Raw Normal View History

2016-07-17 00:49:35 +08:00
#coding=utf-8
#
require 'uglifier'
2016-07-17 00:49:35 +08:00
def compress(srcs, outfile)
wechat_path = File.join(Rails.root, "public", "javascripts", "wechat")
out_buffer = ''
srcs.each do |src|
Dir.glob("#{wechat_path}/#{src}").each do |path|
puts "assets #{path}"
out_buffer = out_buffer + "\n//#{File.basename(path)}\n" + Uglifier.compile(File.read(path))
end
end
File.open(File.join(wechat_path, "build/#{outfile}"), 'w+') {|f| f.write(out_buffer)}
end
namespace :wechat do
desc "assets javascript file"
task :assets => :environment do
srcs = Rails.application.config.wechat_srcs
compress(srcs, 'app.min.js')
end
desc "minify angularjs"
task :minify => :environment do
srcs = ['../jquery-1.3.2.js','angular.js', 'angular-route.js', 'angular-sanitize.min.js']
compress(srcs, 'angular.all.min.js')
end
end