-
Notifications
You must be signed in to change notification settings - Fork 16
/
Rakefile
135 lines (112 loc) · 3.47 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
desc 'Install the dependencies'
task :bootstrap do
sh 'git submodule update --init'
sh 'bundle install'
end
begin
require 'rubygems'
require 'bundler/setup'
namespace :stories do
desc 'Add IDs to new stories'
task :autofill do
tmp = '/tmp/push.cocoapods.org-requirements.txt'
sh "saga autofill design/requirements.txt > #{tmp}"
mv tmp, 'design/requirements.txt'
end
desc 'Convert the requirements txt file to html'
task :convert do
sh 'saga convert --template design/requirements_template design/requirements.txt > design/requirements.html'
end
end
task :env do
$LOAD_PATH.unshift(File.expand_path('../', __FILE__))
require 'config/init'
end
task :rack_env do
ENV['RACK_ENV'] ||= 'development'
end
namespace :db do
def schema
require 'terminal-table'
result = ''
DB.tables.each do |table|
result << "#{table}\n"
schema = DB.schema(table)
terminal_table = Terminal::Table.new(
:headings => [:name, *schema[0][1].keys],
:rows => schema.map { |c| [c[0], *c[1].values.map(&:inspect)] },
)
result << "#{terminal_table}\n\n"
end
result
end
desc 'Show schema'
task :schema => :env do
puts schema
end
desc 'Run migrations'
task :migrate => :rack_env do
ENV['TRUNK_APP_LOG_TO_STDOUT'] = 'true'
raise 'Migrations for this DB should run via https://github.com/CocoaPods/humus'
end
desc 'Drop DB for RACK_ENV'
task :drop => :rack_env do
sh "dropdb trunk_cocoapods_org_#{ENV.fetch('RACK_ENV', nil)}"
end
desc 'Create DB for RACK_ENV'
task :create => :rack_env do
sh "createdb -h localhost trunk_cocoapods_org_#{ENV.fetch('RACK_ENV', nil)} -E UTF8"
puts 'Note: Migrations for this DB should run via https://github.com/cocoaPods/humus'
end
desc 'Seed DB'
task :seed => :rack_env do
sh 'bundle exec ruby db/seeds.rb'
end
desc 'Create, migrate, and seed the DB for RACK_ENV'
task :bootstrap => %i[create migrate seed]
desc 'Drop and then bootstrap the DB for RACK_ENV'
task :reset => %i[drop bootstrap]
end
desc 'Starts a interactive console with the model env loaded'
task :console do
exec 'irb', '-I', File.expand_path('../', __FILE__), '-r', 'config/init'
end
desc 'Starts processes for local development'
task :serve do
puts 'Starting server at http://localhost:4567'
exec 'env PORT=4567 RACK_ENV=development foreman start'
end
desc 'Run the specs'
task :spec do
title 'Running the specs'
sh "bacon #{FileList['spec/**/*_spec.rb'].shuffle.join(' ')}"
title 'Checking code style'
Rake::Task[:rubocop].invoke
end
desc 'Use Kicker to automatically run specs'
task :kick do
exec 'bundle exec kicker -c'
end
task :default => :spec
#-- Rubocop -------------------------------------------------------------------
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |task|
task.patterns = FileList['{app,config,db,lib,spec}/**/*.rb']
task.fail_on_error = true
end
rescue LoadError
puts '[!] The Rubocop tasks have been disabled'
end
rescue SystemExit, LoadError => e
puts "[!] The normal tasks have been disabled: #{e.message}"
end
#-- UI ------------------------------------------------------------------------
def title(title)
cyan_title = "\033[0;36m#{title}\033[0m"
puts
puts '-' * 80
puts cyan_title
puts '-' * 80
puts
end