ymdp 0.0.12 → 0.0.13

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