Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the solidus executable and make it rely on just Thor #49

Merged
merged 3 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Enforced Rails version depending on the Solidus version in generated Gemfile
- Made Git ignore `spec/examples.txt` in generated extensions
- It's now possible to update an existing extension with the command `bundle exec solidus extension .` from within the extension

### Changed

- Removed the version constraint for Factory Bot from the Gemfile
- The `solidus` executable is now solely managed by Thor and is open to extension by other gems

### Fixed

Expand All @@ -24,6 +26,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Removed

- Removed RuboCop from the default Rake task
- Removed the `-v` option from the `solidus` executable

## [0.3.0] - 2019-01-10

Expand All @@ -37,6 +40,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Changed

- Updated solidus_support to 0.4.0 for Zeitwerk and Rails 6 compatibility
- Updated the `solidus` executable to only rely on Thor and be open to extension by other gems

### Removed

Expand Down
29 changes: 29 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rake", "rake")
51 changes: 2 additions & 49 deletions exe/solidus
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'optparse'
require 'solidus_dev_support/solidus_command'

require 'solidus_dev_support/version'

Options = Struct.new(:name)

class Parser
class << self
def parse(args)
options.parse!(args)
end

def options
OptionParser.new do |opts|
opts.banner = 'Usage: solidus [[extension extension_name] | [-h] [-v]]'

opts.on('-h', '--help', 'Prints this help') do
puts opts
end

opts.on(
'-v',
'--version',
"Prints the current version: #{SolidusDevSupport::VERSION}"
) do
puts SolidusDevSupport::VERSION
end
end
end
end
end

# Print help if no options are supplied
ARGV << '--help' unless ARGV.first

if ARGV.first == 'extension' || ARGV.first == 'e'
ARGV.shift

unless ARGV.first
puts 'An extension must have a name!'
puts `solidus -h`
exit 1
end

require 'solidus_dev_support'
require 'solidus_dev_support/extension'
SolidusDevSupport::Extension.start
else
Parser.parse(ARGV)
end
SolidusDevSupport::SolidusCommand.start
70 changes: 39 additions & 31 deletions lib/solidus_dev_support/extension.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,69 @@
# frozen_string_literal: true

require 'thor'
require 'thor/group'
require 'pathname'

module SolidusDevSupport
class Extension < Thor::Group
class Extension < Thor
include Thor::Actions
PREFIX = 'solidus_'

desc 'builds a solidus extension'
argument :file_name, type: :string, desc: 'rails app_path', default: '.'
default_command :generate

source_root File.expand_path('templates/extension', __dir__)
desc 'generate PATH', 'Generates a new Solidus extension'
def generate(raw_path = '.')
self.path = raw_path

def generate
use_prefix 'solidus_'
empty_directory path

empty_directory file_name

directory 'app', "#{file_name}/app"
directory 'lib', "#{file_name}/lib"
directory 'bin', "#{file_name}/bin"
directory '.circleci', "#{file_name}/.circleci"
directory '.github', "#{file_name}/.github"
directory 'app', "#{path}/app"
directory 'lib', "#{path}/lib"
directory 'bin', "#{path}/bin"
directory '.circleci', "#{path}/.circleci"
directory '.github', "#{path}/.github"

Dir["#{file_name}/bin/*"].each do |executable|
make_executable executable
end

template 'extension.gemspec.erb', "#{file_name}/#{file_name}.gemspec"
template 'Gemfile', "#{file_name}/Gemfile"
template 'gitignore', "#{file_name}/.gitignore"
template 'gem_release.yml.tt', "#{file_name}/.gem_release.yml"
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 'rubocop.yml', "#{file_name}/.rubocop.yml"
template 'extension.gemspec.erb', "#{path}/#{file_name}.gemspec"
template 'Gemfile', "#{path}/Gemfile"
template 'gitignore', "#{path}/.gitignore"
template 'gem_release.yml.tt', "#{path}/.gem_release.yml"
template 'LICENSE', "#{path}/LICENSE"
template 'Rakefile', "#{path}/Rakefile"
template 'README.md', "#{path}/README.md"
template 'config/routes.rb', "#{path}/config/routes.rb"
template 'config/locales/en.yml', "#{path}/config/locales/en.yml"
template 'rspec', "#{path}/.rspec"
template 'spec/spec_helper.rb.tt', "#{path}/spec/spec_helper.rb"
template 'rubocop.yml', "#{path}/.rubocop.yml"
end

no_tasks do
def class_name
Thor::Util.camel_case file_name
end
def path=(path)
path = File.expand_path(path)

@file_name = Thor::Util.snake_case(File.basename(path))
@file_name = PREFIX + @file_name unless @file_name.start_with?(PREFIX)

@class_name = Thor::Util.camel_case @file_name

def use_prefix(prefix)
@file_name = prefix + Thor::Util.snake_case(file_name) unless file_name =~ /^#{prefix}/
@root = File.dirname(path)
@path = File.join(@root, @file_name)
end

def make_executable(path)
path = Pathname(path)
executable = (path.stat.mode | 0o111)
path.chmod(executable)
end

attr_reader :root, :path, :file_name, :class_name
end

def self.source_root
"#{__dir__}/templates/extension"
end
end
end
21 changes: 21 additions & 0 deletions lib/solidus_dev_support/solidus_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'thor'
require 'solidus_dev_support/extension'

module SolidusDevSupport
class SolidusCommand < Thor
namespace ''

desc 'extension', 'Manage solidus extensions'
subcommand 'extension', Extension

desc 'e', 'Manage solidus extensions (shortcut for "extension")'
subcommand 'e', Extension

def self.exit_on_failure?
true
end
end
end

2 changes: 1 addition & 1 deletion spec/features/create_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def check_solidus_cmd
cd(tmp_path) do
output = `#{solidus_cmd} -h`
expect($?).to be_success
expect(output).to include('Usage')
expect(output).to include('Commands:')
end
end

Expand Down