-
Notifications
You must be signed in to change notification settings - Fork 25
/
shopify-cli@2.rb
120 lines (101 loc) · 3.51 KB
/
shopify-cli@2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# frozen_string_literal: true
#
# The canonical copy of this file is hosted at
# https://github.com/Shopify/shopify-cli/blob/main/packaging/homebrew/shopify-cli.base.rb
# so please make all updates there.
#
# Modified from formula originally generated via `brew-gem` using
# `brew gem formula shopify-cli`
require "formula"
require "fileutils"
class ShopifyCliAT2 < Formula
module RubyBin
def ruby_bin
Formula["ruby"].opt_bin
end
end
class RubyGemsDownloadStrategy < AbstractDownloadStrategy
include RubyBin
def fetch(_timeout: nil, **_options)
ohai("Fetching shopify-cli from gem source")
cache.cd do
ENV["GEM_SPEC_CACHE"] = "#{cache}/gem_spec_cache"
_, err, status = Open3.capture3("gem", "fetch", "shopify-cli", "--version", gem_version)
unless status.success?
odie err
end
end
end
def cached_location
Pathname.new("#{cache}/shopify-cli-#{gem_version}.gem")
end
def cache
@cache ||= HOMEBREW_CACHE
end
def gem_version
@version ||= @resource&.version if defined?(@resource)
raise "Unable to determine version; did Homebrew change?" unless @version
@version
end
def clear_cache
cached_location.unlink if cached_location.exist?
end
end
include RubyBin
url "shopify-cli", using: RubyGemsDownloadStrategy
version "2.36.0"
sha256 "9d8cd40b92ffb3b3ed3915ad3ebb24e239ec132ae383439ac63e71c6d9ecb11c"
depends_on "ruby"
depends_on "git"
disable! date: "2023-05-31", because: "has been disabled because it was deprecated for app and theme development on May 31, 2023. More info: https://shopify.dev/changelog/cli-2-x-is-deprecated"
def install
# set GEM_HOME and GEM_PATH to make sure we package all the dependent gems
# together without accidently picking up other gems on the gem path since
# they might not be there if, say, we change to a different rvm gemset
ENV["GEM_HOME"] = prefix.to_s
ENV["GEM_PATH"] = prefix.to_s
# Use /usr/local/bin at the front of the path instead of Homebrew shims,
# which mess with Ruby's own compiler config when building native extensions
if defined?(HOMEBREW_SHIMS_PATH)
ENV["PATH"] = ENV["PATH"].sub(HOMEBREW_SHIMS_PATH.to_s, "/usr/local/bin")
end
system(
"gem",
"install",
cached_download,
"--no-document",
"--no-wrapper",
"--no-user-install",
"--install-dir", prefix,
"--bindir", bin,
"--",
"--skip-cli-build"
)
raise "gem install 'shopify-cli' failed with status #{$CHILD_STATUS.exitstatus}" unless $CHILD_STATUS.success?
bin.rmtree if bin.exist?
bin.mkpath
brew_gem_prefix = "#{prefix}/gems/shopify-cli-#{version}"
ruby_libs = Dir.glob("#{prefix}/gems/*/lib")
exe = "shopify"
file = Pathname.new("#{brew_gem_prefix}/bin/#{exe}")
(bin + "#{file.basename}2").open("w") do |f|
f << <<~RUBY
#!#{ruby_bin}/ruby -rjson --disable-gems
ENV['ORIGINAL_ENV']=ENV.to_h.to_json
ENV['GEM_HOME']="#{prefix}"
ENV['GEM_PATH']="#{prefix}"
ENV['RUBY_BINDIR']="#{ruby_bin}/"
require 'rubygems'
$:.unshift(#{ruby_libs.map(&:inspect).join(",")})
load "#{file}"
RUBY
end
end
def post_install
message = <<~POSTINSTALL_MESSAGE
Note that Shopify CLI 2.x will be sunset on May 31, 2023.
More info: https://shopify.dev/changelog/cli-2-0-to-be-sunset-on-may-31-2023
POSTINSTALL_MESSAGE
message.each_line { |line| ohai line.chomp }
end
end