Sha256: cb087d1f3431f1b79370d97014a600cb524a0ec84807585162684b74164d245e

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

module Inesita
  class CLI < Thor
    include Thor::Actions

    check_unknown_options!

    namespace :watch

    desc 'watch [OPTIONS]', 'Watch files and build Inesita app'

    method_option :force,
                  aliases: :f,
                  type: :boolean,
                  default: true,
                  desc: 'force overwrite'

    method_option :destination_dir,
                  aliases: :d,
                  type: :string,
                  default: Inesita::Config::BUILD_DIR,
                  desc: 'destination directory'

    method_option :source_dir,
                  aliases: :s,
                  type: :string,
                  default: Inesita::Config::APP_DIR,
                  desc: 'source (app) dir'

    method_option :static_dir,
                  aliases: :t,
                  type: :string,
                  default: Inesita::Config::STATIC_DIR,
                  desc: 'static dir'

    method_option :dist_source_dir,
                  aliases: :b,
                  type: :string,
                  default: Inesita::Config::APP_DIST_DIR,
                  desc: 'source (app) dir for dist build'

    def watch
      puts 'building...'
      safe_build
      puts 'done.'
      Listen.to(options[:source_dir]) do |_modified, _added, _removed|
        puts "rebuilding..."
        safe_build
        puts "done."
      end.start
      loop { sleep 1000 }
    end

    no_commands do
      def safe_build
        begin
          build
        rescue => e
          puts 'build error:'
          puts e
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
inesita-1.0.pre.3 lib/inesita/cli/watch.rb
inesita-1.0.pre.2 lib/inesita/cli/watch.rb
inesita-1.0.pre.1 lib/inesita/cli/watch.rb
inesita-0.9.2 lib/inesita/cli/watch.rb
inesita-0.9.1 lib/inesita/cli/watch.rb
inesita-0.9.0 lib/inesita/cli/watch.rb
inesita-0.8.2 lib/inesita/cli/watch.rb
inesita-0.8.1 lib/inesita/cli/watch.rb
inesita-0.7.0 lib/inesita/cli/watch.rb