shopify-cli 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/bin/load_shopify.rb +3 -1
- data/bin/shopify +2 -0
- data/ext/shopify-cli/extconf.rb +40 -20
- 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 +6 -5
- data/lib/project_types/node/commands/generate/page.rb +8 -5
- data/lib/project_types/node/commands/generate/webhook.rb +4 -1
- data/lib/project_types/node/messages/messages.rb +1 -0
- data/lib/project_types/rails/commands/create.rb +52 -4
- 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 +6 -2
- data/lib/project_types/rails/gem.rb +61 -6
- data/lib/project_types/rails/messages/messages.rb +27 -11
- data/lib/project_types/script/config/extension_points.yml +3 -3
- data/lib/project_types/script/forms/create.rb +1 -1
- data/lib/rubygems_plugin.rb +18 -10
- data/lib/shopify-cli/admin_api/populate_resource_command.rb +1 -1
- data/lib/shopify-cli/commands/connect.rb +1 -1
- data/lib/shopify-cli/commands/system.rb +9 -8
- data/lib/shopify-cli/context.rb +28 -0
- data/lib/shopify-cli/heroku.rb +18 -2
- data/lib/shopify-cli/js_deps.rb +2 -2
- data/lib/shopify-cli/js_system.rb +2 -2
- data/lib/shopify-cli/process_supervision.rb +52 -15
- data/lib/shopify-cli/project.rb +14 -6
- data/lib/shopify-cli/tunnel.rb +10 -4
- data/lib/shopify-cli/version.rb +1 -1
- data/lib/shopify_cli.rb +6 -2
- 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 +25 -4
- data/Vagrantfile +0 -17
- data/lib/project_types/script/forms/script_form.rb +0 -69
@@ -9,9 +9,12 @@ module Rails
|
|
9
9
|
},
|
10
10
|
|
11
11
|
gem: {
|
12
|
+
checking_installation_path: "Checking path %s for gem %s",
|
13
|
+
installed: "Installed %s gem",
|
12
14
|
installed_debug: "%s installed: %s",
|
13
15
|
installing: "Installing %s gem...",
|
14
|
-
|
16
|
+
setting_gem_home: "GEM_HOME being set to %s",
|
17
|
+
setting_gem_path: "GEM_PATH being set to %s",
|
15
18
|
},
|
16
19
|
|
17
20
|
create: {
|
@@ -33,6 +36,14 @@ module Rails
|
|
33
36
|
See {{underline:https://github.com/Shopify/shopify-app-cli/blob/master/docs/installing-ruby.md}}
|
34
37
|
for our recommended method of installing ruby.
|
35
38
|
MSG
|
39
|
+
install_failure: "Error installing %s gem",
|
40
|
+
node_required: "node is required to create a rails project. Download at https://nodejs.org/en/download.",
|
41
|
+
node_version_failure: "Failed to get the current node version. Please make sure it is installed as " \
|
42
|
+
"per the instructions at https://nodejs.org/en.",
|
43
|
+
yarn_required: "yarn is required to create a rails project. Download at " \
|
44
|
+
"https://classic.yarnpkg.com/en/docs/install.",
|
45
|
+
yarn_version_failure: "Failed to get the current yarn version. Please make sure it is installed as per " \
|
46
|
+
"the instructions at https://classic.yarnpkg.com/en/docs/install.",
|
36
47
|
},
|
37
48
|
|
38
49
|
info: {
|
@@ -40,13 +51,18 @@ module Rails
|
|
40
51
|
serve: "{{*}} Change directories to your new project folder {{green:%s}} and run {{command:%s serve}} " \
|
41
52
|
"to start a local server",
|
42
53
|
install: "{{*}} Then, visit {{underline:%s/test}} to install {{green:%s}} on your Dev Store",
|
54
|
+
open_new_shell: "{{*}} {{yellow:After installing %s, please open a new Command Prompt or PowerShell " \
|
55
|
+
"window to continue.}}",
|
43
56
|
},
|
44
|
-
installing_bundler: "Installing bundler
|
57
|
+
installing_bundler: "Installing bundler...",
|
45
58
|
generating_app: "Generating new rails app project in %s...",
|
46
|
-
adding_shopify_gem: "{{v}} Adding shopify_app gem
|
59
|
+
adding_shopify_gem: "{{v}} Adding shopify_app gem...",
|
60
|
+
node_version: "node %s",
|
61
|
+
yarn_version: "yarn %s",
|
47
62
|
running_bundle_install: "Running bundle install...",
|
48
63
|
running_generator: "Running shopify_app generator...",
|
49
|
-
running_migrations: "Running migrations
|
64
|
+
running_migrations: "Running migrations...",
|
65
|
+
running_webpacker_install: "Running webpacker:install...",
|
50
66
|
},
|
51
67
|
|
52
68
|
deploy: {
|
@@ -65,14 +81,14 @@ module Rails
|
|
65
81
|
Deploy the current Rails project to Heroku
|
66
82
|
Usage: {{command:%s deploy heroku}}
|
67
83
|
HELP
|
68
|
-
downloading: "Downloading Heroku CLI
|
84
|
+
downloading: "Downloading Heroku CLI...",
|
69
85
|
downloaded: "Downloaded Heroku CLI",
|
70
|
-
installing: "Installing Heroku CLI
|
86
|
+
installing: "Installing Heroku CLI...",
|
71
87
|
installed: "Installed Heroku CLI",
|
72
88
|
authenticated_with_account: "{{v}} Authenticated with Heroku as `%s`",
|
73
|
-
authenticating: "Authenticating with Heroku
|
89
|
+
authenticating: "Authenticating with Heroku...",
|
74
90
|
authenticated: "{{v}} Authenticated with Heroku",
|
75
|
-
deploying: "Deploying to Heroku
|
91
|
+
deploying: "Deploying to Heroku...",
|
76
92
|
deployed: "{{v}} Deployed to Heroku",
|
77
93
|
db_check: {
|
78
94
|
validating: "Validating application...",
|
@@ -86,7 +102,7 @@ module Rails
|
|
86
102
|
SQLITE
|
87
103
|
},
|
88
104
|
git: {
|
89
|
-
checking: "Checking git repo
|
105
|
+
checking: "Checking git repo...",
|
90
106
|
initialized: "Git repo initialized",
|
91
107
|
what_branch: "What branch would you like to deploy?",
|
92
108
|
branch_selected: "{{v}} Git branch `%s` selected for deploy",
|
@@ -95,10 +111,10 @@ module Rails
|
|
95
111
|
no_apps_found: "No existing Heroku app found. What would you like to do?",
|
96
112
|
name: "What is your Heroku app’s name?",
|
97
113
|
select: "Specify an existing Heroku app",
|
98
|
-
selecting: "Selecting Heroku app `%s
|
114
|
+
selecting: "Selecting Heroku app `%s`...",
|
99
115
|
selected: "{{v}} Heroku app `%s` selected",
|
100
116
|
create: "Create a new Heroku app",
|
101
|
-
creating: "Creating new Heroku app
|
117
|
+
creating: "Creating new Heroku app...",
|
102
118
|
created: "{{v}} New Heroku app created",
|
103
119
|
},
|
104
120
|
},
|
@@ -1,7 +1,7 @@
|
|
1
1
|
discount:
|
2
2
|
assemblyscript:
|
3
3
|
package: "@shopify/extension-point-as-discount"
|
4
|
-
version: "^0.2.
|
4
|
+
version: "^0.2.6"
|
5
5
|
sdk-version: "^6.0.0"
|
6
6
|
toolchain-version: "^1.1.0"
|
7
7
|
unit_limit_per_order:
|
@@ -13,12 +13,12 @@ unit_limit_per_order:
|
|
13
13
|
payment_filter:
|
14
14
|
assemblyscript:
|
15
15
|
package: "@shopify/extension-point-as-payment-filter"
|
16
|
-
version: "^0.2.
|
16
|
+
version: "^0.2.4"
|
17
17
|
sdk-version: "^6.0.0"
|
18
18
|
toolchain-version: "^1.1.0"
|
19
19
|
shipping_filter:
|
20
20
|
assemblyscript:
|
21
21
|
package: "@shopify/extension-point-as-shipping-filter"
|
22
|
-
version: "^0.2.
|
22
|
+
version: "^0.2.6"
|
23
23
|
sdk-version: "^6.0.0"
|
24
24
|
toolchain-version: "^1.1.0"
|
data/lib/rubygems_plugin.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
Gem.post_uninstall do |uninstaller|
|
2
2
|
if uninstaller.spec.name == 'shopify-cli'
|
3
|
-
|
3
|
+
if RUBY_PLATFORM.match(/mingw32/)
|
4
|
+
bat_path = File.dirname(RbConfig.ruby)
|
5
|
+
bat = "#{bat_path}\\shopify.bat"
|
4
6
|
|
5
|
-
|
7
|
+
# delete the auto-generated batch script
|
8
|
+
File.unlink(bat)
|
9
|
+
else
|
10
|
+
require 'fileutils'
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
symlink = '/usr/local/bin/shopify'
|
13
|
+
|
14
|
+
# delete the symbolic link IFF it exists AND it does not point to a file
|
15
|
+
# (i.e., it's been left hanging as a result of the uninstall, as expected)
|
16
|
+
#
|
17
|
+
# if the file still exists, either the uninstall failed (possible but
|
18
|
+
# unlikely) OR
|
19
|
+
# there's another installation of the gem in another ruby folder that has
|
20
|
+
# overwritten it, so leave the symbolic link alone
|
21
|
+
system("sudo rm -f #{symlink}") if File.symlink?(symlink) && !File.exist?(symlink)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
true
|
@@ -118,7 +118,7 @@ module ShopifyCli
|
|
118
118
|
kwargs = { input: data }
|
119
119
|
kwargs[:shop] = @shop
|
120
120
|
resp = AdminAPI.query(
|
121
|
-
@ctx, "create_#{snake_case_resource_type}", kwargs
|
121
|
+
@ctx, "create_#{snake_case_resource_type}", **kwargs
|
122
122
|
)
|
123
123
|
@ctx.abort(resp['errors']) if resp['errors']
|
124
124
|
@ctx.done(message(resp['data'])) unless @silent
|
@@ -13,8 +13,8 @@ module ShopifyCli
|
|
13
13
|
end
|
14
14
|
|
15
15
|
org = ShopifyCli::Tasks::EnsureEnv.call(@ctx, regenerate: true)
|
16
|
-
api_key = Project.current.env['api_key']
|
17
16
|
write_cli_yml(project_type, org['id']) unless Project.has_current?
|
17
|
+
api_key = Project.current(force_reload: true).env['api_key']
|
18
18
|
@ctx.puts(@ctx.message('core.connect.connected', get_app(org['apps'], api_key).first["title"]))
|
19
19
|
end
|
20
20
|
|
@@ -68,13 +68,14 @@ module ShopifyCli
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def display_utility_commands(_show_all_details)
|
71
|
-
commands = %w(git curl tar
|
71
|
+
commands = %w(git curl tar)
|
72
72
|
|
73
73
|
@ctx.puts("\n" + @ctx.message('core.system.command_header'))
|
74
74
|
commands.each do |s|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
cmd_path = @ctx.which(s)
|
76
|
+
|
77
|
+
if !cmd_path.nil?
|
78
|
+
@ctx.puts(" " + @ctx.message('core.system.command_with_path', s, cmd_path))
|
78
79
|
else
|
79
80
|
@ctx.puts(" " + @ctx.message('core.system.command_not_found', s))
|
80
81
|
end
|
@@ -82,7 +83,7 @@ module ShopifyCli
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def display_ngrok
|
85
|
-
ngrok_location = File.join(ShopifyCli.cache_dir, 'ngrok')
|
86
|
+
ngrok_location = File.join(ShopifyCli.cache_dir, @ctx.windows? ? 'ngrok.exe' : 'ngrok')
|
86
87
|
if File.exist?(ngrok_location)
|
87
88
|
@ctx.puts(" " + @ctx.message('core.system.ngrok_available', ngrok_location))
|
88
89
|
else
|
@@ -102,11 +103,11 @@ module ShopifyCli
|
|
102
103
|
def display_project(project_type, commands)
|
103
104
|
@ctx.puts("\n" + @ctx.message('core.system.project.header', project_type))
|
104
105
|
commands.each do |s|
|
105
|
-
|
106
|
-
if
|
106
|
+
cmd_path = @ctx.which(s)
|
107
|
+
if !cmd_path.nil?
|
107
108
|
version_output, _ = @ctx.capture2e(s, '--version')
|
108
109
|
version = version_output.match(/(\d+\.[^\s]+)/)[0]
|
109
|
-
@ctx.puts(" " + @ctx.message('core.system.project.command_with_path', s,
|
110
|
+
@ctx.puts(" " + @ctx.message('core.system.project.command_with_path', s, cmd_path.strip, version.strip))
|
110
111
|
else
|
111
112
|
@ctx.puts(" " + @ctx.message('core.system.project.command_not_found', s))
|
112
113
|
end
|
data/lib/shopify-cli/context.rb
CHANGED
@@ -56,6 +56,7 @@ module ShopifyCli
|
|
56
56
|
host = uname
|
57
57
|
return :mac if /darwin/.match(host)
|
58
58
|
return :linux if /linux/.match(host)
|
59
|
+
return :windows if /mingw32/.match(host)
|
59
60
|
end
|
60
61
|
|
61
62
|
# will return true if the cli is running on an apple computer.
|
@@ -68,6 +69,11 @@ module ShopifyCli
|
|
68
69
|
os == :linux
|
69
70
|
end
|
70
71
|
|
72
|
+
# will return true if the cli is running on Windows
|
73
|
+
def windows?
|
74
|
+
os == :windows
|
75
|
+
end
|
76
|
+
|
71
77
|
# will return true if the cli is being run from an installation, and not a
|
72
78
|
# development instance. The gem installation will not have a 'test' directory.
|
73
79
|
# See `#development?` for checking for development environment.
|
@@ -418,6 +424,28 @@ module ShopifyCli
|
|
418
424
|
end
|
419
425
|
end
|
420
426
|
|
427
|
+
# Checks if the given command exists in the system
|
428
|
+
#
|
429
|
+
# #### Parameters
|
430
|
+
# - `cmd`: The command to test
|
431
|
+
#
|
432
|
+
# #### Returns
|
433
|
+
# The path of the executable if it is found
|
434
|
+
#
|
435
|
+
# @todo This is currently a duplicate of CLI::Kit::System.which() - we should make that method public when we make
|
436
|
+
# Kit changes and make this a wrapper instead.
|
437
|
+
def which(cmd)
|
438
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
439
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
440
|
+
exts.each do |ext|
|
441
|
+
exe = File.join(File.expand_path(path), "#{cmd}#{ext}")
|
442
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
nil
|
447
|
+
end
|
448
|
+
|
421
449
|
private
|
422
450
|
|
423
451
|
def ctx_path(fname)
|
data/lib/shopify-cli/heroku.rb
CHANGED
@@ -3,7 +3,7 @@ module ShopifyCli
|
|
3
3
|
DOWNLOAD_URLS = {
|
4
4
|
linux: 'https://cli-assets.heroku.com/heroku-linux-x64.tar.gz',
|
5
5
|
mac: 'https://cli-assets.heroku.com/heroku-darwin-x64.tar.gz',
|
6
|
-
windows: 'https://cli-assets.heroku.com/heroku-
|
6
|
+
windows: 'https://cli-assets.heroku.com/heroku-x64.exe',
|
7
7
|
}
|
8
8
|
|
9
9
|
def initialize(ctx)
|
@@ -44,7 +44,11 @@ module ShopifyCli
|
|
44
44
|
def install
|
45
45
|
return if installed?
|
46
46
|
|
47
|
-
result = @ctx.
|
47
|
+
result = if @ctx.windows?
|
48
|
+
@ctx.system(download_path)
|
49
|
+
else
|
50
|
+
@ctx.system('tar', '-xf', download_path, chdir: ShopifyCli.cache_dir)
|
51
|
+
end
|
48
52
|
@ctx.abort(@ctx.message('core.heroku.error.install')) unless result.success?
|
49
53
|
|
50
54
|
@ctx.rm(download_path)
|
@@ -82,6 +86,18 @@ module ShopifyCli
|
|
82
86
|
local_path = File.join(ShopifyCli.cache_dir, 'heroku', 'bin', 'heroku').to_s
|
83
87
|
if File.exist?(local_path)
|
84
88
|
local_path
|
89
|
+
elsif @ctx.windows?
|
90
|
+
# Check if Heroku exists in the Windows registry and run it from there
|
91
|
+
require 'win32/registry'
|
92
|
+
begin
|
93
|
+
windows_path = Win32::Registry::HKEY_CURRENT_USER.open('SOFTWARE\heroku') do |reg|
|
94
|
+
reg[''] # This reads the 'Default' registry key
|
95
|
+
end
|
96
|
+
|
97
|
+
File.join(windows_path, 'bin', 'heroku').to_s
|
98
|
+
rescue
|
99
|
+
'heroku'
|
100
|
+
end
|
85
101
|
else
|
86
102
|
'heroku'
|
87
103
|
end
|
data/lib/shopify-cli/js_deps.rb
CHANGED
@@ -69,7 +69,7 @@ module ShopifyCli
|
|
69
69
|
deps = parse_dependencies
|
70
70
|
errors = nil
|
71
71
|
|
72
|
-
spinner_title = ctx.message('core.js_deps.
|
72
|
+
spinner_title = ctx.message('core.js_deps.installing', @system.package_manager)
|
73
73
|
success = CLI::UI::Spinner.spin(spinner_title, auto_debrief: false) do |spinner|
|
74
74
|
_, errors, status = CLI::Kit::System.capture3(*cmd, env: @ctx.env, chdir: ctx.root)
|
75
75
|
update_spinner_title_and_status(spinner, status, deps)
|
@@ -81,7 +81,7 @@ module ShopifyCli
|
|
81
81
|
|
82
82
|
def update_spinner_title_and_status(spinner, status, deps)
|
83
83
|
if status.success?
|
84
|
-
spinner.update_title(ctx.message('core.js_deps.
|
84
|
+
spinner.update_title(ctx.message('core.js_deps.installed', deps.size))
|
85
85
|
else
|
86
86
|
spinner.update_title(ctx.message('core.js_deps.error.install_spinner_error', deps.size))
|
87
87
|
CLI::UI::Spinner::TASK_FAILED
|
@@ -64,8 +64,8 @@ module ShopifyCli
|
|
64
64
|
#
|
65
65
|
def yarn?
|
66
66
|
@has_yarn ||= begin
|
67
|
-
|
68
|
-
File.exist?(File.join(ctx.root, 'yarn.lock')) &&
|
67
|
+
cmd_path = @ctx.which('yarn')
|
68
|
+
File.exist?(File.join(ctx.root, 'yarn.lock')) && !cmd_path.nil?
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -8,7 +8,7 @@ module ShopifyCli
|
|
8
8
|
# a string or a symbol to identify this process by
|
9
9
|
attr_reader :identifier
|
10
10
|
# process ID for the running process
|
11
|
-
|
11
|
+
attr_accessor :pid
|
12
12
|
# starttime of the process
|
13
13
|
attr_reader :time
|
14
14
|
# filepath to the pidfile for this process
|
@@ -58,15 +58,37 @@ module ShopifyCli
|
|
58
58
|
#
|
59
59
|
def start(identifier, args)
|
60
60
|
return for_ident(identifier) if running?(identifier)
|
61
|
-
|
62
|
-
|
61
|
+
|
62
|
+
# Windows doesn't support forking process without extra gems, so we resort to spawning a new child process -
|
63
|
+
# that means that it dies along with the original process if it is interrupted. On UNIX, we fork the process so
|
64
|
+
# that it doesn't have to be restarted on every run.
|
65
|
+
if Context.new.windows?
|
66
|
+
pid_file = new(identifier)
|
67
|
+
|
68
|
+
# Make sure the file exists and is empty, otherwise Windows fails
|
69
|
+
File.open(pid_file.log_path, 'w') {}
|
70
|
+
pid = Process.spawn(
|
71
|
+
*args,
|
72
|
+
out: pid_file.log_path,
|
73
|
+
err: pid_file.log_path,
|
74
|
+
in: Context.new.windows? ? "nul" : "/dev/null",
|
75
|
+
)
|
76
|
+
pid_file.pid = pid
|
63
77
|
pid_file.write
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
78
|
+
|
79
|
+
Process.detach(pid)
|
80
|
+
else
|
81
|
+
fork do
|
82
|
+
pid_file = new(identifier, pid: Process.pid)
|
83
|
+
pid_file.write
|
84
|
+
STDOUT.reopen(pid_file.log_path, "w")
|
85
|
+
STDERR.reopen(pid_file.log_path, "w")
|
86
|
+
STDIN.reopen("/dev/null", "r")
|
87
|
+
Process.setsid
|
88
|
+
exec(*args)
|
89
|
+
end
|
69
90
|
end
|
91
|
+
|
70
92
|
sleep(0.1)
|
71
93
|
for_ident(identifier)
|
72
94
|
end
|
@@ -106,10 +128,11 @@ module ShopifyCli
|
|
106
128
|
end
|
107
129
|
end
|
108
130
|
|
109
|
-
def initialize(identifier, pid
|
131
|
+
def initialize(identifier, pid: nil, time: Time.now.strftime('%s')) # :nodoc:
|
110
132
|
@identifier = identifier
|
111
133
|
@pid = pid
|
112
134
|
@time = time
|
135
|
+
FileUtils.mkdir_p(ShopifyCli::ProcessSupervision.run_dir)
|
113
136
|
@pid_path = File.join(ShopifyCli::ProcessSupervision.run_dir, "#{identifier}.pid")
|
114
137
|
@log_path = File.join(ShopifyCli::ProcessSupervision.run_dir, "#{identifier}.log")
|
115
138
|
end
|
@@ -117,13 +140,17 @@ module ShopifyCli
|
|
117
140
|
##
|
118
141
|
# will attempt to shutdown a running process
|
119
142
|
#
|
143
|
+
# #### Parameters
|
144
|
+
#
|
145
|
+
# * `ctx` - the context of this command
|
146
|
+
#
|
120
147
|
# #### Returns
|
121
148
|
#
|
122
149
|
# * `stopped` - [true, false]
|
123
150
|
#
|
124
151
|
def stop
|
125
|
-
unlink
|
126
152
|
kill_proc
|
153
|
+
unlink
|
127
154
|
true
|
128
155
|
rescue
|
129
156
|
false
|
@@ -159,7 +186,11 @@ module ShopifyCli
|
|
159
186
|
end
|
160
187
|
|
161
188
|
def kill_proc
|
162
|
-
|
189
|
+
if Context.new.windows?
|
190
|
+
kill(pid)
|
191
|
+
else
|
192
|
+
kill(-pid) # process group
|
193
|
+
end
|
163
194
|
rescue Errno::ESRCH
|
164
195
|
begin
|
165
196
|
kill(pid)
|
@@ -169,12 +200,18 @@ module ShopifyCli
|
|
169
200
|
end
|
170
201
|
|
171
202
|
def kill(id)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
203
|
+
ctx = Context.new
|
204
|
+
|
205
|
+
# Windows does not handle SIGTERM, go straight to SIGKILL
|
206
|
+
unless ctx.windows?
|
207
|
+
Process.kill('TERM', id)
|
208
|
+
50.times do
|
209
|
+
sleep 0.1
|
210
|
+
break unless stat(id)
|
211
|
+
end
|
176
212
|
end
|
177
213
|
Process.kill('KILL', id) if stat(id)
|
214
|
+
sleep(0.1) if ctx.windows? # Give Windows a second to actually close the process
|
178
215
|
end
|
179
216
|
|
180
217
|
def stat(id)
|