From 9093735fefaa4884dca2493767cd7025c1f95420 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 13 Dec 2019 10:02:07 +0100 Subject: [PATCH 1/7] Delay loading libraries to the make the exe faster This way optparse will be able to parse and check options right away and -h will be almost instantaneous. --- exe/solidus | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exe/solidus b/exe/solidus index 8c66bef3..f5171b51 100755 --- a/exe/solidus +++ b/exe/solidus @@ -3,8 +3,7 @@ require 'optparse' -require 'solidus_dev_support' -require 'solidus_dev_support/extension' +require 'solidus_dev_support/version' Options = Struct.new(:name) @@ -46,6 +45,8 @@ if ARGV.first == 'extension' || ARGV.first == 'e' exit 1 end + require 'solidus_dev_support' + require 'solidus_dev_support/extension' SolidusDevSupport::Extension.start else Parser.parse(ARGV) From 83e184e521cfa053a4f598eb7bff3d900a62839b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 13 Dec 2019 10:02:40 +0100 Subject: [PATCH 2/7] Add a binstub for the main exe Just for convenience and consistency with the other development commands. --- bin/solidus | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 bin/solidus diff --git a/bin/solidus b/bin/solidus new file mode 100755 index 00000000..0cef6dd1 --- /dev/null +++ b/bin/solidus @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require 'bundler/setup' +load "#{__dir__}/../exe/solidus" From e5527c4fd926716296138427f9dac88a389d872d Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 13 Dec 2019 13:09:08 +0100 Subject: [PATCH 3/7] Let bin rails create a dummy app and forward ARGV This will make all commands work because they're executed from the app's root. Removed the .tt extension as it has no interpolations to apply. --- .../templates/extension/bin/rails | 13 +++++++++++++ .../templates/extension/bin/rails.tt | 7 ------- 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100755 lib/solidus_dev_support/templates/extension/bin/rails delete mode 100644 lib/solidus_dev_support/templates/extension/bin/rails.tt diff --git a/lib/solidus_dev_support/templates/extension/bin/rails b/lib/solidus_dev_support/templates/extension/bin/rails new file mode 100755 index 00000000..3250808e --- /dev/null +++ b/lib/solidus_dev_support/templates/extension/bin/rails @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby + +app_root = 'spec/dummy' + +unless File.exist? "#{app_root}/bin/rails" + system "bin/rake", app_root or begin + warn "Automatic creation of the dummy app failed" + exit 1 + end +end + +Dir.chdir 'spec/dummy' +exec 'bin/rails', *ARGV diff --git a/lib/solidus_dev_support/templates/extension/bin/rails.tt b/lib/solidus_dev_support/templates/extension/bin/rails.tt deleted file mode 100644 index 6f97dd98..00000000 --- a/lib/solidus_dev_support/templates/extension/bin/rails.tt +++ /dev/null @@ -1,7 +0,0 @@ -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/<%= file_name -%>/engine', __FILE__) - -require 'rails/all' -require 'rails/engine/commands' From cfe337efdafa7400390b7f594b68101cc2558283 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 13 Dec 2019 14:17:41 +0100 Subject: [PATCH 4/7] Generate bin helpers for console and setup --- .../templates/extension/bin/console.tt | 15 +++++++++++++++ .../templates/extension/bin/setup | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100755 lib/solidus_dev_support/templates/extension/bin/console.tt create mode 100755 lib/solidus_dev_support/templates/extension/bin/setup diff --git a/lib/solidus_dev_support/templates/extension/bin/console.tt b/lib/solidus_dev_support/templates/extension/bin/console.tt new file mode 100755 index 00000000..03c56be4 --- /dev/null +++ b/lib/solidus_dev_support/templates/extension/bin/console.tt @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "<%= file_name %>" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. +$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"]) + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/lib/solidus_dev_support/templates/extension/bin/setup b/lib/solidus_dev_support/templates/extension/bin/setup new file mode 100755 index 00000000..e97c371a --- /dev/null +++ b/lib/solidus_dev_support/templates/extension/bin/setup @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +gem install bundler --conservative +bundle update +bin/rake clobber +bin/rake spec/dummy +bin/rails railties:install:migrations db:migrate db:seed From 081d072b547c3b2038b272010ed9b882ec6c7c32 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 13 Dec 2019 17:35:52 +0100 Subject: [PATCH 5/7] Appease rubocop Completely excluded tmp/ and disabled the frozen magic for bin & exe files. --- .rubocop.yml | 9 +++++++++ lib/solidus_dev_support/templates/extension/bin/rails | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 73760a1b..bf71d6db 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,2 +1,11 @@ inherit_from: - https://relaxed.ruby.style/rubocop.yml + +AllCops: + Exclude: + - tmp/**/* + +Style/FrozenStringLiteralComment: + Exclude: + - "**/bin/*" + - "**/exe/*" diff --git a/lib/solidus_dev_support/templates/extension/bin/rails b/lib/solidus_dev_support/templates/extension/bin/rails index 3250808e..cfe59976 100755 --- a/lib/solidus_dev_support/templates/extension/bin/rails +++ b/lib/solidus_dev_support/templates/extension/bin/rails @@ -3,7 +3,7 @@ app_root = 'spec/dummy' unless File.exist? "#{app_root}/bin/rails" - system "bin/rake", app_root or begin + system "bin/rake", app_root or begin # rubocop:disable Style/AndOr warn "Automatic creation of the dummy app failed" exit 1 end From 3892a679243726d350fc94a5a5abc920229f3e36 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 13 Dec 2019 17:58:57 +0100 Subject: [PATCH 6/7] Use Ruby for bin/setup --- bin/setup | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/setup b/bin/setup index dce67d86..b4f06885 100755 --- a/bin/setup +++ b/bin/setup @@ -1,8 +1,20 @@ -#!/usr/bin/env bash -set -euo pipefail -IFS=$'\n\t' -set -vx +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils -bundle install +GEM_ROOT = File.expand_path('..', __dir__) -# Do any other automated setup that you need to do here +def system(*args) + puts "$ #{args.size == 1 ? args.first : args.shelljoin}" + super +end + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +cd GEM_ROOT + +puts "\n== Installing Ruby dependencies ==" +system! %{gem install bundler --conservative} +system! %{bundle check || bundle install} From 5fee8aeaac24c54743a49a884fadccaf82092f12 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 3 Jan 2020 18:38:06 +0100 Subject: [PATCH 7/7] Make files inside bin executables The code has been taken from Bundler. --- lib/solidus_dev_support/extension.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/solidus_dev_support/extension.rb b/lib/solidus_dev_support/extension.rb index d1efeed2..211ee217 100644 --- a/lib/solidus_dev_support/extension.rb +++ b/lib/solidus_dev_support/extension.rb @@ -2,6 +2,7 @@ require 'thor' require 'thor/group' +require 'pathname' module SolidusDevSupport class Extension < Thor::Group @@ -23,6 +24,10 @@ def generate directory '.circleci', "#{file_name}/.circleci" directory '.github', "#{file_name}/.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" @@ -45,6 +50,12 @@ def class_name def use_prefix(prefix) @file_name = prefix + Thor::Util.snake_case(file_name) unless file_name =~ /^#{prefix}/ end + + def make_executable(path) + path = Pathname(path) + executable = (path.stat.mode | 0o111) + path.chmod(executable) + end end end end