forked from spree/spree
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved spree_cmd into main spree project
[Fixes spree#967]
- Loading branch information
Showing
31 changed files
with
604 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2007-2012, Spree Commerce, Inc. and other contributors | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name Spree nor the names of its contributors may be used to | ||
endorse or promote products derived from this software without specific | ||
prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Spree Installer | ||
=============== | ||
|
||
**Until the release of Spree 1.0 you must use the --edge option** | ||
|
||
Command line utility to create new Spree store applications | ||
and extensions | ||
|
||
See the main spree project: https://github.com/spree/spree | ||
|
||
Installation | ||
------------ | ||
|
||
```ruby | ||
gem install spree_cmd | ||
``` | ||
This will make the command line utility 'spree' available. | ||
|
||
You can add Spree to an existing rails application | ||
|
||
```ruby | ||
rails new my_app | ||
spree install my_app | ||
``` | ||
|
||
Extensions | ||
---------- | ||
|
||
To build a new Spree Extension, you can run | ||
```ruby | ||
spree extension my_extension | ||
``` | ||
Examples | ||
-------- | ||
|
||
If you want to accept all the defaults pass --auto_accept | ||
|
||
spree install my_store --edge --auto_accept | ||
|
||
to use a local clone of Spree, pass the --path option | ||
|
||
spree install my_store --path=../spree | ||
|
||
|
||
options | ||
------- | ||
|
||
* --auto_accept - answer yes to all questions | ||
* --edge - to use the edge version of Spree | ||
* --path=../spree - to use a local version of spree | ||
* --git=[email protected]:cmar/spree.git | ||
* --branch=my_changes or --ref=23423423423423 or --tag=my_tag | ||
|
||
Older Versions of Spree | ||
----------------------- | ||
|
||
Versions of the Spree gem before 1.0 included a spree binary. If you | ||
have one of these installed in your gemset, then you can alternatively | ||
use the command line utility "spree_cmd". For example "spree_cmd install | ||
my_app". | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "bundler/gem_tasks" | ||
|
||
desc 'alias for :build to work with other spree gems' | ||
task :gem => :build do | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'spree_cmd' | ||
|
||
SpreeCmd::Command.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'spree_cmd' | ||
|
||
SpreeCmd::Command.start | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'thor' | ||
require 'thor/group' | ||
|
||
require "spree_cmd/installer" | ||
require "spree_cmd/extension" | ||
|
||
module SpreeCmd | ||
class Command < Thor | ||
|
||
desc "install", "adds spree to an existing rails app" | ||
method_option :app_path, :type => :string, :desc => 'path to rails application' | ||
def install(app_path='.') | ||
invoke Installer | ||
end | ||
|
||
desc "extension", "builds a spree extension" | ||
method_option :app_path, :type => :string, :desc => 'path to new extension' | ||
def extension(app_path) | ||
invoke Extension | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module SpreeCmd | ||
|
||
class Extension < Thor::Group | ||
include Thor::Actions | ||
|
||
desc "builds a spree extension" | ||
argument :file_name, :type => :string, :desc => 'rails app_path', :default => '.' | ||
|
||
source_root File.expand_path('../templates/extension', __FILE__) | ||
|
||
def generate | ||
empty_directory file_name | ||
|
||
directory "app", "#{file_name}/app" | ||
directory "lib", "#{file_name}/lib" | ||
directory "script", "#{file_name}/script" | ||
|
||
template "extension.gemspec", "#{file_name}/#{file_name}.gemspec" | ||
template "Gemfile", "#{file_name}/Gemfile" | ||
template "gitignore", "#{file_name}/.gitignore" | ||
template "LICENSE", "#{file_name}/LICENSE" | ||
template "Rakefile", "#{file_name}/Rakefile" | ||
template "README.md", "#{file_name}/README.md" | ||
template "config/routes.rb", "#{file_name}/config/routes.rb" | ||
template "config/locales/en.yml", "#{file_name}/config/locales/en.yml" | ||
template "rspec", "#{file_name}/.rspec" | ||
template "spec/spec_helper.rb.tt", "#{file_name}/spec/spec_helper.rb" | ||
template "Versionfile", "#{file_name}/Versionfile" | ||
end | ||
|
||
def final_banner | ||
say %Q{ | ||
#{'*' * 80} | ||
Your extension has been generated with a gemspec dependency on Spree #{spree_version}. | ||
Please update the Versionfile to designate compatibilty with different versions of Spree. | ||
See http://spreecommerce.com/documentation/extensions.html#versionfile | ||
Consider listing your extension in the official extension registry http://spreecommerce.com/extensions" | ||
#{'*' * 80} | ||
} | ||
end | ||
|
||
no_tasks do | ||
def class_name | ||
Thor::Util.camel_case file_name | ||
end | ||
|
||
def spree_version | ||
'1.0.0' | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
module SpreeCmd | ||
|
||
class Installer < Thor::Group | ||
include Thor::Actions | ||
|
||
desc "Creates a new rails project with a spree store" | ||
argument :app_path, :type => :string, :desc => 'rails app_path', :default => '.' | ||
|
||
class_option :auto_accept, :type => :boolean, :aliases => '-A', :desc => "Answer yes to all prompts" | ||
|
||
class_option :skip_install_data, :type => :boolean, :default => false, | ||
:desc => 'Skip running migrations and loading seed and sample data' | ||
|
||
class_option :version, :type => :string, :default => 'current', | ||
:desc => 'Spree Version to use (current, edge, local)' | ||
|
||
class_option :edge, :type => :boolean | ||
|
||
class_option :path, :type => :string, :desc => 'Spree gem path' | ||
class_option :git, :type => :string, :desc => 'Spree gem git url' | ||
class_option :ref, :type => :string, :desc => 'Spree gem git ref' | ||
class_option :branch, :type => :string, :desc => 'Spree gem git branch' | ||
class_option :tag, :type => :string, :desc => 'Spree gem git tag' | ||
|
||
def verify_rails | ||
unless is_rails_project? | ||
say "#{@app_path} rails project not found" | ||
exit(1) | ||
end | ||
end | ||
|
||
def prepare_options | ||
@spree_gem_options = {} | ||
|
||
if options[:edge] | ||
@spree_gem_options[:git] = 'https://github.com/spree/spree.git' | ||
elsif options[:path] | ||
@spree_gem_options[:path] = options[:path] | ||
elsif options[:git] | ||
@spree_gem_options[:git] = options[:git] | ||
@spree_gem_options[:ref] = options[:ref] if options[:ref] | ||
@spree_gem_options[:branch] = options[:branch] if options[:branch] | ||
@spree_gem_options[:tag] = options[:tag] if options[:tag] | ||
end | ||
end | ||
|
||
def ask_questions | ||
@install_blue_theme = ask_with_default("Would you like to install the default blue theme?") | ||
@install_default_gateways = ask_with_default("Would you like to install the default gateways?") | ||
|
||
if options[:skip_install_data] | ||
@run_migrations = false | ||
@load_seed_data = false | ||
@load_sample_data = false | ||
else | ||
@run_migrations = ask_with_default("Would you like to run the migrations?") | ||
if @run_migrations | ||
@load_seed_data = ask_with_default("Would you like to load the seed data?") | ||
@load_sample_data = ask_with_default("Would you like to load the sample data?") | ||
else | ||
@load_seed_data = false | ||
@load_sample_data = false | ||
end | ||
end | ||
end | ||
|
||
def add_gems | ||
inside @app_path do | ||
|
||
gem :spree, @spree_gem_options | ||
|
||
if @install_blue_theme | ||
gem :spree_blue_theme, { :git => 'git://github.com/spree/spree_blue_theme.git', | ||
:ref => '10666404ccb3ed4a4cc9cbe41e822ab2bb55112e' } | ||
end | ||
|
||
if @install_default_gateways | ||
gem :spree_usa_epay, { :git => 'git://github.com/spree/spree_usa_epay.git', | ||
:ref => '2be3faede9594327b9bb548ad042ef28f2836509' } | ||
|
||
gem :spree_skrill, { :git => 'git://github.com/spree/spree_skrill.git', | ||
:ref => '6743bcbd0146d1c7145d6befc648005d8d0cf79a' } | ||
end | ||
|
||
run 'bundle install' | ||
end | ||
end | ||
|
||
def initialize_spree | ||
spree_options = [] | ||
spree_options << "--migrate=#{@run_migrations}" | ||
spree_options << "--seed=#{@load_seed_data}" | ||
spree_options << "--sample=#{@load_sample_data}" | ||
spree_options << "--auto_accept" if options[:auto_accept] | ||
|
||
inside @app_path do | ||
run "rails generate spree:install #{spree_options.join(' ')}" | ||
end | ||
end | ||
|
||
private | ||
|
||
def gem(name, options={}) | ||
say_status :gemfile, name | ||
parts = ["'#{name}'"] | ||
options.each {|key, value| parts << ":#{key} => '#{value}'" } | ||
append_file "Gemfile", "gem #{parts.join(', ')}\n", :verbose => false | ||
end | ||
|
||
def ask_with_default(message, default='yes') | ||
return true if options[:auto_accept] | ||
|
||
valid = false | ||
until valid | ||
response = ask "#{message} (yes/no) [#{default}]" | ||
response = default if response.empty? | ||
valid = (response =~ /\Ay(?:es)?|no?\Z/i) | ||
end | ||
response.downcase[0] == ?y | ||
end | ||
|
||
def create_rails_app | ||
say :create, @app_path | ||
|
||
rails_cmd = "rails new #{@app_path} --skip-bundle" | ||
if options[:template] | ||
rails_cmd += " -m #{options[:template]}" | ||
end | ||
if options[:database] | ||
rails_cmd += " -d #{options[:database]}" | ||
end | ||
run(rails_cmd) | ||
end | ||
|
||
def is_rails_project? | ||
File.exists? File.join(@app_path, 'script', 'rails') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
source 'http://rubygems.org' | ||
|
||
group :test do | ||
gem 'ffaker' | ||
end | ||
|
||
if RUBY_VERSION < "1.9" | ||
gem "ruby-debug" | ||
else | ||
gem "ruby-debug19" | ||
end | ||
|
||
gemspec |
Oops, something went wrong.