Class: JBundle::CommandLine

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/jbundle/command_line.rb

Constant Summary collapse

AFTER_INIT_MESSAGE =
%(
Done. Try it!

jbundle s
open test/index.html

Then package your work

jsbundle
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



55
56
57
# File 'lib/jbundle/command_line.rb', line 55

def self.source_root
  ::File.dirname(__FILE__)
end

Instance Method Details

#bundleObject



15
16
17
18
19
20
21
22
# File 'lib/jbundle/command_line.rb', line 15

def bundle
  begin
    JBundle.config_from_file(options[:jfile])
    JBundle.write!
  rescue JBundle::NoJFileError => boom
    puts boom.message
  end
end

#init(name) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/jbundle/command_line.rb', line 72

def init(name)
  @name = name
  @klass_name = name.sub('.js', '').split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
  
  template('templates/jfile.tt', "JFile")
  empty_directory 'src'
  template('templates/license.tt', "src/license.txt")
  template('templates/lib.tt', "src/#{name}")
  if options[:tests] == 'qunit'
    empty_directory 'test'
    template('templates/index.tt', "test/index.html")
    template('templates/tests.tt', "test/tests.js")
    copy_file 'templates/qunit.tt', 'test/qunit.js'
    copy_file 'templates/qunit_css.tt', 'test/qunit.css'
  end
  empty_directory 'dist'
  say AFTER_INIT_MESSAGE, :yellow
end

#serverObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jbundle/command_line.rb', line 27

def server
  require 'rack'
  JBundle.config_from_file(options[:jfile])
  say "Starting test server on http://localhost:#{options[:port]}. Available bundles:", :yellow
  JBundle.config.bundles_and_files.each do |f|
    say "- /#{f.name}", :green
  end

  handler = Rack::Handler.default
  downward = false
  ['INT', 'TERM', 'QUIT'].each do |signal|
    trap(signal) do
      exit! if downward
      downward = true
      handler.shutdown if handler.respond_to?(:shutdown)
      Process.wait rescue nil
      say 'Shutting down test server', :yellow
      exit!
    end
  end
  handler.run JBundle::Server.new, {:Port => options[:port]}
end

#versionObject



51
52
53
# File 'lib/jbundle/command_line.rb', line 51

def version
  say JBundle::VERSION, :green
end