Sha256: 3c250b41a4341e4a0e4b197077b39aa88ba3fdffe884d6e11b6db72b7969f15b

Contents?: true

Size: 1.79 KB

Versions: 14

Compression:

Stored size: 1.79 KB

Contents

require 'thor'
require 'mime/types'

require 'rubyfox/server'
require 'rubyfox/server/version'
require 'rubyfox/server/environment'

module Rubyfox
  module Server
    class CLI < Thor
      include Thor::Actions

      def self.source_root
        Rubyfox::Server.data_dir
      end

      desc "install TARGET_DIR", "Install SmartFox Server into TARGET_DIR"
      def install(target_dir)
        if File.exist?(target_dir)
          abort "Directory #{target_dir} already exists!"
        end

        directory self.class.source_root, target_dir
      end

      desc "configure TARGET_DIR TEMPLATE_DIR", "Configure SmartFox Server in TARGET_DIR via TEMPLATE_DIR"
      def configure(target_dir, template_dir)
        template_dir = File.expand_path(template_dir, Dir.pwd)
        target_dir = File.expand_path(target_dir, Dir.pwd)

        Dir["#{template_dir}/**/*"].each do |file|
          if File.file?(file)
            part = file.partition(template_dir).last
            target_file = "#{target_dir}/#{part}"
            if file_plain?(file)
              template file, target_file
            else
              copy_file file, target_file
            end
          end
        end
      end
      map "config" => :configure

      desc "start TARGET_DIR", "Start SmartFox Server in TARGET_DIR"
      def start(target_dir)
        inside(target_dir) do
          system "sh ./sfs2x.sh"
        end
      end

      desc "version", "Display version of this command"
      def version
        puts Rubyfox::Server::VERSION
      end

      no_tasks do
        def env
          @env ||= Environment.new(ENV, self)
        end
      end

      private

      def file_plain?(file)
        types = MIME::Types.type_for(file)
        types.empty? || types.any? { |type| type.media_type == "text" }
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rubyfox-server-2.16.0.1 lib/rubyfox/server/cli.rb
rubyfox-server-2.16.0.0 lib/rubyfox/server/cli.rb
rubyfox-server-2.13.7.3 lib/rubyfox/server/cli.rb
rubyfox-server-2.13.6.2 lib/rubyfox/server/cli.rb
rubyfox-server-2.13.6.1 lib/rubyfox/server/cli.rb
rubyfox-server-2.13.5.1 lib/rubyfox/server/cli.rb
rubyfox-server-2.13.4.1 lib/rubyfox/server/cli.rb
rubyfox-server-2.13.3.1 lib/rubyfox/server/cli.rb
rubyfox-server-2.12.5.1 lib/rubyfox/server/cli.rb
rubyfox-server-2.12.5.0 lib/rubyfox/server/cli.rb
rubyfox-server-2.12.4.0 lib/rubyfox/server/cli.rb
rubyfox-server-2.12.1.0 lib/rubyfox/server/cli.rb
rubyfox-server-2.11.1.0 lib/rubyfox/server/cli.rb
rubyfox-server-2.9.2.0 lib/rubyfox/server/cli.rb