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



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

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

#cleanObject



73
74
75
76
# File 'lib/embork/cli.rb', line 73

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

#clean_cacheObject



79
80
81
82
# File 'lib/embork/cli.rb', line 79

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



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

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



85
86
87
88
89
90
# File 'lib/embork/cli.rb', line 85

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 = 'localhost'

  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