Class: Mwc::Commands::Watch

Inherits:
Thor::Group
  • Object
show all
Includes:
Utils::Command, Thor::Actions
Defined in:
lib/mwc/commands/watch.rb

Overview

:nodoc:

Constant Summary collapse

DESIRE_FILES =
/\.(h|c|cpp|js)$/.freeze

Instance Method Summary collapse

Methods included from Utils::Command

included

Instance Method Details

#prepareObject



22
23
24
25
26
27
28
# File 'lib/mwc/commands/watch.rb', line 22

def prepare
  @stopped = false
  @dirs = [
    Mwc.root.join('src'),
    Mwc.root.join('include')
  ].map(&:to_s)
end

#setup_listenerObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/mwc/commands/watch.rb', line 34

def setup_listener
  @listener = Listen.to(*@dirs, only: DESIRE_FILES) do |*_|
    Mwc.use(parent_options['env']) do
      # TODO: Allow change output directory
      empty_directory('dist')

      compile
    end
  end
end

#setup_tasksObject



30
31
32
# File 'lib/mwc/commands/watch.rb', line 30

def setup_tasks
  Tasks.new
end

#startObject



45
46
47
48
49
50
51
# File 'lib/mwc/commands/watch.rb', line 45

def start
  puts 'Starting watch file changes...'
  @listener.start

  Signal.trap(:INT) { exit }
  sleep
end