Class: Phlexite::Cli::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/phlexite/cli/cli.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#buildObject



28
29
30
31
32
33
34
35
36
# File 'lib/phlexite/cli/cli.rb', line 28

def build
  spin do
    file = options[:script] || "./build.rb"
    cmd = "#{RbConfig.ruby} #{file}"
    cmd = "bundle exec #{cmd}" if File.file? "Gemfile"

    system(cmd)
  end
end

#devObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/phlexite/cli/cli.rb', line 42

def dev
  build_dir = options[:build_dir] || "_build"

  build

  port = options[:port] || 3000
  puts "\e[1m>  Starting server on port #{port}\e[0m"
  server = Server.start port, build_dir

  puts "\e[1m>  Starting watcher (excluding #{build_dir} and gitignored files)\e[0m"

  excluded_paths = ([File.join(build_dir, "**", "*.*")] +
                   (File.read(".gitignore") || "").split("\n"))
    .map { |p| Glob.new(p).to_regexp }
  listener = Listen.to(".", ignore: excluded_paths) do |modified, added, removed|
    build
  end
  listener.start
  server.join
end