forked from php-imagine/Imagine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
188 lines (165 loc) · 5.04 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
require 'date'
require 'nokogiri'
require 'digest/md5'
require 'fileutils'
require 'json'
class String
def underscore
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end
def unindent
gsub(/^#{self[/\A\s*/]}/, '')
end
end
task :phar, :version do |t, args|
version = args[:version]
File.open("stub.php", "w") do |f|
f.write(<<-STUB.unindent)
<?php
Phar::mapPhar();
$basePath = 'phar://' . __FILE__ . '/';
spl_autoload_register(function($class) use ($basePath)
{
if (0 !== strpos($class, "Imagine\\\\")) {
return false;
}
$path = str_replace('\\\\', DIRECTORY_SEPARATOR, substr($class, 8));
$file = $basePath.$path.'.php';
if (file_exists($file)) {
require_once $file;
return true;
}
});
__HALT_COMPILER();
STUB
end
system "phar-build -s #{Dir.pwd}/lib/Imagine -S #{Dir.pwd}/stub.php --phar #{Dir.pwd}/imagine.phar --ns"
File.unlink("stub.php")
end
task :test do
system "phpunit tests/"
end
task :sphinx do
`git ls-files lib/Imagine*.php`.split("\n").each do |f|
rst_file = f.gsub(/^lib\/Imagine(.*)\.php/) { |s| "docs/api#{$1}.rst" }.underscore
rst_dir = File.dirname(rst_file)
FileUtils.mkdir_p(rst_dir) unless Dir.exists?(rst_dir)
system "doxphp < #{f} | doxphp2sphinx > #{rst_file}"
end
end
task :clean do
system "git clean -df"
end
task :pear, :version do |t, args|
Dir.chdir("lib")
version = args[:version]
now = DateTime.now
hash = Digest::MD5.new
xml = Nokogiri::XML::Builder.new do |xml|
xml.package(:packagerversion => "1.8.0", :version => "2.0",
:xmlns => "http://pear.php.net/dtd/package-2.0",
"xmlns:tasks" => "http://pear.php.net/dtd/tasks-1.0",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation" => [
"http://pear.php.net/dtd/tasks-1.0",
"http://pear.php.net/dtd/tasks-1.0.xsd",
"http://pear.php.net/dtd/package-2.0",
"http://pear.php.net/dtd/package-2.0.xsd"
].join(" ")) {
xml.name "Imagine"
xml.channel "pear.avalanche123.com"
xml.summary "PHP 5.3 Object Oriented image manipulation library."
xml.description "Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries."
xml.lead {
xml.name "Bulat Shakirzyanov"
xml.user "avalanche123"
xml.email "mallluhuct at gmail.com"
xml.active "yes"
}
xml.date now.strftime('%Y-%m-%d')
xml.time now.strftime('%H:%M:%S')
xml.version {
xml.release version
xml.api version
}
xml.stability {
xml.release "beta"
xml.api "beta"
}
xml.license "MIT", :uri => "http://www.opensource.org/licenses/mit-license.php"
xml.notes "-"
xml.contents {
xml.dir(:name => "/") {
`git ls-files`.split("\n").each { |f|
open(f, "r") do |io|
while (!io.eof)
hash.update(io.readpartial(1024))
end
end
xml.file(:md5sum => hash.hexdigest, :role => "php", :name => f)
}
}
}
xml.dependencies {
xml.required {
xml.php {
xml.min "5.3.2"
}
xml.pearinstaller {
xml.min "1.4.0"
}
}
}
xml.phprelease
}
end
File.open("package.xml", "w") { |f| f.write(xml.to_xml) }
system "pear package"
File.unlink("package.xml")
FileUtils.mv("Imagine-#{version}.tgz", "../")
end
task :composer, :version do |t, args|
version = args[:version]
File.open("composer.json", "w") do |f|
f.write(JSON.pretty_generate(
"name" => "imagine/Imagine",
"description" => "Image processing for PHP 5.3",
"keywords" => ["image manipulation","image processing", "drawing", "graphics"],
"homepage" => "http://imagine.readthedocs.org/",
"license" => "MIT",
"authors" => [
{
"name" => "Bulat Shakirzyanov",
"email" => "mallluhuct@gmail.com",
"homepage" => "http://avalanche123.com"
}
],
"require" => {
"php" => ">=5.3.2"
}
))
end
end
task :release, :version do |t, args|
version = args[:version]
Rake::Task["test"]
Rake::Task["sphinx"].invoke
system "git add docs/api"
system "git commit -m \"updated api docs for release #{version}\""
Rake::Task["composer"].invoke(version)
system "git add composer.json"
system "git commit -m \"updated composer.json for #{version} release\""
Rake::Task["pear"].invoke(version)
Rake::Task["phar"].invoke(version)
system "git add imagine.phar"
system "git commit -m \"update phar distribution for #{version}\""
system "git checkout master"
system "git merge develop"
system "git tag v#{version} -m \"release v#{version}\""
system "git push"
system "git push --tags"
end