Module: Yass::CLI::Runner

Defined in:
lib/yass/cli/runner.rb

Constant Summary collapse

INIT_DIR =
Pathname.new(File.expand_path(File.join("..", "..", "..", "..", "docs-src"), __FILE__))

Class Method Summary collapse

Class Method Details

.build(config, argv:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/yass/cli/runner.rb', line 8

def self.build(config, argv:)
  config.cwd = Helpers.get_working_dir! argv
  site = Site.new(config)
  Generator.new(site).generate!
  return 0
rescue => e
  raise e if config.debug
  config.stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end

.init(config, argv:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yass/cli/runner.rb', line 19

def self.init(config, argv:)
  config.cwd = Helpers.get_working_dir! argv
  site = Site.new(config)

  Dir[INIT_DIR.join("**/*.*")].each do |path|
    dest = site.cwd.join Pathname.new(path).relative_path_from(INIT_DIR)
    site.stdout.puts "Creating #{dest}"
    FileUtils.mkdir_p dest.dirname unless dest.dirname.exist?
    FileUtils.cp(path, dest) unless dest.exist?
  end
  return 0
rescue => e
  raise e if config.debug
  config.stderr.puts "#{e.class.name}: #{e.message}"
  return 1
end

.watch(config, argv:) {|watcher| ... } ⇒ Object

Yields:

  • (watcher)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yass/cli/runner.rb', line 36

def self.watch(config, argv:)
  config.cwd = Helpers.get_working_dir! argv
  site = Site.new(config)

  site.stdout.puts "Watching for changes..."
  watcher = Filewatcher.new([site.src_dir, site.layout_dir, site.template_dir].map(&:to_s))
  yield watcher if block_given?

  Yass::CLI::Runner.build(config, argv: argv)
  watcher.watch do |changes|
    files = changes.map { |f, _| Pathname.new(f).relative_path_from(site.cwd).to_s }.reject { |f| Dir.exist? f }
    # TODO use \r?
    site.stdout.puts "Building #{files.join ", "}"
    site.clear_cache!
    Yass::CLI::Runner.build(config, argv: argv)
  end
  return 0
end