#!/usr/bin/env ruby # coding: utf-8 require "jacana" require "optparse" require 'fileutils' include FileUtils options = { :Doc_Root => './', :Port => 1453, :Php_Path => '/usr/bin/env', } rewrite = nil php_configfile = '.rewriterule' opt = OptionParser.new opt.on('-d VAL') do |docroot| options[:Doc_Root] = docroot end opt.on('-p VAL') do |port| options[:Port] = port.to_i end opt.on('-s VAL') do |php_path| options[:Php_Path] = php_path.to_s end opt.on('-c VAL') do |composer| if composer == "true" system("curl -sS https://getcomposer.org/installer | php") system("mv composer.phar /usr/local/bin/composer") end end opt.on('-v') do require "../lib/commands/version" puts "Version: #{Jacana::VERSION_P} - #{Jacana::VERSION_NAME} @ #{Jacana::AUTHOR}" exit end opt.on('-h') do |help| require "../lib/commands/help" Jacana::Help.new exit end opt.on('-i VAL,PATH,NAME') do |package| require "../lib/commands/install" package = package.split(",") i = Installer::Handler.new case package[0] when 'composer' i.get_composer when 'laravel' i.get_laravel(package[1], package[2]) when '' puts "Command error. Please check jacana -h" end exit end opt.on('--FRAMEWORK=PATH,NAME,VAL') do |framework| framework = framework.split(",") case framework[2] when 'laravel' if !File.exist?('/usr/local/bin/composer') system("curl -sS https://getcomposer.org/installer | php") system("mv composer.phar /usr/local/bin/composer") end cd(framework[0], :verbose => false) system("composer create-project laravel/laravel #{framework[1]} --prefer-dist") system("chmod -R 0777 #{framework[0]}/#{framework[1]}") system("clear") puts "Laravel project is created !" options[:Doc_Root] = framework[0] + "/" + framework[1] + "/public" end end opt.parse! puts "Jagana PHP Handler is Started !" jacana_server = Jacana::JacanaHttpServer.new options if File.exist? php_configfile config = File.read php_configfile jacana_server.instance_eval config end jacana_server.a_rewrite /\/(?.*)/, '/index.php' trap 'INT' do jacana_server.shutdown end jacana_server.start