shopify-cli 1.0.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +1 -1
- data/.travis.yml +3 -2
- data/CHANGELOG.md +21 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +13 -13
- data/bin/load_shopify.rb +3 -1
- data/bin/shopify +2 -0
- data/docs/Gemfile.lock +23 -13
- data/docs/getting-started/index.md +3 -2
- data/docs/getting-started/install/index.md +55 -9
- data/docs/getting-started/uninstall/index.md +1 -1
- data/docs/getting-started/upgrade/index.md +8 -4
- data/ext/shopify-cli/extconf.rb +40 -20
- data/lib/project_types/extension/cli.rb +1 -0
- data/lib/project_types/extension/features/argo_config.rb +60 -0
- data/lib/project_types/extension/messages/messages.rb +3 -0
- data/lib/project_types/extension/models/type.rb +1 -0
- data/lib/project_types/extension/models/types/checkout_post_purchase.rb +5 -2
- data/lib/project_types/extension/tasks/create_extension.rb +1 -1
- data/lib/project_types/extension/tasks/get_app.rb +1 -1
- data/lib/project_types/extension/tasks/update_draft.rb +1 -1
- data/lib/project_types/node/commands/create.rb +4 -4
- data/lib/project_types/node/commands/deploy/heroku.rb +6 -1
- data/lib/project_types/node/commands/generate/billing.rb +7 -5
- data/lib/project_types/node/commands/generate/page.rb +9 -5
- data/lib/project_types/node/commands/generate/webhook.rb +5 -1
- data/lib/project_types/node/commands/serve.rb +5 -5
- data/lib/project_types/node/messages/messages.rb +5 -1
- data/lib/project_types/rails/commands/create.rb +56 -5
- data/lib/project_types/rails/commands/generate.rb +1 -0
- data/lib/project_types/rails/commands/generate/webhook.rb +3 -2
- data/lib/project_types/rails/commands/serve.rb +11 -7
- data/lib/project_types/rails/gem.rb +61 -6
- data/lib/project_types/rails/messages/messages.rb +32 -12
- data/lib/project_types/script/commands/create.rb +1 -5
- data/lib/project_types/script/commands/disable.rb +1 -2
- data/lib/project_types/script/commands/enable.rb +5 -5
- data/lib/project_types/script/commands/push.rb +1 -6
- data/lib/project_types/script/config/extension_points.yml +4 -4
- data/lib/project_types/script/errors.rb +8 -0
- data/lib/project_types/script/forms/create.rb +1 -1
- data/lib/project_types/script/layers/domain/errors.rb +2 -0
- data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +36 -1
- data/lib/project_types/script/layers/infrastructure/errors.rb +8 -0
- data/lib/project_types/script/layers/infrastructure/script_service.rb +6 -2
- data/lib/project_types/script/messages/messages.rb +22 -48
- data/lib/project_types/script/ui/error_handler.rb +12 -0
- data/lib/rubygems_plugin.rb +18 -10
- data/lib/shopify-cli/admin_api/populate_resource_command.rb +1 -1
- data/lib/shopify-cli/command.rb +12 -6
- data/lib/shopify-cli/commands/connect.rb +7 -75
- data/lib/shopify-cli/commands/create.rb +1 -1
- data/lib/shopify-cli/commands/system.rb +21 -12
- data/lib/shopify-cli/context.rb +68 -0
- data/lib/shopify-cli/core/entry_point.rb +4 -1
- data/lib/shopify-cli/core/executor.rb +3 -5
- data/lib/shopify-cli/core/monorail.rb +1 -1
- data/lib/shopify-cli/db.rb +1 -1
- data/lib/shopify-cli/git.rb +1 -1
- data/lib/shopify-cli/heroku.rb +21 -5
- data/lib/shopify-cli/js_deps.rb +2 -2
- data/lib/shopify-cli/js_system.rb +2 -2
- data/lib/shopify-cli/messages/messages.rb +35 -25
- data/lib/shopify-cli/process_supervision.rb +60 -21
- data/lib/shopify-cli/project.rb +17 -9
- data/lib/shopify-cli/project_type.rb +3 -2
- data/lib/shopify-cli/sub_command.rb +1 -0
- data/lib/shopify-cli/task.rb +2 -2
- data/lib/shopify-cli/tasks.rb +11 -4
- data/lib/shopify-cli/tasks/ensure_env.rb +74 -17
- data/lib/shopify-cli/tunnel.rb +22 -7
- data/lib/shopify-cli/version.rb +1 -1
- data/lib/shopify_cli.rb +35 -9
- data/shopify-cli.gemspec +4 -1
- data/vendor/deps/cli-kit/REVISION +1 -1
- data/vendor/deps/cli-kit/lib/cli/kit.rb +1 -1
- data/vendor/deps/cli-kit/lib/cli/kit/autocall.rb +2 -2
- data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +12 -6
- data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +9 -11
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +8 -2
- data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +7 -7
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +48 -17
- data/vendor/deps/cli-ui/REVISION +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui.rb +5 -4
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +9 -3
- data/vendor/deps/cli-ui/lib/cli/ui/color.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -2
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +13 -5
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +29 -2
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +21 -10
- data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +11 -2
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -3
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +6 -8
- data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +2 -0
- data/vendor/gen/lib/gen.rb +39 -0
- data/vendor/gen/lib/gen/commands.rb +18 -0
- data/vendor/gen/lib/gen/commands/help.rb +20 -0
- data/vendor/gen/lib/gen/commands/new.rb +21 -0
- data/vendor/gen/lib/gen/entry_point.rb +10 -0
- data/vendor/gen/lib/gen/generator.rb +165 -0
- data/vendor/gen/template/.gitignore +2 -0
- data/vendor/gen/template/Gemfile +10 -0
- data/vendor/gen/template/README.md +1 -0
- data/vendor/gen/template/bin/testunit +23 -0
- data/vendor/gen/template/bin/update-deps +97 -0
- data/vendor/gen/template/dev-gems.yml +3 -0
- data/vendor/gen/template/dev-vendor.yml +4 -0
- data/vendor/gen/template/exe/__app__-gems +17 -0
- data/vendor/gen/template/exe/__app__-vendor +18 -0
- data/vendor/gen/template/lib/__app__.rb +33 -0
- data/vendor/gen/template/lib/__app__/commands.rb +18 -0
- data/vendor/gen/template/lib/__app__/commands/example.rb +19 -0
- data/vendor/gen/template/lib/__app__/commands/help.rb +21 -0
- data/vendor/gen/template/lib/__app__/entry_point.rb +10 -0
- data/vendor/gen/template/test/example_test.rb +17 -0
- data/vendor/gen/template/test/test_helper.rb +22 -0
- metadata +26 -4
- data/Vagrantfile +0 -17
- data/lib/project_types/script/forms/script_form.rb +0 -69
|
@@ -14,6 +14,7 @@ module ShopifyCli
|
|
|
14
14
|
alias_method :all_loaded, :repository
|
|
15
15
|
|
|
16
16
|
def inherited(klass)
|
|
17
|
+
super
|
|
17
18
|
repository << klass
|
|
18
19
|
klass.project_type = @current_type
|
|
19
20
|
klass.project_load_shallow = @shallow_load
|
|
@@ -32,7 +33,7 @@ module ShopifyCli
|
|
|
32
33
|
|
|
33
34
|
def load_all
|
|
34
35
|
Dir.glob(File.join(ShopifyCli::ROOT, 'lib', 'project_types', '*', 'cli.rb')).map do |filepath|
|
|
35
|
-
load_type(filepath.split(File::Separator)[-2], true)
|
|
36
|
+
load_type(filepath.split(File::Separator)[-2].to_sym, true)
|
|
36
37
|
end
|
|
37
38
|
end
|
|
38
39
|
|
|
@@ -64,7 +65,7 @@ module ShopifyCli
|
|
|
64
65
|
|
|
65
66
|
def register_task(task, name)
|
|
66
67
|
return if project_load_shallow
|
|
67
|
-
Task
|
|
68
|
+
ShopifyCli::Task.register(task, name)
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
def register_messages(messages)
|
data/lib/shopify-cli/task.rb
CHANGED
data/lib/shopify-cli/tasks.rb
CHANGED
|
@@ -12,15 +12,22 @@ module ShopifyCli
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def [](name)
|
|
15
|
-
@tasks[name]
|
|
15
|
+
class_or_proc = @tasks[name]
|
|
16
|
+
if class_or_proc.is_a?(Class)
|
|
17
|
+
class_or_proc
|
|
18
|
+
elsif class_or_proc.respond_to?(:call)
|
|
19
|
+
class_or_proc.call
|
|
20
|
+
else
|
|
21
|
+
class_or_proc
|
|
22
|
+
end
|
|
16
23
|
end
|
|
17
24
|
end
|
|
18
25
|
|
|
19
26
|
Registry = TaskRegistry.new
|
|
20
27
|
|
|
21
|
-
def self.register(task, name, path)
|
|
22
|
-
autoload(task, path)
|
|
23
|
-
Registry.add(const_get(task), name)
|
|
28
|
+
def self.register(task, name, path = nil)
|
|
29
|
+
autoload(task, path) if path
|
|
30
|
+
Registry.add(-> () { const_get(task) }, name)
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
register :CreateApiClient, :create_api_client, 'shopify-cli/tasks/create_api_client'
|
|
@@ -3,27 +3,84 @@ require 'shopify_cli'
|
|
|
3
3
|
module ShopifyCli
|
|
4
4
|
module Tasks
|
|
5
5
|
class EnsureEnv < ShopifyCli::Task
|
|
6
|
-
def call(ctx)
|
|
6
|
+
def call(ctx, regenerate: false, required: [:api_key, :secret])
|
|
7
7
|
@ctx = ctx
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
env_data =
|
|
9
|
+
begin
|
|
10
|
+
Resources::EnvFile.parse_external_env
|
|
11
|
+
rescue Errno::ENOENT
|
|
12
|
+
{}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
return {} if !regenerate && required.all? { |property| env_data[property] }
|
|
16
|
+
|
|
17
|
+
org = fetch_org
|
|
18
|
+
write_env(env_data, org)
|
|
19
|
+
org
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def fetch_org
|
|
25
|
+
orgs = PartnersAPI::Organizations.fetch_with_app(@ctx)
|
|
26
|
+
org_id = if orgs.count == 1
|
|
27
|
+
orgs.first["id"]
|
|
28
|
+
else
|
|
29
|
+
CLI::UI::Prompt.ask(@ctx.message('core.tasks.ensure_env.organization_select')) do |handler|
|
|
30
|
+
orgs.each do |org|
|
|
31
|
+
handler.option(
|
|
32
|
+
@ctx.message('core.partners_api.org_name_and_id', org['businessName'], org['id'])
|
|
33
|
+
) { org["id"] }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
orgs.find { |o| o["id"] == org_id }
|
|
11
38
|
end
|
|
12
39
|
|
|
13
|
-
def
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
def get_app(org_id, apps)
|
|
41
|
+
if apps.count == 1
|
|
42
|
+
apps.first
|
|
43
|
+
elsif apps.count == 0
|
|
44
|
+
@ctx.puts(@ctx.message('core.tasks.ensure_env.no_apps'))
|
|
45
|
+
title = CLI::UI::Prompt.ask(@ctx.message('core.tasks.ensure_env.app_name'))
|
|
46
|
+
type = CLI::UI::Prompt.ask(@ctx.message('core.tasks.ensure_env.app_type.select')) do |handler|
|
|
47
|
+
handler.option(@ctx.message('core.tasks.ensure_env.app_type.select_public')) { 'public' }
|
|
48
|
+
handler.option(@ctx.message('core.tasks.ensure_env.app_type.select_custom')) { 'custom' }
|
|
49
|
+
end
|
|
50
|
+
ShopifyCli::Tasks::CreateApiClient.call(@ctx, org_id: org_id, title: title, type: type)
|
|
51
|
+
else
|
|
52
|
+
CLI::UI::Prompt.ask(@ctx.message('core.tasks.ensure_env.app_select')) do |handler|
|
|
53
|
+
apps.each { |app| handler.option(app["title"]) { app } }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def get_shop(shops, id)
|
|
59
|
+
if shops.count == 1
|
|
60
|
+
shop = shops.first["shopDomain"]
|
|
61
|
+
elsif shops.count == 0
|
|
62
|
+
@ctx.puts(@ctx.message('core.tasks.ensure_env.no_development_stores', id))
|
|
63
|
+
else
|
|
64
|
+
shop = CLI::UI::Prompt.ask(@ctx.message('core.tasks.ensure_env.development_store_select')) do |handler|
|
|
65
|
+
shops.each { |s| handler.option(s["shopName"]) { s["shopDomain"] } }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
shop
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def write_env(env_data, org)
|
|
72
|
+
id = org['id']
|
|
73
|
+
app = get_app(id, org['apps'])
|
|
74
|
+
|
|
75
|
+
env_data[:shop] = get_shop(org['stores'], id)
|
|
76
|
+
env_data[:api_key] = app["apiKey"]
|
|
77
|
+
env_data[:secret] = app["apiSecretKeys"].first["secret"]
|
|
78
|
+
env_data[:scopes] = 'write_products,write_customers,write_draft_orders' if env_data[:scopes].nil?
|
|
79
|
+
env_data[:extra] = {} if env_data[:extra].nil?
|
|
80
|
+
|
|
81
|
+
Resources::EnvFile.new(
|
|
82
|
+
env_data
|
|
25
83
|
).write(@ctx)
|
|
26
|
-
env
|
|
27
84
|
end
|
|
28
85
|
end
|
|
29
86
|
end
|
data/lib/shopify-cli/tunnel.rb
CHANGED
|
@@ -21,6 +21,7 @@ module ShopifyCli
|
|
|
21
21
|
DOWNLOAD_URLS = {
|
|
22
22
|
mac: 'https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-amd64.zip',
|
|
23
23
|
linux: 'https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip',
|
|
24
|
+
windows: 'https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-windows-amd64.zip',
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
NGROK_TUNNELS_URI = URI.parse('http://localhost:4040/api/tunnels')
|
|
@@ -88,7 +89,7 @@ module ShopifyCli
|
|
|
88
89
|
#
|
|
89
90
|
def auth(ctx, token)
|
|
90
91
|
install(ctx)
|
|
91
|
-
ctx.system(File.join(ShopifyCli
|
|
92
|
+
ctx.system(File.join(ShopifyCli.cache_dir, 'ngrok'), 'authtoken', token)
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
##
|
|
@@ -122,14 +123,21 @@ module ShopifyCli
|
|
|
122
123
|
private
|
|
123
124
|
|
|
124
125
|
def install(ctx)
|
|
125
|
-
return if File.exist?(File.join(ShopifyCli
|
|
126
|
+
return if File.exist?(File.join(ShopifyCli.cache_dir, ctx.windows? ? 'ngrok.exe' : 'ngrok'))
|
|
127
|
+
check_prereq_command(ctx, 'curl')
|
|
128
|
+
check_prereq_command(ctx, ctx.linux? ? 'unzip' : 'tar')
|
|
126
129
|
spinner = CLI::UI::SpinGroup.new
|
|
127
130
|
spinner.add('Installing ngrok...') do
|
|
128
|
-
zip_dest = File.join(ShopifyCli
|
|
131
|
+
zip_dest = File.join(ShopifyCli.cache_dir, 'ngrok.zip')
|
|
129
132
|
unless File.exist?(zip_dest)
|
|
130
|
-
ctx.system('curl', '-o', zip_dest, DOWNLOAD_URLS[ctx.os], chdir: ShopifyCli
|
|
133
|
+
ctx.system('curl', '-o', zip_dest, DOWNLOAD_URLS[ctx.os], chdir: ShopifyCli.cache_dir)
|
|
131
134
|
end
|
|
132
|
-
|
|
135
|
+
args = if ctx.linux?
|
|
136
|
+
%W(unzip -u #{zip_dest})
|
|
137
|
+
else
|
|
138
|
+
%W(tar -xf #{zip_dest})
|
|
139
|
+
end
|
|
140
|
+
ctx.system(*args, chdir: ShopifyCli.cache_dir)
|
|
133
141
|
ctx.rm(zip_dest)
|
|
134
142
|
end
|
|
135
143
|
spinner.wait
|
|
@@ -143,7 +151,7 @@ module ShopifyCli
|
|
|
143
151
|
end
|
|
144
152
|
|
|
145
153
|
def ngrok_command(port)
|
|
146
|
-
"
|
|
154
|
+
"\"#{File.join(ShopifyCli.cache_dir, 'ngrok')}\" http -inspect=false -log=stdout -log-level=debug #{port}"
|
|
147
155
|
end
|
|
148
156
|
|
|
149
157
|
def seconds_to_hm(seconds)
|
|
@@ -163,6 +171,13 @@ module ShopifyCli
|
|
|
163
171
|
end
|
|
164
172
|
start_ngrok(ctx, port)
|
|
165
173
|
end
|
|
174
|
+
|
|
175
|
+
def check_prereq_command(ctx, command)
|
|
176
|
+
cmd_path = ctx.which(command)
|
|
177
|
+
ctx.abort(ctx.message('core.tunnel.error.prereq_command_required', command)) if cmd_path.nil?
|
|
178
|
+
ctx.done(ctx.message('core.tunnel.prereq_command_location', command, cmd_path))
|
|
179
|
+
end
|
|
180
|
+
|
|
166
181
|
class LogParser # :nodoc:
|
|
167
182
|
TIMEOUT = 10
|
|
168
183
|
|
|
@@ -195,7 +210,7 @@ module ShopifyCli
|
|
|
195
210
|
end
|
|
196
211
|
|
|
197
212
|
def parse_account
|
|
198
|
-
account, timeout, _ = @log.match(/AccountName:([\w\s]*) SessionDuration:([\d]+) PlanName/)&.captures
|
|
213
|
+
account, timeout, _ = @log.match(/AccountName:([\w\s\d@._\-]*) SessionDuration:([\d]+) PlanName/)&.captures
|
|
199
214
|
@account = account&.empty? ? nil : account
|
|
200
215
|
@timeout = timeout&.empty? ? 0 : timeout.to_i
|
|
201
216
|
end
|
data/lib/shopify-cli/version.rb
CHANGED
data/lib/shopify_cli.rb
CHANGED
|
@@ -44,10 +44,6 @@ module ShopifyCli
|
|
|
44
44
|
ROOT = File.expand_path('../..', __FILE__)
|
|
45
45
|
PROJECT_TYPES_DIR = File.join(ROOT, 'lib', 'project_types')
|
|
46
46
|
TEMP_DIR = File.join(ROOT, '.tmp')
|
|
47
|
-
CACHE_DIR = File.join(File.expand_path(ENV.fetch('XDG_CACHE_HOME', '~/.cache')), TOOL_NAME)
|
|
48
|
-
TOOL_CONFIG_PATH = File.join(File.expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config')), TOOL_NAME)
|
|
49
|
-
LOG_FILE = File.join(TOOL_CONFIG_PATH, 'logs', 'log.log')
|
|
50
|
-
DEBUG_LOG_FILE = File.join(TOOL_CONFIG_PATH, 'logs', 'debug.log')
|
|
51
47
|
|
|
52
48
|
# programmer emoji if default install location, else wrench emoji
|
|
53
49
|
EMOJI = ROOT == '/opt/shopify' ? "\u{1f469}\u{200d}\u{1f4bb}" : "\u{1f527}"
|
|
@@ -82,7 +78,7 @@ module ShopifyCli
|
|
|
82
78
|
# ShopifyCli::Config
|
|
83
79
|
autocall(:Config) { CLI::Kit::Config.new(tool_name: TOOL_NAME) }
|
|
84
80
|
# ShopifyCli::Logger
|
|
85
|
-
autocall(:Logger) { CLI::Kit::Logger.new(debug_log_file:
|
|
81
|
+
autocall(:Logger) { CLI::Kit::Logger.new(debug_log_file: ShopifyCli.debug_log_file) }
|
|
86
82
|
# ShopifyCli::Resolver
|
|
87
83
|
autocall(:Resolver) do
|
|
88
84
|
ShopifyCli::Core::HelpResolver.new(
|
|
@@ -93,7 +89,7 @@ module ShopifyCli
|
|
|
93
89
|
# ShopifyCli::ErrorHandler
|
|
94
90
|
autocall(:ErrorHandler) do
|
|
95
91
|
CLI::Kit::ErrorHandler.new(
|
|
96
|
-
log_file: ShopifyCli
|
|
92
|
+
log_file: ShopifyCli.log_file,
|
|
97
93
|
exception_reporter: nil,
|
|
98
94
|
)
|
|
99
95
|
end
|
|
@@ -127,7 +123,37 @@ module ShopifyCli
|
|
|
127
123
|
|
|
128
124
|
require 'shopify-cli/messages/messages'
|
|
129
125
|
Context.load_messages(ShopifyCli::Messages::MESSAGES)
|
|
130
|
-
end
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
def self.cache_dir
|
|
128
|
+
cache_dir = if ENV.key?('RUNNING_SHOPIFY_CLI_TESTS')
|
|
129
|
+
TEMP_DIR
|
|
130
|
+
elsif ENV['LOCALAPPDATA'].nil?
|
|
131
|
+
File.join(File.expand_path(ENV.fetch('XDG_CACHE_HOME', '~/.cache')), TOOL_NAME)
|
|
132
|
+
else
|
|
133
|
+
File.join(File.expand_path(ENV['LOCALAPPDATA']), TOOL_NAME)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Make sure the cache dir always exists
|
|
137
|
+
@cache_dir_exists ||= FileUtils.mkdir_p(cache_dir)
|
|
138
|
+
|
|
139
|
+
cache_dir
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def self.tool_config_path
|
|
143
|
+
if ENV.key?('RUNNING_SHOPIFY_CLI_TESTS')
|
|
144
|
+
TEMP_DIR
|
|
145
|
+
elsif ENV['APPDATA'].nil?
|
|
146
|
+
File.join(File.expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config')), TOOL_NAME)
|
|
147
|
+
else
|
|
148
|
+
File.join(File.expand_path(ENV['APPDATA']), TOOL_NAME)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def self.log_file
|
|
153
|
+
File.join(tool_config_path, 'logs', 'log.log')
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def self.debug_log_file
|
|
157
|
+
File.join(tool_config_path, 'logs', 'debug.log')
|
|
158
|
+
end
|
|
159
|
+
end
|
data/shopify-cli.gemspec
CHANGED
|
@@ -26,7 +26,10 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
# Specify which files should be added to the gem when it is released.
|
|
27
27
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
28
28
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
29
|
-
%x(git ls-files -z).split("\x0").reject
|
|
29
|
+
%x(git ls-files -z).split("\x0").reject do |f|
|
|
30
|
+
f.match(%r{^(test|spec|features|packaging)/}) ||
|
|
31
|
+
f.match(%r{^bin/(update-deps|shopify.bat)$})
|
|
32
|
+
end
|
|
30
33
|
end
|
|
31
34
|
spec.bindir = "bin"
|
|
32
35
|
spec.require_paths = ["lib", "vendor"]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1013aa5c5664e7034ca3f02fd2e0513361b07e95 (dirty)
|
|
@@ -51,7 +51,7 @@ module CLI
|
|
|
51
51
|
# 1. rescue Abort or Bug
|
|
52
52
|
# 2. Print a contextualized error message
|
|
53
53
|
# 3. Re-raise AbortSilent or BugSilent respectively.
|
|
54
|
-
GenericAbort = Class.new(Exception)
|
|
54
|
+
GenericAbort = Class.new(Exception) # rubocop:disable Lint/InheritException
|
|
55
55
|
Abort = Class.new(GenericAbort)
|
|
56
56
|
Bug = Class.new(GenericAbort)
|
|
57
57
|
BugSilent = Class.new(GenericAbort)
|
|
@@ -22,11 +22,11 @@ module CLI
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def handle_exception(error)
|
|
25
|
-
if notify_with = exception_for_submission(error)
|
|
25
|
+
if (notify_with = exception_for_submission(error))
|
|
26
26
|
logs = begin
|
|
27
27
|
File.read(@log_file)
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
rescue => e
|
|
29
|
+
"(#{e.class}: #{e.message})"
|
|
30
30
|
end
|
|
31
31
|
exception_reporter.report(notify_with, logs)
|
|
32
32
|
end
|
|
@@ -56,7 +56,7 @@ module CLI
|
|
|
56
56
|
# if it was `exit 30`, translate the exit code to 1, and submit nothing.
|
|
57
57
|
# 30 is used to signal normal failures that are not indicative of bugs.
|
|
58
58
|
# However, users should see it presented as 1.
|
|
59
|
-
exit
|
|
59
|
+
exit(1)
|
|
60
60
|
else
|
|
61
61
|
# A weird termination status happened. `error.exception "message"` will maintain backtrace
|
|
62
62
|
# but allow us to set a message
|
|
@@ -83,7 +83,7 @@ module CLI
|
|
|
83
83
|
|
|
84
84
|
CLI::Kit::EXIT_FAILURE_BUT_NOT_BUG
|
|
85
85
|
rescue Interrupt
|
|
86
|
-
|
|
86
|
+
stderr_puts_message('Interrupt')
|
|
87
87
|
CLI::Kit::EXIT_FAILURE_BUT_NOT_BUG
|
|
88
88
|
rescue Errno::ENOSPC
|
|
89
89
|
message = if @tool_name
|
|
@@ -91,10 +91,16 @@ module CLI
|
|
|
91
91
|
else
|
|
92
92
|
"Your disk is full - free space is required to operate"
|
|
93
93
|
end
|
|
94
|
-
|
|
94
|
+
stderr_puts_message(message)
|
|
95
95
|
CLI::Kit::EXIT_FAILURE_BUT_NOT_BUG
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
+
def stderr_puts_message(message)
|
|
99
|
+
$stderr.puts(format_error_message(message))
|
|
100
|
+
rescue Errno::EPIPE
|
|
101
|
+
nil
|
|
102
|
+
end
|
|
103
|
+
|
|
98
104
|
def exception_reporter
|
|
99
105
|
if @exception_reporter_or_proc.respond_to?(:report)
|
|
100
106
|
@exception_reporter_or_proc
|
|
@@ -13,19 +13,17 @@ module CLI
|
|
|
13
13
|
def call(command, command_name, args)
|
|
14
14
|
with_traps do
|
|
15
15
|
with_logging do |id|
|
|
16
|
+
command.call(args, command_name)
|
|
17
|
+
rescue => e
|
|
16
18
|
begin
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# Outputting to stderr is best-effort. Avoid raising another error when outputting debug info so that
|
|
24
|
-
# we can detect and log the original error, which may even be the source of this error.
|
|
25
|
-
nil
|
|
26
|
-
end
|
|
27
|
-
raise e
|
|
19
|
+
$stderr.puts "This command ran with ID: #{id}"
|
|
20
|
+
$stderr.puts "Please include this information in any issues/report along with relevant logs"
|
|
21
|
+
rescue SystemCallError
|
|
22
|
+
# Outputting to stderr is best-effort. Avoid raising another error when outputting debug info so that
|
|
23
|
+
# we can detect and log the original error, which may even be the source of this error.
|
|
24
|
+
nil
|
|
28
25
|
end
|
|
26
|
+
raise e
|
|
29
27
|
end
|
|
30
28
|
end
|
|
31
29
|
end
|
|
@@ -10,9 +10,10 @@ module CLI
|
|
|
10
10
|
# Constructor for CLI::Kit::Logger
|
|
11
11
|
#
|
|
12
12
|
# @param debug_log_file [String] path to the file where debug logs should be stored
|
|
13
|
-
def initialize(debug_log_file:)
|
|
13
|
+
def initialize(debug_log_file:, env_debug_name: 'DEBUG')
|
|
14
14
|
FileUtils.mkpath(File.dirname(debug_log_file))
|
|
15
15
|
@debug_logger = ::Logger.new(debug_log_file, MAX_NUM_LOGS, MAX_LOG_SIZE)
|
|
16
|
+
@env_debug_name = env_debug_name
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
# Functionally equivalent to Logger#info
|
|
@@ -60,7 +61,7 @@ module CLI
|
|
|
60
61
|
#
|
|
61
62
|
# @param msg [String] the message to log
|
|
62
63
|
def debug(msg)
|
|
63
|
-
$stdout.puts CLI::UI.fmt(msg) if
|
|
64
|
+
$stdout.puts CLI::UI.fmt(msg) if is_debug?
|
|
64
65
|
@debug_logger.debug(format_debug(msg))
|
|
65
66
|
end
|
|
66
67
|
|
|
@@ -71,6 +72,11 @@ module CLI
|
|
|
71
72
|
return msg unless CLI::UI::StdoutRouter.current_id
|
|
72
73
|
"[#{CLI::UI::StdoutRouter.current_id[:id]}] #{msg}"
|
|
73
74
|
end
|
|
75
|
+
|
|
76
|
+
def is_debug?
|
|
77
|
+
val = ENV[@env_debug_name]
|
|
78
|
+
val && val != '0' && val != ''
|
|
79
|
+
end
|
|
74
80
|
end
|
|
75
81
|
end
|
|
76
82
|
end
|