Class: Vapid::CLI

Inherits:
Thor show all
Includes:
Thor::Actions
Defined in:
lib/vapid/cli.rb

Overview

Command line interface

Constant Summary collapse

GUARDFILE =
%(
  guard 'livereload' do
    watch('.cache/livereload.txt')
    watch(%r{templates/.+})
    watch(%r{assets/.+})
  end
).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



22
23
24
# File 'lib/vapid/cli.rb', line 22

def self.source_root
  "#{File.dirname(__FILE__)}/generator_template"
end

Instance Method Details

#build(target = ".") ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vapid/cli.rb', line 54

def build(target = ".")
  inside_target(target) do
    Models.migrate!
    ensure_user_exists(options.)

    say "== Parsing templates for fields"
    template_files = files("templates")
    Builder.build!(template_files) do |filepath|
      say_status :parse, filepath
    end
    say "== Build complete"
  end
end

#deploy(target = ".") ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vapid/cli.rb', line 70

def deploy(target = ".")
  inside_target(target) do
    @api_key = ensure_api_key
    site_id = ensure_site_id

    project_files = files("templates", "assets")
    Deployer.new(@api_key, site_id).deploy(project_files) do |message, color, status|
      if status
        say_status status, message, color
      else
        say "== #{message}", color
      end
    end
  end
end

#new(target) ⇒ Object



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

def new(target)
  say "== Creating a new Vapid project in #{expanded_target(target)}"
  directory ".", target
  inside_target(target) do
    run "bundle install"
  end
end

#server(target = ".") ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/vapid/cli.rb', line 40

def server(target = ".")
  say "== The Vapid server is loading"
  inside_target(target) do
    fork do
      Guard.start guardfile_contents: GUARDFILE, watchdir: target, no_interactions: true
    end
    Server.run! options.merge directory: target
  end
  say "== The Vapid server is now shut down"
end

#versionObject



88
89
90
# File 'lib/vapid/cli.rb', line 88

def version
  say "Vapid #{Vapid::VERSION}"
end