forked from erisdev/adium-gentleglow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
127 lines (94 loc) · 3.65 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
require 'less'
require 'yaml'
require 'json'
class String
def / (other) File.join(self, other); end
def basename(*args) File.basename(self, *args); end
end
def template_file template_path, output_path
output = File.read template_path
output.gsub!(%r( \$\{ ([^\}]+) \} )x) { PACKAGE_INFO[$1.gsub(/_/, '-')] }
output_path = output_path / File.basename(template_path) \
if File.directory? output_path
File.open(output_path, 'w') { |io| io.write output }
end
PACKAGE_INFO = YAML.load_file 'package.yaml'
BUNDLE_NAME = "#{PACKAGE_INFO['package-name']}.AdiumMessageStyle"
BUILD_DIR = 'build'
PACKAGE_DIR = BUILD_DIR / PACKAGE_INFO['package-name']
BUNDLE_DIR = PACKAGE_DIR / BUNDLE_NAME
CONTENTS_DIR = BUNDLE_DIR / "Contents"
RESOURCES_DIR = CONTENTS_DIR / 'Resources'
COFFEE_FILES = FileList['scripts/**/*.coffee']
JS_FILES = COFFEE_FILES.pathmap BUILD_DIR / '%X.js'
VARIANT_FILES = FileList[ ]
PACKAGE_INFO['variants'].each do |name, files|
output_name = BUILD_DIR / 'variants' / "#{name}.css"
VARIANT_FILES << output_name
file output_name => FileList[files, BUILD_DIR / 'variants'] do
sh "lessc #{files.join ' '} > #{output_name}"
end
end
task :default => :compile
desc 'compile scripts and stylesheets'
task :compile => %w[ compile:scripts compile:variants ]
desc 'remove all build products'
task :clean => %w[ clean:scripts clean:variants clean:package ]
namespace :compile do
desc 'compile scripts'
task :scripts => [*JS_FILES, BUILD_DIR / 'scripts/message-style.js']
desc 'compile variant stylesheets'
task :variants => VARIANT_FILES
end
desc 'package for distribution'
task :package => [:compile, PACKAGE_DIR, CONTENTS_DIR, RESOURCES_DIR] do
package_name = PACKAGE_INFO['package-name']
package_version = PACKAGE_INFO['package-version']
scripts_dir = BUILD_DIR / 'scripts'
variants_dir = BUILD_DIR / 'variants'
PACKAGE_INFO['include-files'].each do |file|
if file.is_a? Hash
file.each { |from, to| sh "cp #{from} #{PACKAGE_DIR / to}"}
else
sh "cp #{file} #{PACKAGE_DIR}"
end
end
sh "rsync --recursive resources/ #{RESOURCES_DIR}"
sh "rsync --recursive #{variants_dir} #{RESOURCES_DIR}" \
if File.directory? variants_dir
sh "rsync --recursive #{scripts_dir} #{RESOURCES_DIR}" \
if File.directory? scripts_dir
template_file 'templates/Info.plist', CONTENTS_DIR
sh 'tar', 'jcf', BUILD_DIR / "#{package_name}-#{package_version}.tar.bz2",
'-C', BUILD_DIR, package_name
end
desc "install to Adium's Message Styles folder"
task :install => :package do
message_styles_dir = ENV['HOME'] / 'Library/Application Support/Adium 2.0/Message Styles'
sh "rm -R '#{message_styles_dir / BUNDLE_NAME}'"
sh "cp -R #{BUNDLE_DIR} '#{message_styles_dir}'"
end
namespace :clean do
desc 'remove compiled scripts'
task(:scripts) { system 'rm', '-f', *JS_FILES.existing }
desc 'remove compiled variant stylesheets'
task(:variants) { system 'rm', '-f', *VARIANT_FILES.existing }
desc 'remove distribution package'
task(:package) { system 'rm', '-R', 'build' if File.exist? 'build' }
end
directory BUILD_DIR
directory BUILD_DIR / 'scripts'
directory BUILD_DIR / 'variants'
directory PACKAGE_DIR
directory CONTENTS_DIR
directory RESOURCES_DIR
def pathmap spec
proc { |file| file.pathmap spec }
end
file BUILD_DIR / 'scripts/message-style.js' => 'package.yaml' do |t|
puts "writing package info to #{t.name}"
File.open(t.name, 'w') { |io| io.puts "window.MessageStyle = #{PACKAGE_INFO.to_json}" }
end
rule %r(\.js$) => [pathmap("%{^build/,}d/%n.coffee"), BUILD_DIR / 'scripts'] do |t|
sh "coffee -o #{File.dirname t.name} -c #{t.source}"
end