Class: Embork::CLI

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

Instance Method Summary collapse

Instance Method Details

#build(environment = :production) ⇒ Object



64
65
66
67
68
# File 'lib/embork/cli.rb', line 64

def build(environment = :production)
  borkfile = Embork::Borkfile.new options[:borkfile], environment
  builder = Embork::Builder.new(borkfile)
  builder.build
end

#cleanObject



71
72
73
74
# File 'lib/embork/cli.rb', line 71

def clean
  borkfile = Embork::Borkfile.new options[:borkfile]
  FileUtils.rm_rf File.expand_path('build', borkfile.project_root)
end

#clean_cacheObject



77
78
79
80
# File 'lib/embork/cli.rb', line 77

def clean_cache
  borkfile = Embork::Borkfile.new options[:borkfile]
  FileUtils.rm_rf File.expand_path('.cache', borkfile.project_root)
end

#create(package_name) ⇒ Object



12
13
14
15
# File 'lib/embork/cli.rb', line 12

def create(package_name)
  puts %{Creating embork app in "%s"} % package_name
  Embork::Generator.new(package_name, options).generate
end

#depsObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/embork/cli.rb', line 91

def deps
  if !system('which node 2>&1 > /dev/null')
    puts "Please install node and npm before continuing."
    exit 1
  elsif !system('which npm 2>&1 > /dev/null')
    puts "Please install npm before continuing."
    exit 1
  end
  borkfile = Embork::Borkfile.new options[:borkfile]
  Dir.chdir borkfile.project_root do
    system('npm install')
    system('PATH=$(npm bin):$PATH bower install')
  end
end

#hintObject



83
84
85
86
87
88
# File 'lib/embork/cli.rb', line 83

def hint
  borkfile = Embork::Borkfile.new options[:borkfile]
  Dir.chdir borkfile.project_root do
    system('PATH=$(npm bin):$PATH jshint app tests')
  end
end

#phrender(environment = :development) ⇒ Object



33
34
35
36
# File 'lib/embork/cli.rb', line 33

def phrender(environment = :development)
  borkfile = Embork::Borkfile.new options[:borkfile], environment
  Embork::Phrender.new(borkfile, options).run_webrick
end

#server(environment = :development) ⇒ Object



23
24
25
26
# File 'lib/embork/cli.rb', line 23

def server(environment = :development)
  borkfile = Embork::Borkfile.new options[:borkfile], environment
  Embork::Server.new(borkfile, options).run_webrick
end

#test(environment = :development) ⇒ Object



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

def test(environment = :development)
  borkfile = Embork::Borkfile.new options[:borkfile], environment
  min = 52000
  max = 65000
  port = (Random.rand * (max - min) + min).to_i
  host = '0.0.0.0'

  server_options = {
    :host => host,
    :port => port,
    :enable_tests => true,
    :disable_logging => true
  }

  server = Embork::Server.new(borkfile, server_options)

  server_thread = Thread.new{ server.run_webrick }

  test_url = "http://%s:%s/tests.html" % [ host, port ]
  Qunit::Runner.new(test_url).run(10000)
  server_thread.kill
end