forked from tantaman/strut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
139 lines (114 loc) · 3.14 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
136
137
138
139
# This rakefile:
# -compiles coffee scripts
# -compiles templates
# -compiles stylus styles
# -eventually cleans up web to be a dist only thinger
require 'rake'
myDir = Dir.pwd
cmdPprefix = ""
if ENV['OS'] != nil
if ENV['OS']['Windows'] != nil
cmdPrefix = "powershell "
end
end
task :compileTpls, :pretty do |t, args|
FileList[myDir + "/src/ui/**/res/templates"].each do |filename|
pretty = args[:pretty]
puts "Processing: #{filename}"
compiledTemplates = '''
define(["vendor/amd/Handlebars"], function(Handlebars) {
return {
'''
first = true
FileList["#{filename}/*.bars"].each do |fname|
pipe = IO.popen("handlebars -s #{fname}")
result = pipe.readlines
pipe.close
joined = result.join
if not pretty
joined = joined.gsub(/\\r\\n|\n|\\n/, "");
end
templateFileName = File.basename(fname, ".bars");
if first
compiledTemplates += "\n\"#{templateFileName}\": Handlebars.template(#{joined})"
first = false
else
compiledTemplates += ",\n\"#{templateFileName}\": Handlebars.template(#{joined})"
end
end
destination = filename.sub("/src/ui/", "/web/scripts/ui/").sub("/res/templates", "")
puts "#{destination}/Templates.js"
File.open("#{destination}/Templates.js", 'w') {|f|
f.write(compiledTemplates)
f.write("\n}});");
}
end
end
task :compileStylus do
end
task :buildVendor do
system "#{cmdPrefix}rm web/scripts/vendor/vendor-built.js"
system "#{cmdPrefix}rm web/scripts/vendor/temp/*"
FileList["web/scripts/vendor/*.js"].each do |fname|
system %{uglifyjs #{fname} > web/scripts/vendor/temp/#{File.basename(fname, ".js")}.min.js}
end
if cmdPrefix != ""
system %{type web\\scripts\\vendor\\temp\\* >> web\\scripts\\vendor\\vendor-built.js}
else
system %{cat web/scripts/vendor/temp/* >> web/scripts/vendor/vendor-built.js}
end
end
task :compileCoffee, :watch do |t,args|
watch = ""
if args[:watch]
watch = "--watch"
end
system %{coffee #{watch} -b --compile --output web/scripts/ src/}
end
task :docs do
system %{yuidoc web/scripts -o docs}
end
task :refactor, :source, :destination do |t, args|
source = args[:source]
destination = args[:destination]
if !destination
puts "usage: rake refactor[source,destination]"
exit
end
FileList["./**/*.js"].each do |fname|
#puts fname
pipe = IO.popen("amdRefactor #{source} < #{fname}")
result = pipe.readlines
pipe.close
if result.length > 0
# line col_start col_end
importLoc = result[0].split(",")
line = Integer(importLoc[0]) - 1
colStart = Integer(importLoc[1]) - 1
colEnd = Integer(importLoc[2])
lines = File.readlines(fname);
theLine = lines[line]
theLine =
"#{theLine[0..colStart]}#{destination}#{theLine[colEnd..theLine.length]}"
lines[line] = theLine
puts "Refactoring: #{fname}"
File.open(fname, 'w') { |f| f << lines }
#puts lines
end
end
end
task :showDeps, :package do |t, args|
myPkg = args[:package]
if !myPkg
puts "usage: rake showDeps[package]"
exit
end
FileList["web/scripts/#{myPkg}/**/*.js"].each do |fname|
pipe = IO.popen("amdDeps #{myPkg} < #{fname}")
result = pipe.readlines
pipe.close
if result.length > 0
puts result
end
end
end