-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
154 lines (128 loc) · 3.95 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
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
require 'yaml'
require 'plist'
config_file = 'config.yml'
workflow_home = File.expand_path('~/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows')
$config = YAML.load_file(config_file)
$config['bundleid'] = "#{$config['domain']}.#{$config['id']}"
$config['plist'] = File.join($config['path'], 'info.plist')
$config['workflow_dbx'] = File.join(File.expand_path($config['dropbox']), '/Alfred.alfredpreferences/workflows')
# import sub-rakefiles
FileList['*/Rakefile'].each { |file|
import file
}
desc 'Update config'
task :config do
modified = false
info = Plist::parse_xml($config['plist'])
if info['bundleid'] != $config['bundleid']
info['bundleid'] = $config['bundleid']
modified = true
end
if info['createdby'] != $config['created_by']
info['createdby'] = $config['created_by']
modified = true
end
if info['description'] != $config['description']
info['description'] = $config['description']
modified = true
end
if info['name'] != $config['name']
info['name'] = $config['name']
modified = true
end
if info['webaddress'] != $config['website']
info['webaddress'] = $config['website']
modified = true
end
if info['readme'] != $config['readme']
info['readme'] = $config['readme']
modified = true
end
if modified
File.open($config['plist'], 'wb') { |file| file.write(info.to_plist) }
end
end
task :chdir => [:config] do
chdir $config['path']
end
desc 'Install Gems'
task 'bundle:install' => [:chdir] do
sh %Q{bundle install --standalone --clean} do |ok, res|
if !ok
puts "fail to install gems (status = #{res.exitstatus})"
end
end
end
desc 'Update Gems'
task 'bundle:update' => [:chdir] do
sh %Q{bundle update && bundle install --standalone --clean} do |ok, res|
if !ok
puts "fail to update gems (status = #{res.exitstatus})"
end
end
end
desc 'Install to Alfred'
task :install => [:config] do
ln_sf File.expand_path($config['path']), File.join(workflow_home, $config['bundleid'])
end
desc 'Unlink from Alfred'
task :uninstall => [:config] do
rm File.join(workflow_home, $config['bundleid'])
end
desc 'Install to Dropbox'
task :dbxinstall => [:config] do
ln_sf File.expand_path($config['path']), File.join($config['workflow_dbx'], $config['bundleid'])
end
desc 'Unlink from Dropbox'
task :dbxuninstall => [:config] do
rm File.join($config['workflow_dbx'], $config['bundleid'])
end
desc 'Clean up all the extras'
task :clean => [:config] do
end
desc 'Remove any generated file'
task :clobber => [:clean] do
rmtree File.join($config['path'], '.bundle')
rmtree File.join($config['path'], 'bundle')
end
desc 'Create packed Workflow'
task :export => [:config] do
ruby_version = RbConfig::CONFIG['ruby_version']
filename = "#{$config['id'].chomp '-workflow'}.alfredworkflow"
output = 'output'
FileUtils.rm filename if File.exists? filename
FileUtils.rmtree output if File.exists? output
FileUtils.cp_r $config['path'], output
chdir output
# clean up workflow files for export
Dir.foreach('.') do |file|
FileUtils.rmtree file if %w(Gemfile Gemfile.lock .bundle).include? file
end
Dir.chdir('bundle/ruby') do
Dir.foreach('.') do |dir|
next if dir == '.' || dir == '..'
FileUtils.rmtree dir if dir != ruby_version
end
end
Dir.chdir("bundle/ruby/#{ruby_version}") do
Dir.foreach('.') do |dir|
FileUtils.rmtree dir if %w(build_info cache doc specifications).include? dir
end
Dir.chdir('gems') do
Dir.foreach('.') do |dir|
next if dir == '.' || dir == '..'
Dir.chdir(dir) do
Dir.foreach('.') do |subdir|
next if subdir == '.' || subdir == '..'
FileUtils.rmtree subdir if !(%w(. .. lib).include? subdir)
end
end
end
end
end
`/usr/bin/zip -r ../#{filename} *`
chdir('..')
FileUtils.rmtree output
puts 'Workflow exported to project directory'
end