Class: Xing::Tasks::Develop

Inherits:
Tasklib
  • Object
show all
Defined in:
lib/xing/tasks/develop.rb

Constant Summary collapse

DEFAULT_RELOAD_PORT =
35729
DEFAULT_RAILS_PORT =
3000
DEFAULT_MOBILE_PORT =
9000
DEFAULT_STATIC_PORT =
9292

Instance Method Summary collapse

Methods inherited from Tasklib

#edict_task

Instance Method Details

#choose_output_managerObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/xing/tasks/develop.rb', line 32

def choose_output_manager
  begin
    require 'xing/managers/child'
    require 'xing/managers/tmux'
    if Managers::Tmux.available?
      Managers::TmuxPane.new
    else
      ChildManager.new.tap do |mngr|
        at_exit{ mngr.kill_all }
      end
    end
  end.tap do |mgr|
    puts "Using #{mgr.class.name}"
  end
end

#default_configurationObject



48
49
50
51
52
# File 'lib/xing/tasks/develop.rb', line 48

def default_configuration
  @port_offset ||= get_port_offset
  @manager ||= choose_output_manager
  super
end

#defineObject



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
140
141
142
143
144
145
146
# File 'lib/xing/tasks/develop.rb', line 62

def define
  in_namespace do
    desc "Launch a browser connected to a running development server"
    edict_task :launch_browser, Edicts::LaunchBrowser

    edict_task :grunt_watch, Edicts::StartChild do |gw|
      gw.manager = manager
      gw.label = "Grunt"
      gw.child_task = in_namespace('service:grunt_watch').first
    end

    edict_task :compass_watch, Edicts::StartChild do |cw|
      cw.manager = manager
      cw.label = "Compass"
      cw.child_task = in_namespace('service:compass_watch').first
    end

    edict_task :rails_server, Edicts::StartChild do |rs|
      rs.manager = manager
      rs.label = "Rails"
      rs.child_task = in_namespace('service:rails_server').first
    end

    edict_task :sidekiq, Edicts::StartChild do |sk|
      sk.manager = manager
      sk.label = "Sidekiq"
      sk.child_task = in_namespace('service:sidekiq').first
    end

    edict_task :static_assets, Edicts::StartChild do |sa|
      sa.manager = manager
      sa.label = "Static"
      sa.child_task = in_namespace('service:static_assets').first
    end

    namespace :service do
      edict_task :grunt_watch, Edicts::CleanRun do |gw|
        gw.dir = "frontend"
        gw.shell_cmd = %w{bundle exec node_modules/.bin/grunt delta:develop}
        gw.env_hash = {"CUSTOM_CONFIG_DIR" => config_dir}
      end
      task :grunt_watch => 'frontend:setup'

      edict_task :compass_watch, Edicts::CleanRun do |cw|
        cw.dir = "frontend"
        cw.shell_cmd = %w{bundle exec compass watch}
      end

      edict_task :rails_server, Edicts::CleanRun do |rs|
        words = %w{bundle exec rails server}
        words << "-p#{rails_server_port}" #ok

        rs.dir = "backend"
        rs.shell_cmd = words
      end
      task :rails_server => 'backend:setup'

      edict_task :sidekiq, Edicts::CleanRun do |sk|
        sk.dir = "backend"
        sk.shell_cmd = %w{bundle exec sidekiq}
      end

      edict_task :static_assets, Edicts::CleanRun do |sa|
        words = %w{bundle exec rackup}
        words << "-p#{static_server_port}" #ok
        words << "static-app.ru"

        sa.dir = "backend"
        sa.shell_cmd = words
        sa.env_hash = {
          "LRD_BACKEND_PORT" => "#{rails_server_port}", # deprecate for 1.0
          "XING_BACKEND_PORT" => "#{rails_server_port}"
        }
      end
    end

    task :wait do
      manager.wait_all
    end

    task :startup => [:grunt_watch, :compass_watch, :sidekiq, :static_assets, :rails_server, :launch_browser]

    task :all => [:startup, :wait]
  end
end

#get_port_offsetObject



22
23
24
25
26
27
28
29
30
# File 'lib/xing/tasks/develop.rb', line 22

def get_port_offset
  if !ENV['PORT_OFFSET'].nil?
    ENV['PORT_OFFSET'].to_i.tap do |offset|
      puts "Shifting server ports by #{offset}"
    end
  else
    0
  end
end

#resolve_configurationObject



54
55
56
57
58
59
60
# File 'lib/xing/tasks/develop.rb', line 54

def resolve_configuration
  super
  self.reload_server_port = DEFAULT_RELOAD_PORT + port_offset if field_unset?(:reload_server_port)
  self.rails_server_port  = DEFAULT_RAILS_PORT  + port_offset if field_unset?(:rails_server_port)
  self.mobile_server_port = DEFAULT_MOBILE_PORT + port_offset if field_unset?(:mobile_server_port)
  self.static_server_port = DEFAULT_STATIC_PORT + port_offset if field_unset?(:static_server_port)
end