ymdp 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/application_view/compiler/template_compiler.rb +2 -1
- data/lib/application_view/tasks/keys.rake +236 -0
- data/lib/application_view/tasks/ymdp.rake +720 -0
- data/lib/new_application/lib/tasks/keys.rake +1 -233
- data/lib/new_application/lib/tasks/ymdp.rake +1 -715
- data/ymdp.gemspec +3 -2
- metadata +3 -2
- data/lib/application_view/support/g.rb +0 -11
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
@@ -250,7 +250,7 @@ class TemplateCompiler
|
|
250
250
|
attr_accessor :domain, :git_hash, :options
|
251
251
|
|
252
252
|
def self.compile
|
253
|
-
time do
|
253
|
+
time("", :title => "YMDP") do
|
254
254
|
system "rm ./tmp/*"
|
255
255
|
|
256
256
|
options = parse_options
|
@@ -357,6 +357,7 @@ class TemplateCompiler
|
|
357
357
|
system "rm -rf #{dir}/assets/javascripts"
|
358
358
|
system "rm -rf #{dir}/assets/stylesheets"
|
359
359
|
system "rm -rf #{dir}/assets/yrb"
|
360
|
+
system "rm #{TMP_DIR}/*"
|
360
361
|
end
|
361
362
|
|
362
363
|
def log(text)
|
@@ -0,0 +1,236 @@
|
|
1
|
+
require 'lib/init'
|
2
|
+
|
3
|
+
require 'translator/base'
|
4
|
+
|
5
|
+
@key = ENV["key"] || ""
|
6
|
+
@key = @key.upcase
|
7
|
+
|
8
|
+
ASSETS_ROOT = "#{YMDP_ROOT}/app/assets"
|
9
|
+
YRB_ROOT = "#{ASSETS_ROOT}/yrb"
|
10
|
+
|
11
|
+
namespace :keys do
|
12
|
+
task :add_new do
|
13
|
+
Dir["./app/assets/yrb/*.pres"].each do |path|
|
14
|
+
# system "cat app/assets/new/keys_en-US.pres >> app/assets/yrb/keys_en-US.pres"
|
15
|
+
new_path = path.gsub("yrb", "new")
|
16
|
+
system "cat #{new_path} >> #{path}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :new_since do
|
21
|
+
@date = ENV["date"]
|
22
|
+
if @date
|
23
|
+
change_keys do |line|
|
24
|
+
puts line
|
25
|
+
if line =~ /#{@date}/
|
26
|
+
@on ||= true
|
27
|
+
end
|
28
|
+
line if @on
|
29
|
+
end
|
30
|
+
else
|
31
|
+
message = "Must define a date with 'date='"
|
32
|
+
growl(message)
|
33
|
+
raise message
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
task :combine do
|
38
|
+
system "rm #{TMP_DIR}/*"
|
39
|
+
each_locale do |path|
|
40
|
+
puts path
|
41
|
+
filename = path.split("/").last
|
42
|
+
lang = "en-US"
|
43
|
+
if filename =~ /_(.*)\.pres/
|
44
|
+
lang = $1
|
45
|
+
end
|
46
|
+
|
47
|
+
File.open(path, "r") do |f|
|
48
|
+
File.open("#{TMP_DIR}/keys_#{lang}.pres", "a") do |tmp|
|
49
|
+
tmp.write(f.read)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
system "rm -rf #{YRB_ROOT}/*"
|
55
|
+
system "cp #{TMP_DIR}/* #{YRB_ROOT}"
|
56
|
+
|
57
|
+
system "rm #{TMP_DIR}/*"
|
58
|
+
end
|
59
|
+
|
60
|
+
task :destroy do
|
61
|
+
system "rm #{TMP_DIR}/*"
|
62
|
+
|
63
|
+
raise "Must define a key with 'key='" if @key == ""
|
64
|
+
|
65
|
+
change_keys do |line|
|
66
|
+
line_array = parse_yrb(line)
|
67
|
+
|
68
|
+
if line_array[0] == @key
|
69
|
+
line = ""
|
70
|
+
end
|
71
|
+
|
72
|
+
line
|
73
|
+
end
|
74
|
+
|
75
|
+
system "rm #{TMP_DIR}/*"
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Translate any new keys into non-US languages"
|
79
|
+
task :translate do
|
80
|
+
ApplicationView::Translator::YRB.translate
|
81
|
+
end
|
82
|
+
|
83
|
+
task :rename do
|
84
|
+
system "rm #{TMP_DIR}/*"
|
85
|
+
|
86
|
+
@to = ENV["to"] || ""
|
87
|
+
@to = @to.upcase
|
88
|
+
|
89
|
+
raise "Must define a key with 'key='" if @key == ""
|
90
|
+
raise "Must define a new key name with 'to='" if @to == ""
|
91
|
+
|
92
|
+
change_keys do |line|
|
93
|
+
line_array = parse_yrb(line)
|
94
|
+
|
95
|
+
if line_array[0] == @key
|
96
|
+
line = "#{@to}=#{line_array[1]}"
|
97
|
+
end
|
98
|
+
|
99
|
+
line
|
100
|
+
end
|
101
|
+
|
102
|
+
system "rm #{TMP_DIR}/*"
|
103
|
+
end
|
104
|
+
|
105
|
+
# task :unused do
|
106
|
+
# # this probably would be more complicated than it's worth
|
107
|
+
#
|
108
|
+
# keys = []
|
109
|
+
# unused_keys = []
|
110
|
+
# File.open("#{YRB_ROOT}/keys_en-US.pres", "r") do |f|
|
111
|
+
# f.readlines.each do |line|
|
112
|
+
# key = parse_yrb(line).first
|
113
|
+
# keys << key unless key.blank?
|
114
|
+
# end
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
# keys.each do |key|
|
118
|
+
# puts "grep #{key} ./servers/* -R -i"
|
119
|
+
# if `grep #{key} ./servers/* -R -i`.length < 10
|
120
|
+
# puts "OMG"
|
121
|
+
# end
|
122
|
+
# end
|
123
|
+
# end
|
124
|
+
|
125
|
+
task :list do
|
126
|
+
each_locale do |path|
|
127
|
+
filename = path.split("/").last
|
128
|
+
lang = "en-US"
|
129
|
+
if filename =~ /_(.*)\.pres/
|
130
|
+
lang = $1
|
131
|
+
end
|
132
|
+
|
133
|
+
puts lang
|
134
|
+
|
135
|
+
File.open(path, "r") do |f|
|
136
|
+
f.readlines.each do |line|
|
137
|
+
puts line if line =~ /^#{@key}=/
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
task :convert_to_yml do
|
144
|
+
each_locale do |path|
|
145
|
+
# puts path
|
146
|
+
filename = path.split("/").last
|
147
|
+
lang = "en-US"
|
148
|
+
if filename =~ /_(.*)\.pres/
|
149
|
+
lang = $1
|
150
|
+
end
|
151
|
+
|
152
|
+
puts "#{lang}:"
|
153
|
+
|
154
|
+
File.open(path, "r") do |f|
|
155
|
+
f.readlines.each do |line|
|
156
|
+
if @key.blank? || line =~ /^#{@key}=/
|
157
|
+
k,v = parse_yrb(line)
|
158
|
+
puts " #{k.downcase}: #{v}"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def change_keys
|
167
|
+
each_locale do |path|
|
168
|
+
@on = false
|
169
|
+
puts path
|
170
|
+
filename = path.split("/").last
|
171
|
+
File.open(path, "r") do |f|
|
172
|
+
File.open("#{TMP_DIR}/#{filename}", "w") do |tmp|
|
173
|
+
f.readlines.each do |line|
|
174
|
+
new_line = yield line
|
175
|
+
tmp.write new_line
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
system "cp #{TMP_DIR}/#{filename} #{path}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def change_keys_with_lang
|
184
|
+
each_locale do |path|
|
185
|
+
puts path
|
186
|
+
filename = path.split("/").last
|
187
|
+
lang = "en-US"
|
188
|
+
if filename =~ /_(.*)\.pres/
|
189
|
+
lang = $1
|
190
|
+
end
|
191
|
+
File.open(path, "r") do |f|
|
192
|
+
File.open("#{TMP_DIR}/#{filename}", "w") do |tmp|
|
193
|
+
f.readlines.each do |line|
|
194
|
+
new_line = yield line, lang, filename
|
195
|
+
tmp.write new_line
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
system "cp #{TMP_DIR}/#{filename} #{path}"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def parse_yrb(line)
|
204
|
+
key = value = nil
|
205
|
+
unless line =~ /#/
|
206
|
+
tokens = line.split("=")
|
207
|
+
key = tokens.shift
|
208
|
+
value = tokens.join("=")
|
209
|
+
end
|
210
|
+
[key, value]
|
211
|
+
end
|
212
|
+
|
213
|
+
def each_locale
|
214
|
+
Dir["#{YRB_ROOT}/*.pres"].each do |path|
|
215
|
+
yield path
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def to_yrb(key, value)
|
220
|
+
"#{key}=#{value}\n"
|
221
|
+
end
|
222
|
+
|
223
|
+
def yrb_to_hash(path)
|
224
|
+
hash = {}
|
225
|
+
File.open(path, "r") do |f|
|
226
|
+
f.readlines.each do |line|
|
227
|
+
k, v = parse_yrb(line)
|
228
|
+
|
229
|
+
if k
|
230
|
+
hash[k] = v
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
hash
|
235
|
+
end
|
236
|
+
|
@@ -0,0 +1,720 @@
|
|
1
|
+
include Timer
|
2
|
+
include ApplicationView::Config
|
3
|
+
|
4
|
+
@start_time = Time.now
|
5
|
+
|
6
|
+
begin
|
7
|
+
CATEGORIES = YAML.load_file("./config/categories.yml")["categories"] unless defined?(CATEGORIES)
|
8
|
+
rescue
|
9
|
+
CATEGORIES = {} unless defined?(CATEGORIES)
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir.mkdir(TMP_DIR) rescue Errno::EEXIST
|
13
|
+
|
14
|
+
def set_application_variables(application)
|
15
|
+
@application = application
|
16
|
+
@application_id = SERVERS[@application]["application_id"]
|
17
|
+
@assets_id = SERVERS[@application]["assets_id"]
|
18
|
+
@dir = @application
|
19
|
+
rescue
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_from_servers
|
23
|
+
SERVERS.keys.each do |key|
|
24
|
+
yield key.to_sym, "set_#{key}".to_sym
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_from_default_server
|
29
|
+
yield @default_server
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_from_categories(task_name)
|
33
|
+
CATEGORIES.keys.each do |category|
|
34
|
+
desc "#{task_name.to_s.capitalize} the #{category}"
|
35
|
+
task category.to_sym => ["set_#{category}", task_name]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# rake deploy app=staging PATH=views/settings
|
40
|
+
# rake deploy app=my
|
41
|
+
|
42
|
+
@username = CONFIG["username"]
|
43
|
+
@password = CONFIG["password"]
|
44
|
+
|
45
|
+
unless @username
|
46
|
+
puts
|
47
|
+
puts "Enter your username in ./config/config.yml"
|
48
|
+
puts
|
49
|
+
raise "Username not found."
|
50
|
+
end
|
51
|
+
|
52
|
+
unless @password
|
53
|
+
puts
|
54
|
+
puts "Enter your password in ./config/config.yml"
|
55
|
+
puts
|
56
|
+
raise "Password not found."
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
@default_server = CONFIG["default_server"] || "staging"
|
61
|
+
@application = ENV["app"] || @default_server
|
62
|
+
set_application_variables(@application)
|
63
|
+
@path = ENV["path"] || ENV["p"] || ""
|
64
|
+
@dry_run = ENV["dry_run"]
|
65
|
+
@confirm = ENV["confirm"]
|
66
|
+
@build_message = ENV["build"]
|
67
|
+
@view = ENV["view"]
|
68
|
+
@lang = ENV["lang"]
|
69
|
+
|
70
|
+
@sync = ENV["sync"]
|
71
|
+
|
72
|
+
@validate_html = (ENV["validate_html"] || CONFIG["validate_html"].to_s) != "false"
|
73
|
+
@validate_js_assets = (ENV["validate_js_assets"] || CONFIG["validate_js_assets"].to_s) != "false"
|
74
|
+
@validate_json_assets = (ENV["validate_json_assets"] || CONFIG["validate_json_assets"].to_s) != "false"
|
75
|
+
@validate_embedded_js = (ENV["validate_embedded_js"] || CONFIG["validate_embedded_js_deploy"].to_s) != "false"
|
76
|
+
|
77
|
+
create_from_servers do |key, set_task|
|
78
|
+
task set_task do
|
79
|
+
set_application_variables(key.to_s)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "Default task shows documentation"
|
84
|
+
task :default do
|
85
|
+
docs = <<-DOCS
|
86
|
+
USAGE: rake TASK [app={application}] [path={path}], [dry_run=true], [dir={directory}], [application_id={app_id}] [skip_validation=true]
|
87
|
+
|
88
|
+
GETTING STARTED:
|
89
|
+
|
90
|
+
1. First, copy the config.yml.example file to config.yml with the command:
|
91
|
+
|
92
|
+
./script/config
|
93
|
+
|
94
|
+
2. Enter the correct username and password in ./config/config.yml
|
95
|
+
|
96
|
+
3. Download local copies of all our remote applications from YMDP:
|
97
|
+
|
98
|
+
rake create:all
|
99
|
+
|
100
|
+
4. Edit the HTML template in the subdirectories "app/views" and "app/assets".
|
101
|
+
|
102
|
+
5. To build the views and javascript files from edited templates, and commit the changes:
|
103
|
+
|
104
|
+
./script/build -m "<commit_message>"
|
105
|
+
|
106
|
+
6. To deploy your local changes to the staging server:
|
107
|
+
|
108
|
+
rake deploy:views
|
109
|
+
rake deploy:javascripts
|
110
|
+
|
111
|
+
DOCS
|
112
|
+
puts docs
|
113
|
+
end
|
114
|
+
|
115
|
+
desc "Some more help"
|
116
|
+
task :help do
|
117
|
+
docs = <<-DOCS
|
118
|
+
|
119
|
+
#{please_install_rhino}
|
120
|
+
|
121
|
+
FOR HELP:
|
122
|
+
|
123
|
+
To list reference for all tasks:
|
124
|
+
|
125
|
+
rake tasks
|
126
|
+
|
127
|
+
To get help for a specific command (this is still in progress):
|
128
|
+
|
129
|
+
rake create:help
|
130
|
+
rake deploy:help
|
131
|
+
rake validate:help
|
132
|
+
|
133
|
+
DOCS
|
134
|
+
puts docs
|
135
|
+
end
|
136
|
+
|
137
|
+
desc "Show usage for tasks"
|
138
|
+
task :tasks do
|
139
|
+
docs = <<-DOCS
|
140
|
+
USAGE: rake TASK [app={application}] [path={path}], [dry_run=true], [dir={directory}], [application_id={app_id}]
|
141
|
+
|
142
|
+
VALID TASKS:
|
143
|
+
|
144
|
+
create creates a new local copy of an existing YMDP application
|
145
|
+
deploy deploys local copy of YMDP application to remote server
|
146
|
+
validate validates javascript assets
|
147
|
+
|
148
|
+
The "create" and "deploy" tasks can be subtasked with the name of a server:
|
149
|
+
|
150
|
+
create:my create a new local copy of the production application
|
151
|
+
deploy:staging deploy local changes to the staging application
|
152
|
+
|
153
|
+
The "validate" task can be subtasked with "all" to validate all the javascripts for the given server:
|
154
|
+
|
155
|
+
validate:all validates all our javascript assets for the given server (including JSON)
|
156
|
+
|
157
|
+
DOCS
|
158
|
+
# TODO: add more documentation
|
159
|
+
|
160
|
+
puts docs
|
161
|
+
end
|
162
|
+
|
163
|
+
desc "Deploys application to YMDP servers"
|
164
|
+
task :deploy do
|
165
|
+
time("Deployed #{@application}: #{@path}") do
|
166
|
+
deploy(@application, @path)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
desc "Deploys application to YMDP servers, matching a path"
|
171
|
+
task :deploy_path do
|
172
|
+
time("Deployed #{@application}: #{@path}") do
|
173
|
+
deploy_path(@application, @path)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
task :deploy_yrb do
|
178
|
+
time("Deployed #{@application}: #{@path}") do
|
179
|
+
deploy_yrb(@application, @path, {:lang => @lang, :view => @view})
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
desc "List files"
|
184
|
+
task :list_assets do
|
185
|
+
puts list(@application, @path)
|
186
|
+
end
|
187
|
+
|
188
|
+
desc "Quality-control to determine if all the assets have the same ID"
|
189
|
+
task :check_assets do
|
190
|
+
report_asset_ids(@application, @path)
|
191
|
+
end
|
192
|
+
|
193
|
+
desc "Update remote assets which don't match the correct asset ID"
|
194
|
+
task :fix_assets do
|
195
|
+
fix_assets(@application, @path)
|
196
|
+
end
|
197
|
+
|
198
|
+
desc "Validates all javascripts"
|
199
|
+
task :validate => "validate:all"
|
200
|
+
|
201
|
+
|
202
|
+
namespace :check_assets do
|
203
|
+
create_from_servers do |key, set_task|
|
204
|
+
desc "Check asset IDs on #{key} server"
|
205
|
+
task key => [set_task, :check_assets]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
namespace :fix_assets do
|
210
|
+
create_from_servers do |key, set_task|
|
211
|
+
desc "Update remote assets which don't match the correct asset ID on #{key} server"
|
212
|
+
task key => [set_task, :fix_assets]
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
namespace :list_assets do
|
217
|
+
create_from_servers do |key, set_task|
|
218
|
+
desc "List files from #{key} application"
|
219
|
+
task key => [set_task, :list]
|
220
|
+
end
|
221
|
+
|
222
|
+
create_from_servers do |key, set_task|
|
223
|
+
namespace key do
|
224
|
+
desc "Lists views from the #{key} server"
|
225
|
+
task :views => [set_task, :set_views, :list_assets]
|
226
|
+
|
227
|
+
desc "Lists all assets from the #{key} server"
|
228
|
+
task :assets => [set_task, :set_assets, :list_assets]
|
229
|
+
|
230
|
+
desc "Lists javascript assets from the #{key} server"
|
231
|
+
task :javascripts => [set_task, :set_javascripts, :list_assets]
|
232
|
+
|
233
|
+
desc "Lists image assets from the #{key} server"
|
234
|
+
task :images => [set_task, :set_images, :list_assets]
|
235
|
+
|
236
|
+
desc "Lists YRB bundles from the #{key} server"
|
237
|
+
task :yrb => [set_task, :set_yrb, :list_assets]
|
238
|
+
|
239
|
+
desc "Lists everything except images from the the #{key} server"
|
240
|
+
task :code => ["list_assets:#{key}:views", :skip_validation, "list_assets:#{key}:javascripts", "list_assets:#{key}:yrb"]
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
create_from_categories(:list)
|
245
|
+
end
|
246
|
+
|
247
|
+
namespace :validate do
|
248
|
+
create_from_servers do |key, set_task|
|
249
|
+
namespace key do
|
250
|
+
desc "Validates all javascripts (excluding prototype/scriptaculous)"
|
251
|
+
task :javascripts => [set_task, "validate:javascripts"]
|
252
|
+
|
253
|
+
desc "Validates all JSON"
|
254
|
+
task :json => [set_task, "validate:json"] do
|
255
|
+
end
|
256
|
+
|
257
|
+
desc "Validates all HTML"
|
258
|
+
task :html => [set_task,"validate:html"] do
|
259
|
+
end
|
260
|
+
|
261
|
+
desc "Validates all embedded JavaScript"
|
262
|
+
task :embedded_js => [set_task,"validate:embedded_js"] do
|
263
|
+
end
|
264
|
+
|
265
|
+
desc "Validates all javascripts and JSON and HTML"
|
266
|
+
task :all => [set_task, "validate:all"]
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
desc "Validates all javascripts (excluding prototype/scriptaculous)"
|
271
|
+
task :javascripts do
|
272
|
+
puts "\nValidating external JavaScript assets in #{@application}..."
|
273
|
+
Dir["#{BASE_PATH}/servers/#{@application}/assets/javascripts/*.js"].each do |path|
|
274
|
+
ApplicationView::Validator::JavaScript.validate(path)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
desc "Validates all JSON"
|
279
|
+
task :json do
|
280
|
+
puts "\nValidating JSON in #{@application}..."
|
281
|
+
Dir["./servers/#{@application}/assets/yrb/*json"].each do |json|
|
282
|
+
filename = json.split("/").last
|
283
|
+
path = "#{BASE_PATH}/servers/#{@application}/assets/yrb/#{filename}"
|
284
|
+
ApplicationView::Validator::JSON.validate(path)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
desc "Validates all HTML"
|
289
|
+
task :html do
|
290
|
+
puts "\nValidating HTML in #{@application}..."
|
291
|
+
`rm -rf #{TMP_DIR}`
|
292
|
+
Dir.mkdir(TMP_DIR) rescue Errno::EEXIST
|
293
|
+
Dir["./servers/#{@application}/views/*"].each do |filename|
|
294
|
+
ApplicationView::Validator::HTML.validate(filename) if filename =~ /#{@path}/
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
desc "Validates all JavaScript inside HTML"
|
299
|
+
task :embedded_js do
|
300
|
+
if @path =~ /views/
|
301
|
+
validate_path = @path.gsub(/views\/$/, "/*")
|
302
|
+
else
|
303
|
+
validate_path = "views/*"
|
304
|
+
end
|
305
|
+
puts "\nValidating embedded JavaScript in #{@application}..."
|
306
|
+
Dir["./servers/#{@application}/views/*"].each do |filename|
|
307
|
+
validated_embedded_js(filename) if filename =~ /#{@path}/
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
desc "Validates all javascripts and JSON"
|
312
|
+
task :all => ["validate:javascripts", "validate:json", "validate:html", "validate:embedded_js"]
|
313
|
+
end
|
314
|
+
|
315
|
+
task :set_yrb do
|
316
|
+
@path = "assets/yrb/"
|
317
|
+
end
|
318
|
+
|
319
|
+
task :set_sync do
|
320
|
+
@sync = true
|
321
|
+
end
|
322
|
+
|
323
|
+
desc "Syncs default server"
|
324
|
+
task :sync => [:set_sync, :deploy]
|
325
|
+
|
326
|
+
namespace :sync do
|
327
|
+
create_from_servers do |key, set_task|
|
328
|
+
desc "Syncs application with #{key} server"
|
329
|
+
task key => [set_task, :set_sync, :deploy]
|
330
|
+
end
|
331
|
+
|
332
|
+
create_from_servers do |key, set_task|
|
333
|
+
namespace key do
|
334
|
+
desc "Syncs views to the #{key} server"
|
335
|
+
task :views => [set_task, :set_views, :set_sync, :deploy]
|
336
|
+
|
337
|
+
desc "Syncs all assets to the #{key} server"
|
338
|
+
task :assets => [set_task, :set_assets, :set_sync, :deploy]
|
339
|
+
|
340
|
+
desc "Syncs javascript assets to the #{key} server"
|
341
|
+
task :javascripts => [set_task, :set_javascripts, :set_sync, :deploy]
|
342
|
+
|
343
|
+
desc "Syncs image assets to the #{key} server"
|
344
|
+
task :images => [set_task, :set_images, :set_sync, :deploy]
|
345
|
+
|
346
|
+
desc "Syncs YRB bundles to the #{key} server"
|
347
|
+
task :yrb => [set_task, :set_yrb, :set_sync, :deploy_yrb]
|
348
|
+
|
349
|
+
desc "Syncs everything except images to the the #{key} server"
|
350
|
+
task :code => [set_task, "deploy:#{key}:views", :skip_validation, "deploy:#{key}:javascripts", "deploy:#{key}:yrb"]
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
task :yrb => [:set_yrb, :set_sync, :deploy_yrb]
|
355
|
+
|
356
|
+
create_from_categories(:sync)
|
357
|
+
end
|
358
|
+
|
359
|
+
namespace :deploy do
|
360
|
+
desc "Show shows documentation"
|
361
|
+
task :help do
|
362
|
+
docs = <<-DOCS
|
363
|
+
USAGE: rake deploy [app={application}] [path={path}], [dry_run=true], [dir={directory}], [application_id={app_id}]
|
364
|
+
|
365
|
+
Deploys the local application to the remote YMDP servers. Validates javascript assets beforehand, aborting the deploy in case of validation errors.
|
366
|
+
|
367
|
+
Run without options, the default is to deploy everything to the staging server.
|
368
|
+
|
369
|
+
Specify the application to deploy to:
|
370
|
+
rake deploy app=staging
|
371
|
+
rake deploy app=my
|
372
|
+
rake deploy app=alpha
|
373
|
+
|
374
|
+
NOTE: use subtasks to simplify specifying the application:
|
375
|
+
rake deploy:my
|
376
|
+
rake deploy:alpha
|
377
|
+
rake deploy:staging
|
378
|
+
|
379
|
+
VALID SUBTASKS: my, alpha, staging
|
380
|
+
|
381
|
+
Specify files to deploy:
|
382
|
+
rake deploy path=views
|
383
|
+
rake deploy path=views/settings
|
384
|
+
rake deploy path=assets/javascripts/application.js
|
385
|
+
|
386
|
+
NOTE: use subtasks to simplify the subset of files to deploy,
|
387
|
+
rake deploy:views
|
388
|
+
rake deploy:javascripts
|
389
|
+
|
390
|
+
VALID SUBTASKS: views, assets, javascripts, images, yrb
|
391
|
+
|
392
|
+
|
393
|
+
DOCS
|
394
|
+
# TODO: add more documentation
|
395
|
+
|
396
|
+
puts docs
|
397
|
+
end
|
398
|
+
|
399
|
+
create_from_servers do |key, set_task|
|
400
|
+
desc "Deploys application to #{key} server"
|
401
|
+
task key => [set_task, :deploy]
|
402
|
+
end
|
403
|
+
|
404
|
+
create_from_servers do |key, set_task|
|
405
|
+
namespace key do
|
406
|
+
desc "Deploys views to the #{key} server"
|
407
|
+
task :views => [set_task, :set_views, :deploy]
|
408
|
+
|
409
|
+
desc "Deploys all assets to the #{key} server"
|
410
|
+
task :assets => [set_task, :set_assets, :deploy]
|
411
|
+
|
412
|
+
desc "Deploys javascript assets to the #{key} server"
|
413
|
+
task :javascripts => [set_task, :set_javascripts, :deploy]
|
414
|
+
|
415
|
+
desc "Deploys image assets to the #{key} server"
|
416
|
+
task :images => [set_task, :set_images, :deploy]
|
417
|
+
|
418
|
+
desc "Deploys YRB bundles to the #{key} server"
|
419
|
+
task :yrb => [set_task, :set_yrb, :deploy_yrb]
|
420
|
+
|
421
|
+
desc "Deploys everything except images to the the #{key} server"
|
422
|
+
task :code => [set_task, "deploy:#{key}:views", :skip_validation, "deploy:#{key}:javascripts", "deploy:#{key}:yrb"]
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
task :yrb => [:set_yrb, :deploy_yrb]
|
427
|
+
|
428
|
+
create_from_categories(:deploy)
|
429
|
+
end
|
430
|
+
|
431
|
+
|
432
|
+
# rake create app=my path=./my
|
433
|
+
# rake create app=staging path=staging
|
434
|
+
|
435
|
+
desc "Creates a new local copy of a YMDP application"
|
436
|
+
task :create do
|
437
|
+
puts "about to create_directory for #{@application}"
|
438
|
+
time("Created") do
|
439
|
+
create_directory_from_application(@application, @path)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
# rake create:my path=./my
|
444
|
+
# rake create:staging path=staging
|
445
|
+
|
446
|
+
namespace :create do
|
447
|
+
desc "Create all applications"
|
448
|
+
task :all do
|
449
|
+
time("Created all applications") do
|
450
|
+
SERVERS.each do |key, values|
|
451
|
+
create_directory_from_application(values["server"])
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
create_from_servers do |key, set_task|
|
457
|
+
desc "Creates local application from #{key} server"
|
458
|
+
task key do
|
459
|
+
@application = key.to_s
|
460
|
+
Rake::Task["create"].invoke
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
# TASKS TO SET UP ENVIRONMENT
|
468
|
+
|
469
|
+
CATEGORIES.each do |name, path|
|
470
|
+
task "set_#{name}" do
|
471
|
+
@path = "#{path}/#{@path}"
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
|
476
|
+
# END OF RAKE TASKS
|
477
|
+
|
478
|
+
def invoke_ymdt(command_string, application, path="", return_results=false)
|
479
|
+
dir = "./servers/" << application
|
480
|
+
path = dir << "/" << path
|
481
|
+
|
482
|
+
command = []
|
483
|
+
command << command_string
|
484
|
+
command << "\"#{path}\""
|
485
|
+
command << "-s" if @sync
|
486
|
+
|
487
|
+
ymdt_command(command, return_results)
|
488
|
+
end
|
489
|
+
|
490
|
+
def ymdt_command(commands, return_results=false)
|
491
|
+
command = []
|
492
|
+
# command << "php"
|
493
|
+
command << "./script/ymdt"
|
494
|
+
|
495
|
+
command << commands
|
496
|
+
|
497
|
+
command << "-u#{@username}"
|
498
|
+
command << "-p#{@password}"
|
499
|
+
command_string = command.join(" ")
|
500
|
+
|
501
|
+
display_string = command_string.dup
|
502
|
+
display_string.gsub!(@username, "[username]")
|
503
|
+
display_string.gsub!(@password, "[password]")
|
504
|
+
|
505
|
+
puts
|
506
|
+
puts display_string
|
507
|
+
|
508
|
+
unless @dry_run
|
509
|
+
if return_results
|
510
|
+
`#{command_string}`
|
511
|
+
else
|
512
|
+
puts
|
513
|
+
system command_string
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
def validated_embedded_js(path)
|
519
|
+
# jslint only accepts files, later we can hack it to accept stdin pipes
|
520
|
+
doc = open(path) { |f|
|
521
|
+
Hpricot(f)
|
522
|
+
}
|
523
|
+
|
524
|
+
js_fragment_path = TMP_DIR + "/#{File.basename(path)}_js_fragment"
|
525
|
+
|
526
|
+
File.open(js_fragment_path,'w') do |f|
|
527
|
+
(doc / "script").each { |js| f.puts js.inner_html + "\n\n" }
|
528
|
+
end
|
529
|
+
|
530
|
+
ApplicationView::Validator::JavaScript.validate(js_fragment_path)
|
531
|
+
system "rm #{js_fragment_path}"
|
532
|
+
end
|
533
|
+
|
534
|
+
def deploy(application, path)
|
535
|
+
puts "\nDeploying #{application}: #{path}"
|
536
|
+
|
537
|
+
Rake::Task["validate:html"].invoke if validate_html?
|
538
|
+
Rake::Task["validate:embedded_js"].invoke if validate_embedded_js?
|
539
|
+
Rake::Task["validate:#{application}:javascripts"].invoke if validate_js_assets?
|
540
|
+
Rake::Task["validate:#{application}:json"].invoke if validate_json_assets?
|
541
|
+
|
542
|
+
puts "About to invoke_ymdt: put, #{application}, #{path}"
|
543
|
+
invoke_ymdt("put", application, path)
|
544
|
+
end
|
545
|
+
|
546
|
+
def deploy_path(application, path)
|
547
|
+
puts "\nDeploying #{application}: #{path}"
|
548
|
+
|
549
|
+
Rake::Task["validate:html"].invoke if validate_html?
|
550
|
+
Rake::Task["validate:embedded_js"].invoke if validate_embedded_js?
|
551
|
+
Rake::Task["validate:#{application}:javascripts"].invoke if validate_js_assets?
|
552
|
+
Rake::Task["validate:#{application}:json"].invoke if validate_json_assets?
|
553
|
+
|
554
|
+
dir = "./servers/#{application}"
|
555
|
+
|
556
|
+
if path =~ /\/$/
|
557
|
+
deploy(application, path)
|
558
|
+
else
|
559
|
+
path =~ /^(.*)\/.*$/
|
560
|
+
short_path = $1
|
561
|
+
|
562
|
+
full_path = "#{dir}/#{short_path}/**"
|
563
|
+
|
564
|
+
Dir[full_path].each do |file|
|
565
|
+
new_path = file.gsub(/#{dir}\//, "")
|
566
|
+
|
567
|
+
if file =~ Regexp.new(path)
|
568
|
+
puts file
|
569
|
+
invoke_ymdt("put", application, new_path)
|
570
|
+
end
|
571
|
+
end
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
def deploy_yrb(application, path, options={})
|
576
|
+
lang = options[:lang]
|
577
|
+
view = options[:view]
|
578
|
+
|
579
|
+
if lang
|
580
|
+
new_path = "#{path}/keys_#{lang}.json"
|
581
|
+
deploy_path(application, new_path)
|
582
|
+
else
|
583
|
+
deploy_path(application, path)
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
def list(application, path)
|
588
|
+
invoke_ymdt("ls", application, path, true)
|
589
|
+
end
|
590
|
+
|
591
|
+
def check_asset_ids(application, path)
|
592
|
+
result = list(application, path)
|
593
|
+
|
594
|
+
lines = result.split("\n")
|
595
|
+
wrong_lines = []
|
596
|
+
|
597
|
+
lines.each do |line|
|
598
|
+
if line =~ /om\/assets\/(.*)\//
|
599
|
+
match = $1
|
600
|
+
|
601
|
+
if match =~ /#{@assets_id}/
|
602
|
+
puts line
|
603
|
+
else
|
604
|
+
wrong_lines << line
|
605
|
+
end
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
wrong_lines
|
610
|
+
end
|
611
|
+
|
612
|
+
def report_asset_ids(application, path)
|
613
|
+
time("Listed asset ids") do
|
614
|
+
wrong_ids = []
|
615
|
+
wrong_lines = check_asset_ids(application, path)
|
616
|
+
|
617
|
+
puts
|
618
|
+
|
619
|
+
if wrong_lines.any?
|
620
|
+
message = "Some assets do not have the specified asset ID of #{@assets_id}"
|
621
|
+
puts message
|
622
|
+
wrong_lines.each do |line|
|
623
|
+
if line =~ /om\/assets\/(.*)\//
|
624
|
+
match = $1
|
625
|
+
if match !~ /#{@assets_id}/
|
626
|
+
wrong_id = match.split("/").first
|
627
|
+
wrong_ids << wrong_id unless wrong_ids.include?(wrong_id)
|
628
|
+
end
|
629
|
+
end
|
630
|
+
puts line
|
631
|
+
end
|
632
|
+
puts
|
633
|
+
puts "The above assets do not have the specified asset ID of #{@assets_id}"
|
634
|
+
puts
|
635
|
+
if wrong_ids.any?
|
636
|
+
puts "Here are the other asset IDs used:"
|
637
|
+
wrong_ids.each do |wrong_id|
|
638
|
+
puts " " + wrong_id;
|
639
|
+
first_index = @assets_id.split("_").last
|
640
|
+
second_index = wrong_id.split("_").last
|
641
|
+
if second_index.to_i > first_index.to_i
|
642
|
+
puts
|
643
|
+
puts " This index is higher than the stored application ID."
|
644
|
+
puts " You can update your servers.yml with the following settings:"
|
645
|
+
puts
|
646
|
+
puts "servers:"
|
647
|
+
puts " #{@application}:"
|
648
|
+
puts " dir: #{@dir}"
|
649
|
+
puts " application_id: #{@application_id}"
|
650
|
+
puts " assets_id: #{wrong_id}"
|
651
|
+
else
|
652
|
+
puts
|
653
|
+
puts " This index is lower than the stored application ID."
|
654
|
+
puts
|
655
|
+
puts " Run rake fix_assets:#{application} to update remote assets"
|
656
|
+
end
|
657
|
+
end
|
658
|
+
end
|
659
|
+
else
|
660
|
+
message = "All assets have the specified asset ID of #{@assets_id}"
|
661
|
+
end
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
def fix_assets(application, path)
|
666
|
+
time("Fixed assets") do
|
667
|
+
Rake::Task["validate:all"].invoke unless @skip_validation
|
668
|
+
@skip_validation = true
|
669
|
+
|
670
|
+
wrong_lines = check_asset_ids(application, path)
|
671
|
+
|
672
|
+
if wrong_lines.any?
|
673
|
+
wrong_lines.each do |line|
|
674
|
+
filename = line.split(" ")[0]
|
675
|
+
|
676
|
+
puts deploy(application, filename)
|
677
|
+
end
|
678
|
+
else
|
679
|
+
message = "All assets are up to date"
|
680
|
+
end
|
681
|
+
end
|
682
|
+
end
|
683
|
+
|
684
|
+
def create_directory_from_application(application, path="")
|
685
|
+
time("Done creating #{application}: #{path}") do
|
686
|
+
puts "Creating #{application}: #{path}"
|
687
|
+
application_id = SERVERS[application]["application_id"]
|
688
|
+
|
689
|
+
dir = "./servers/#{application}"
|
690
|
+
|
691
|
+
if path == ""
|
692
|
+
path = dir
|
693
|
+
else
|
694
|
+
path = "./" << path
|
695
|
+
end
|
696
|
+
|
697
|
+
command = []
|
698
|
+
|
699
|
+
command << "get"
|
700
|
+
command << path
|
701
|
+
command << "-a#{application_id}"
|
702
|
+
|
703
|
+
ymdt_command(command)
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
707
|
+
def please_install_rhino
|
708
|
+
output = <<-DOC
|
709
|
+
NOTE:
|
710
|
+
|
711
|
+
You must have Rhino installed in your classpath to validate javascripts, which is required to deploy. Download Rhino from:
|
712
|
+
|
713
|
+
http://www.mozilla.org/rhino/download.html
|
714
|
+
|
715
|
+
To put Rhino into your Java classpath, run:
|
716
|
+
|
717
|
+
mkdir -p ~/Library/Java/Extensions/
|
718
|
+
cp rhino****/js.jar ~/Library/Java/Extensions/
|
719
|
+
DOC
|
720
|
+
end
|