-
Notifications
You must be signed in to change notification settings - Fork 9
/
Rakefile
174 lines (151 loc) · 4.06 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# -*- ruby -*-
text_domain = "mroonga"
translated_languages = [
"ja",
]
mo_files = translated_languages.collect do |language|
"languages/#{text_domain}-#{language}.mo"
end
php_files = Dir.glob("*.php")
release_files = []
release_files += mo_files
release_files += php_files
release_files += ["readme.txt"]
def detect_version
mroonga_php = File.join(__dir__, "mroonga.php")
File.open(mroonga_php) do |input|
input.each_line do |line|
case line.chomp
when /\AVersion: (.+)\z/
return $1
end
end
end
nil
end
version = ENV["VERSION"] || detect_version
pot_file = "languages/#{text_domain}.pot"
file pot_file => php_files do
sh("xgettext",
"--language", "php",
"--keyword=__",
"--output", pot_file,
"--package-name", "Mroonga",
"--package-version", version,
"--msgid-bugs-address",
"https://github.com/mroonga/wordpress-mroonga/issues/new",
*php_files)
end
def newer?(path1, path2)
File.exist?(path1) and
File.exist?(path2) and
File.mtime(path1) > File.mtime(path2)
end
task :force
edit_po_files = []
translated_languages.each do |language|
base_name = "languages/#{text_domain}-#{language}"
po_file = "#{base_name}.po"
edit_po_file = "#{base_name}.edit.po"
timestamp_file = "#{base_name}.timestamp"
edit_po_files << edit_po_file
po_file_is_updated = newer?(po_file, timestamp_file)
po_file_dependencies = [edit_po_file]
edit_po_file_dependencies = [pot_file]
if po_file_is_updated
edit_po_file_dependencies << :force
end
file edit_po_file => edit_po_file_dependencies do
if po_file_is_updated
rm_f(edit_po_file)
end
unless File.exist?(edit_po_file)
if File.exist?(po_file)
cp(po_file, edit_po_file)
else
sh("msginit",
"--input", pot_file,
"--output-file", edit_po_file,
"--locale", language,
"--no-translator")
end
end
sh("msgmerge",
"--output-file", edit_po_file,
"--sort-by-file",
edit_po_file,
pot_file)
end
file po_file => po_file_dependencies do
sh("msgcat",
"--output-file", po_file,
"--no-location",
"--sort-by-file",
edit_po_file)
po_content = File.read(po_file)
File.open(po_file, "w") do |output|
in_header = true
po_content.each_line do |line|
if in_header
case line.chomp
when ""
in_header = false
output.print(line)
when /\A"POT-Creation-Date:/
when /\A"PO-Revision-Date:/
else
output.print(line)
end
else
output.print(line)
end
end
end
touch(timestamp_file)
end
end
rule ".mo" => ".po" do |task|
sh("msgfmt",
"--output-file", task.name,
task.source)
end
desc "Update translation"
task :translate => (edit_po_files + mo_files)
release_repository_path = "../wordpress-mroonga.release"
release_repository_url = "https://plugins.svn.wordpress.org/mroonga"
directory release_repository_path do
sh("svn", "co",
release_repository_url,
release_repository_path)
end
desc "Publish #{version}"
task :publish => [release_repository_path, :translate] do
trunk = File.join(release_repository_path, "trunk")
sh("svn", "up", trunk)
# TODO: Removed files
release_files.each do |file|
dest_file = File.join(trunk, file)
dest_directory = File.dirname(dest_file)
unless File.exist?(dest_directory)
mkdir_p(dest_directory)
sh("svn", "add", dest_directory)
end
dest_file_exist = File.exist?(dest_file)
cp(file, dest_file)
sh("svn", "add", dest_file) unless dest_file_exist
end
sh("svn", "ci",
"--message", "Import #{version}",
trunk)
sh("svn", "cp",
"--message", "#{version} has been released!!!",
"#{release_repository_url}/trunk",
"#{release_repository_url}/tags/#{version}")
end
desc "Tag #{version}"
task :tag do
sh("git", "tag", "-a", version, "-m", "#{version} has been released!!!")
sh("git", "push", "--tags")
end
desc "Release #{version}"
task :release => [:publish, :tag]