Sha256: daaccc9edb575b3b5adf99c6da994950136ba7373046932014c1aa1549d20e9c

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 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 { Linner.perform }
    end

    desc "watch", "watch assets"
    def watch
      trap(:INT) { exit! }
      clean
      perform_proc.call
      watch_for_perform
      watch_for_reload
      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

    def perform_proc
      @proc ||= Proc.new do
        begin
          Notifier.profile{ Linner.perform }
        rescue
          Notifier.error $!
        end
      end
    end

    def watch_for_perform
      Listen.to env.watched_paths do |modified, added, removed|
        Linner.cache.expire_by(modified + added + removed)
        perform_proc.call
      end
    end

    def watch_for_reload
      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
    end

    def exit!
      Notifier.exit
      Kernel::exit
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
linner-0.4.6 lib/linner/command.rb
linner-0.4.5 lib/linner/command.rb
linner-0.4.4 lib/linner/command.rb
linner-0.4.3 lib/linner/command.rb
linner-0.4.2 lib/linner/command.rb