Sha256: a8ecec6661c58b492b6d55f3066a230adb7a063567c2c569b76df741bab12c19

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require "thor"
require "listen"

module Linner
  class Command < Thor
    include Thor::Actions
    map "-v" => :version

    def self.source_root
      File.dirname(__FILE__)
    end

    desc "version", "show version"
    def version
      puts Linner::VERSION
    end

    desc "build", "build assets"
    def build
      Linner.compile = true

      clean

      Notifier.profile do
        Linner.perform
      end
    end

    desc "watch", "watch assets"
    def watch
      trap :INT do
        Notifier.exit
        Process.kill("QUIT", 0)
      end

      clean

      @proc = Proc.new do |modified, added, removed|
        begin
          Notifier.profile{ Linner.perform }
        rescue
          Notifier.error $!
        end
      end
      @proc.call

      Listen.to env.app_folder, env.vendor_folder, env.test_folder do |modified, added, removed|
        is_include_partial_styles = (modified + added + removed).any? do |path|
          Asset.new(path).stylesheet? and File.basename(path).start_with? "_"
        end
        Linner.cache.reject! {|k, v| v.stylesheet?} if is_include_partial_styles
        @proc.call
      end

      @reactor = Reactor.supervise_as(:reactor).actors.first
      Listen.to env.public_folder, relative_path: true do |modified, added, removed|
        @reactor.reload_browser(modified + added + removed)
      end

      sleep
    end

    desc "clean", "clean assets"
    def clean
      FileUtils.rm_rf Dir.glob("#{env.public_folder}/*")
    end

    desc "new", "create the skeleton of project"
    def new(name)
      directory('templates', name)
      chmod("#{name}/bin/server", 0755)
    end

  private
    def env
      Linner.env
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linner-0.4.0 lib/linner/command.rb