#!/usr/bin/env ruby # encoding: UTF-8 begin require "rubygems" require 'rails/version' RAILS_VERSION = Rails::VERSION::STRING if RAILS_VERSION < "3.2" raise LoadError, "Wrong rails version installed. Please run gem install rails -v'~>3.2.11'" end require "thor" require File.join(File.dirname(__FILE__), '..', 'lib/alchemy/version') end class AlchemyInstaller < Thor include Thor::Actions map "-v" => :version map "--version" => :version desc "version", "Prints current Alchemy CMS version", :hide => true def version puts Alchemy::VERSION end desc "new PROJECT", "Creates a new Alchemy CMS project." method_option :database, :type => :string, :default => 'mysql', :aliases => "-d", :desc => "Type of database to use for this project. Default mysql." def new(project) @application = project.downcase.strip.gsub(/ /, '_') if system("rails new #{@application} -m #{File.join(File.dirname(__FILE__), '..', 'lib', 'rails', 'templates', 'alchemy.rb')} -d #{options[:database]} -JT") create_database_yml if options[:database] == 'mysql' system("cd ./#{@application} && rake alchemy:install") gitignore = <<-GIT log/* tmp/* .DS_Store upload/* index/* config/database.yml GIT %x[ cd ./#{@application} rm ./public/index.html rm ./app/assets/images/rails.png mkdir -p ./index mkdir -p ./uploads touch ./index/.gitkeep touch ./uploads/.gitkeep echo "#{gitignore}" > .gitignore ] else say "\nError while installation!\n", :red end end private def create_database_yml @db_root_password = ask("\nPlease provide your local root password for mysql (Leave blank for none):") local_standard_socket = '/tmp/mysql.sock' @db_local_socket = ask("\nPlease provide your local mysql socket (#{local_standard_socket}):") @db_local_socket = local_standard_socket if @db_local_socket.empty? create_file "./#{@application}/config/database.yml", :force => true do <<-DATABASE development: adapter: mysql2 encoding: utf8 reconnect: false database: #{@application}_development pool: 5 username: root password: #{@db_root_password} socket: #{@db_local_socket} # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: mysql2 encoding: utf8 reconnect: false database: #{@application}_test pool: 5 username: root password: #{@db_root_password} socket: #{@db_local_socket} production: adapter: mysql2 encoding: utf8 reconnect: false database: #{@application}_production pool: 5 username: root password: #{@db_root_password} socket: #{@db_local_socket} DATABASE end end end AlchemyInstaller.start