-
Notifications
You must be signed in to change notification settings - Fork 89
/
rakefile
119 lines (98 loc) · 3.62 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
require 'rake'
################################################################################################
# constants
NEXT_VERSION = "0.1"
STABLE_VERSION = "0.1"
ROOT_DIR = File.expand_path('.')
CMXIO_DIR = File.join(ROOT_DIR, '..', 'cmx.io')
CMXIO_EDIT_DIR = File.join(CMXIO_DIR, 'edit')
CMXIO_V_DIR = File.join(CMXIO_DIR, 'v')
################################################################################################
# dependencies
begin
require 'colored'
rescue LoadError
raise 'You must "gem install colored" to use terminal colors'
end
################################################################################################
# helpers
def die(msg, status=1)
puts "Error[#{status||$?}]: #{msg}".red
exit status||$?
end
def sys(cmd)
puts "> #{cmd}".yellow
system(cmd)
end
def patch(path, replacers)
puts "Patching #{path.blue}"
lines = []
File.open(path, "r") do |f|
f.each do |line|
replacers.each do |r|
line.gsub!(r[0], r[1])
end
lines << line
end
end
File.open(path, "w") do |f|
f << lines.join
end
end
################################################################################################
# tasks
desc "start dev server"
task :dev do
sys("yeoman server")
end
desc "build version"
task :build do
die("build failed") if not sys("grunt build -d")
version = ENV["v"] || NEXT_VERSION
VERSION_DIR = File.join(CMXIO_V_DIR, version)
sys("rm -rf \"#{CMXIO_EDIT_DIR}\"/*")
sys("mkdir -p \"#{CMXIO_EDIT_DIR}\"")
Dir.chdir "dist" do
# cherry-pick homepage files
sys("rm -rf \"#{CMXIO_DIR}\"/fonts")
sys("cp -r fonts \"#{CMXIO_DIR}\"")
sys("rm -rf \"#{CMXIO_DIR}\"/img")
sys("cp -r img \"#{CMXIO_DIR}\"")
sys("rm -rf \"#{CMXIO_DIR}\"/styles")
sys("mkdir -p \"#{CMXIO_DIR}/styles\"")
sys("cp -r styles/site.css \"#{CMXIO_DIR}\"/styles")
sys("rm -rf \"#{CMXIO_DIR}\"/scripts")
sys("mkdir -p \"#{CMXIO_DIR}/scripts/vendor\"")
sys("cp scripts/site.js \"#{CMXIO_DIR}\"/scripts")
sys("cp scripts/404.js \"#{CMXIO_DIR}\"/scripts")
sys("cp scripts/vendor/jquery.js \"#{CMXIO_DIR}\"/scripts/vendor")
sys("cp scripts/vendor/modernizr.js \"#{CMXIO_DIR}\"/scripts/vendor")
sys("cp favicon.ico \"#{CMXIO_DIR}\"")
sys("cp index.html \"#{CMXIO_DIR}\"")
sys("cp 404.html \"#{CMXIO_DIR}\"")
# cherry-pick editor files
sys("cp edit/index.html \"#{CMXIO_EDIT_DIR}\"")
sys("cp edit/sample.html \"#{CMXIO_EDIT_DIR}\"")
patch(File.join(CMXIO_EDIT_DIR, "sample.html"), [
["<script data-main=\"v/cmx\" src=\"scripts/vendor/require.js\"></script>", "<script src=\"http://cmx.io/v/#{STABLE_VERSION}/cmx.js\" charset=\"utf-8\"></script>"],
["v/cmx", "http://cmx.io/v/#{STABLE_VERSION}/cmx"]
])
# concat require.js and cmx.js, this work should be done by usemin, but I was unable to debug it
# see https://github.com/yeoman/grunt-usemin/issues/67
sys("mv v/cmx.js v/cmx2.js && cat ../app/edit/scripts/vendor/require.js v/cmx2.js > v/cmx.js && rm v/cmx2.js")
sys("mkdir -p \"#{CMXIO_EDIT_DIR}/scripts\"")
sys("mkdir -p \"#{CMXIO_EDIT_DIR}/styles\"")
sys("mkdir -p \"#{CMXIO_EDIT_DIR}/scripts/ace\"")
sys("cp scripts/editor.js \"#{CMXIO_EDIT_DIR}/scripts\"")
sys("cp styles/editor.css \"#{CMXIO_EDIT_DIR}/styles\"")
sys("cp edit/scripts/ace/theme-chrome.js \"#{CMXIO_EDIT_DIR}/scripts/ace\"")
sys("cp edit/scripts/ace/mode-html.js \"#{CMXIO_EDIT_DIR}/scripts/ace\"")
sys("cp edit/editor.ico \"#{CMXIO_EDIT_DIR}\"")
end
sys("rm -rf \"#{VERSION_DIR}\"/*")
sys("mkdir -p \"#{VERSION_DIR}\"")
Dir.chdir "dist" do
sys("cp -r v/* \"#{VERSION_DIR}\"")
end
end
task :default => :dev