This repository has been archived by the owner on Dec 2, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
57 lines (45 loc) · 1.44 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
require 'rake'
require 'yaml'
require 'curb'
PROJECT_PATH = File.dirname(__FILE__)
PUBLIC = File.join(PROJECT_PATH, "public")
EXPORT = File.join(PROJECT_PATH, "export")
desc "Set up the project before running the server"
task :setup => [:install_dependencies] do
p %(Run "ruby server.rb" to start the server at localhost:4567)
end
desc "Installs the gems needed to run the project server script"
task :install_dependencies do
system %(sudo gem install sinatra less sprockets haml datamapper data_objects do_sqlite3 json curb)
end
desc "Export dynamic files as static"
task :export do
FileUtils.mkdir_p EXPORT
manifest = YAML.load_file("export.yml")
manifest["files"].each do |filename|
output = File.join(EXPORT, filename)
FileUtils.mkdir_p base_path(output)
c = Curl::Easy.perform("http://localhost:4567/" + filename)
File.open(output, "w") do |f|
f.write c.body_str
end
end
copy_files([ "**/**" ], PUBLIC, EXPORT)
end
### Utility Functions
def base_path(file)
file.sub(/#{File.basename(file)}$/, '')
end
def absolute_path_to_relative_path(abs, from, to)
to + abs.sub(/^#{from}/, '')
end
def copy_files(list, from, to)
list.each do |glob|
filelist = FileList.new(File.join(from, glob))
filelist.each do |file|
new_file = absolute_path_to_relative_path(file, from, to)
FileUtils.mkdir_p base_path(new_file)
FileUtils.cp file, new_file unless File.directory?(file)
end
end
end