-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
78 lines (64 loc) · 1.8 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
# Inspired by https://github.com/dusty/multi-rack-app-app/blob/master/tasks/app.rake
BUILD_DIRECTORY = "build"
APP_PORT = 3000
BUILD_PORT = APP_PORT.succ
def start_server(name, port)
puts "=> Starting #{name} server"
sh "rackup -p #{port} -P #{name}.pid -D"
end
def stop_server(name)
begin
Process.kill("INT", File.read("#{name}.pid").to_i)
puts "=> Stopped #{name} server"
rescue
puts "!! PID not found"
end
end
task :default => ["build:make"]
namespace :build do
desc "Build a copy of the domekit.cc generator into the build directory"
task :make => [:clean, :start, :pause, :copy_assets, :copy_app, :stop] do
puts "=> Build complete. Please commit the changes."
end
task :start do
start_server(:build, BUILD_PORT)
end
task :stop do
stop_server(:build)
end
task :copy_assets do
puts "=> Copying static assets to build directory"
files = Dir.glob('domekit.cc/generator/*')
mkdir BUILD_DIRECTORY
cp_r files, "build"
end
task :copy_app do
puts "=> Building app HTML and Javascript"
begin
sh "curl localhost:#{BUILD_PORT}/domekit.cc/generator/generator.js?build > #{BUILD_DIRECTORY}/generator.js"
sh "curl localhost:#{BUILD_PORT}/domekit.cc/generator/index.html?build > #{BUILD_DIRECTORY}/index.html"
rescue
puts "Files failed to be copied. Do you have curl installed? Was the server running?"
end
end
task :pause do
puts "=> Waiting for build server to start"
sleep 3
end
task :clean do
puts "=> Deleting build directory"
rm_rf BUILD_DIRECTORY
end
end
namespace :app do
desc "Start app server in background"
task :start do
start_server(:app, APP_PORT)
end
desc "Stop app server"
task :stop do
stop_server(:app)
end
desc 'Restart app server'
task :restart => [:stop, :start]
end