Class: Tay::CLI::Root
- Inherits:
-
Thor
- Object
- Thor
- Tay::CLI::Root
- Includes:
- Helpers, Thor::Actions
- Defined in:
- lib/tay/cli.rb,
lib/tay/cli/new.rb,
lib/tay/cli/build.rb,
lib/tay/cli/watch.rb,
lib/tay/cli/minify.rb,
lib/tay/cli/package.rb,
lib/tay/cli/validate.rb
Constant Summary
Constants included from Helpers
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #minify ⇒ Object
- #new(name) ⇒ Object
- #package ⇒ Object
- #validate ⇒ Object
- #watch ⇒ Object
Class Method Details
.source_root ⇒ Object
24 25 26 |
# File 'lib/tay/cli.rb', line 24 def self.source_root File.('cli/templates', File.dirname(__FILE__)) end |
Instance Method Details
#build ⇒ Object
9 10 11 12 |
# File 'lib/tay/cli/build.rb', line 9 def build builder = Builder.new(spec, base_dir, build_dir) builder.build! end |
#minify ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tay/cli/minify.rb', line 13 def minify unless ['skip-js'] begin require 'uglifier' Dir[build_dir.join('**/*.js')].each do |path| content = File.read(path) File.open(path, 'w') do |f| f.write Uglifier.compile(content) end end rescue LoadError say('ERROR: please add the uglifier gem to your Gemfile to minfy javascripts', :red) end end unless ['skip-css'] begin require 'yui/compressor' Dir[build_dir.join('**/*.css')].each do |path| content = File.read(path) File.open(path, 'w') do |f| f.write YUI::CssCompressor.new.compress(content) end end rescue LoadError say('ERROR: please add the yui-compressor gem to your Gemfile to minfy css files', :red) end end end |
#new(name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tay/cli/new.rb', line 13 def new(name) outdir = Pathname.new(Utils.filesystem_name(name)) create_directory_structure(outdir) template('Gemfile', outdir.join('Gemfile')) unless ['no-gemfile'] copy_file('gitignore', outdir.join('.gitignore')) unless ['no-gitignore'] template('Tayfile', outdir.join('Tayfile'), { 'name' => name }.merge()) end |
#package ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tay/cli/package.rb', line 11 def package unless %{zip crx} .include?(['type']) raise InvalidPackageType.new("Invalid package type '#{['type']}'") end packager = Packager.new(spec, base_dir, build_dir) if packager.private_key_exists? say("Using private key at #{Utils.relative_path_to(packager.full_key_path)}", :green) else say("Creating private key at #{Utils.relative_path_to(packager.full_key_path)}", :yellow) packager.write_new_key end empty_directory(base_dir.join('tmp')) empty_directory(base_dir.join('pkg')) temp_pkg_path = base_dir.join('tmp', 'package') temp_pkg_path.unlink if temp_pkg_path.exist? packager.send("write_#{['type']}".to_sym, temp_pkg_path) filename = Utils.filesystem_name(spec.name) + '-' + spec.version + '.' + ['type'] pkg_path = base_dir.join('pkg', filename) copy_file(temp_pkg_path, pkg_path) say("The extension's ID is #{packager.extension_id}") say("Wrote #{pkg_path.size} bytes to #{Utils.relative_path_to(pkg_path)}", :green) temp_pkg_path.unlink end |
#validate ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tay/cli/validate.rb', line 9 def validate validator = SpecificationValidator.new(spec, build_dir) validator. = lambda do |type, | say(type.upcase + ": " + , type == 'warn' ? :yellow : :red) end if validator.validate! say("All OK!", :green) end end |
#watch ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tay/cli/watch.rb', line 9 def watch begin require 'guard' require 'guard/tay' rescue LoadError say('ERROR: please add the guard and guard-tay gems to your Gemfile to enable auto compilation', :red) return end template_path = "#{::Guard.locate_guard('tay')}/lib/guard/tay/templates/Guardfile" copy_file(template_path, File.('Guardfile', '.')) say('Auto-compilation is now set up. Run `guard` to start watching for changes.', :green) end |