This repository has been archived by the owner on Jan 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
57 lines (52 loc) · 1.93 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 "rubygems"
require 'rake'
require 'rake/testtask'
task :default => :clone_web
desc "Build a new web app project from template"
task :clone_web do
if ENV['project'].nil?
puts "requires project variable example: bundle exec rake clone_web project='project_name'"
else
project_name = ENV['project']
puts "building project: #{project_name}"
cmds = ["mkdir #{project_name}",
"cp -R ./sinatra_template/web/ ./#{project_name}/",
"cp ./sinatra_template/README.md ./#{project_name}/"
]
cmds.map{ |cmd| run_cmd_in_dir('../',cmd) }
cmds = ["rm -rf .git",
"git init",
"rm -rf .rvmrc",
"rm -rf tmp/*",
"echo \"rvm use ruby-1.9.3-p392 --create\" >> .rvmrc",
"find ./ -type f -exec sed -i '' 's/SINATRA_TEMPLATE/#{project_name}/g' {} \\;"]
cmds.map{ |cmd| run_cmd_in_dir("../#{project_name}",cmd) }
end
end
desc "Build a new api project from template"
task :clone_api do
if ENV['project'].nil?
puts "requires project variable example: bundle exec rake clone_api project='project_name'"
else
project_name = ENV['project']
puts "building project: #{project_name}"
cmds = ["mkdir #{project_name}",
"cp -R ./sinatra_template/api/ ./#{project_name}/",
"cp ./sinatra_template/README.md ./#{project_name}/"
]
cmds.map{ |cmd| run_cmd_in_dir('../',cmd) }
cmds = ["rm -rf .git",
"git init",
"rm -rf .rvmrc",
"rm -rf tmp/*",
"echo \"rvm use ruby-1.9.3-p392 --create\" >> .rvmrc",
"find ./ -type f -exec sed -i '' 's/SINATRA_TEMPLATE/#{project_name}/g' {} \\;"]
cmds.map{ |cmd| run_cmd_in_dir("../#{project_name}",cmd) }
end
end
def run_cmd_in_dir(dir, cmd)
Dir.chdir(dir) do
puts "running #{cmd}"
puts `#{cmd}`
end
end