Class: Bookbinder::Commands::Watch

Inherits:
Object
  • Object
show all
Defined in:
lib/bookbinder/commands/watch.rb

Instance Method Summary collapse

Constructor Details

#initialize(streams, middleman_runner: nil, output_locations: nil, config_fetcher: nil, config_decorator: nil, file_system_accessor: nil, preprocessor: nil, cloner: nil, section_repository: nil, directory_preparer: nil, repo_restrictions: []) ⇒ Watch

Returns a new instance of Watch.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bookbinder/commands/watch.rb', line 4

def initialize(streams,
               middleman_runner: nil,
               output_locations: nil,
               config_fetcher: nil,
               config_decorator: nil,
               file_system_accessor: nil,
               preprocessor: nil,
               cloner: nil,
               section_repository: nil,
               directory_preparer: nil,
               repo_restrictions: [])
  @streams = streams
  @middleman_runner = middleman_runner
  @output_locations = output_locations
  @config_fetcher = config_fetcher
  @config_decorator = config_decorator
  @file_system_accessor = file_system_accessor
  @preprocessor = preprocessor
  @cloner = cloner
  @section_repository = section_repository
  @directory_preparer = directory_preparer
  @repo_restrictions = repo_restrictions
end

Instance Method Details

#runObject



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
# File 'lib/bookbinder/commands/watch.rb', line 28

def run
  watch_config = config_fetcher.fetch_config

  directory_preparer.prepare_directories(
    watch_config,
    File.expand_path('../../../../', __FILE__),
    output_locations,
    cloner
  )
  sections = section_repository.fetch(
    configured_sections: filter_sections(watch_config.sections),
    destination_dir: output_locations.cloned_preprocessing_dir,
    cloner: cloner,
    streams: streams
  )
  preprocessor.preprocess(
    sections,
    output_locations,
    output_streams: streams,
    config: watch_config
  )
  if file_system_accessor.file_exist?('redirects.rb')
    file_system_accessor.copy('redirects.rb', output_locations.final_app_dir)
  end

  middleman_runner.run("server --watcher-force-polling --watcher-latency=5.0",
    output_locations: output_locations,
    config: config_decorator.generate(watch_config, sections),
    local_repo_dir: File.expand_path('..'),
    streams: streams,
    subnavs: subnavs(sections),
    product_info: product_infos(sections)
  ).exitstatus
end