forked from wise9/enchant.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
86 lines (73 loc) · 2.68 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
# 'rake' コマンドを実行することで、dev/enchant.dev.js から、
# コメント翻訳ファイル enchant.js, enchant.ja.js を生成し、また
# minified ファイル enchant.min.js を生成します。
#
# rake docs
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'net/http'
RELEASES = ['enchant.js', 'enchant.min.js', 'doc/index.html', 'sound.swf']
CLEAN << 'enchant.js' << 'enchant.ja.js' << 'enchant.min.js' << 'doc/index.html'
SOURCE = File.read('dev/enchant.js')
VER = SOURCE[/enchant\.js\s+(v\d+\.\d+\.\d+)/, 1]
Copyright = <<EOS
/*
enchant.js #{VER}
Copyright (c) Ubiquitous Entertainment Inc.
Dual licensed under the MIT or GPL Version 3 licenses
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl-3.0.html
*/
EOS
task :default => [:lang, :minify]
task :create => RELEASES
task :bind do
p ARGV.pop
end
task :lang do |t|
Dir.glob('./dev/**/*.js') { |file|
p file
source = File.read(file)
dest_en = file.gsub(/\/dev\//, '/')
dest_ja = file.gsub(/\/dev\//, '/ja/')
File.open(dest_en, 'w'){ |f|
f << source.gsub(/[\t ]*\[lang\:en\]\n(.*?)[\t ]*\[\/lang\]\n/m, "\\1").gsub(/[\t ]*\[lang\:ja\]\n(.*?)[\t ]*\[\/lang\]\n/m, "")
}
File.open(dest_ja, 'w'){ |f|
f << source.gsub(/[\t ]*\[lang\:en\]\n(.*?)[\t ]*\[\/lang\]\n/m, "").gsub(/[\t ]*\[lang\:ja\]\n(.*?)[\t ]*\[\/lang\]\n/m, "\\1")
}
print "source: #{file}\n"
print "generated: #{dest_en}\n"
print "generated: #{dest_ja}\n"
}
end
task :test do |t|
Dir.glob('./examples/**/index.html') {|example|
res = `phantomjs test-phantomjs.js #{example} | grep Error`
print res
}
end
task :minify => ['enchant.min.js']
file 'enchant.min.js' => ['enchant.js'] do |t|
print "generated: #{t.name} ..";
File.open(t.name, 'w') {|f|
uri = URI.parse('http://closure-compiler.appspot.com/compile')
req = Net::HTTP::Post.new(uri.request_uri)
req.set_form_data({
'js_code' => SOURCE,
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
'output_format' => 'text',
'output_info' => 'compiled_code'
})
f << Net::HTTP.start(uri.host, uri.port) {|http| Copyright + http.request(req).body }
}
print "done\n"
end
task :doc => ['doc/ja/index.html','doc/en/index.html'] do |t|
sh 'java -jar jsdoc-toolkit/jsrun.jar jsdoc-toolkit/app/run.js ja/enchant.js ja/plugins/*.js -t=doc/template -d=doc/ja'
sh 'java -jar jsdoc-toolkit/jsrun.jar jsdoc-toolkit/app/run.js enchant.js plugins/*.js -t=doc/template -d=doc/en'
end
file 'sound.swf' do |t|
sh 'mxmlc sound.as'
end