shopify-cli 1.3.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +2 -2
- data/.github/CONTRIBUTING.md +9 -1
- data/.github/PULL_REQUEST_TEMPLATE.md +10 -1
- data/.github/workflows/release.yml +61 -0
- data/.github/workflows/triage.yml +22 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +61 -8
- data/.rubocop_todo.yml +11 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile +3 -2
- data/Gemfile.lock +39 -37
- data/README.md +39 -7
- data/RELEASING.md +19 -29
- data/Rakefile +2 -0
- data/dev.yml +2 -2
- data/docs/_config.yml +1 -18
- data/docs/app/node/commands/index.md +2 -80
- data/docs/app/node/index.md +2 -33
- data/docs/app/rails/commands/index.md +2 -78
- data/docs/app/rails/index.md +2 -34
- data/docs/core/index.md +2 -84
- data/docs/getting-started/index.md +2 -25
- data/docs/getting-started/install/index.md +1 -118
- data/docs/getting-started/migrate/index.md +2 -94
- data/docs/getting-started/uninstall/index.md +2 -35
- data/docs/getting-started/upgrade/index.md +2 -39
- data/docs/help/start-app/index.md +2 -4
- data/docs/index.md +2 -24
- data/install.sh +1 -1
- data/lib/project_types/extension/cli.rb +21 -11
- data/lib/project_types/extension/commands/extension_command.rb +2 -2
- data/lib/project_types/extension/features/argo.rb +117 -0
- data/lib/project_types/extension/forms/create.rb +2 -2
- data/lib/project_types/extension/models/specification.rb +35 -0
- data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +19 -0
- data/lib/project_types/extension/models/specification_handlers/default.rb +67 -0
- data/lib/project_types/extension/models/specifications.rb +77 -0
- data/lib/project_types/extension/tasks/configure_features.rb +52 -0
- data/lib/project_types/extension/tasks/fetch_specifications.rb +38 -0
- data/lib/project_types/node/cli.rb +4 -1
- data/lib/project_types/node/commands/connect.rb +15 -0
- data/lib/project_types/node/commands/create.rb +10 -4
- data/lib/project_types/node/commands/generate.rb +2 -11
- data/lib/project_types/node/messages/messages.rb +16 -50
- data/lib/project_types/rails/cli.rb +4 -1
- data/lib/project_types/rails/commands/connect.rb +15 -0
- data/lib/project_types/rails/commands/create.rb +15 -12
- data/lib/project_types/rails/forms/create.rb +1 -1
- data/lib/project_types/rails/gem.rb +1 -1
- data/lib/project_types/rails/messages/messages.rb +8 -5
- data/lib/project_types/script/cli.rb +9 -5
- data/lib/project_types/script/commands/create.rb +6 -4
- data/lib/project_types/script/commands/enable.rb +12 -4
- data/lib/project_types/script/commands/push.rb +5 -13
- data/lib/project_types/script/config/extension_points.yml +17 -12
- data/lib/project_types/script/errors.rb +21 -0
- data/lib/project_types/script/forms/create.rb +26 -2
- data/lib/project_types/script/graphql/app_script_update_or_create.graphql +10 -1
- data/lib/project_types/script/layers/application/build_script.rb +18 -17
- data/lib/project_types/script/layers/application/create_script.rb +12 -10
- data/lib/project_types/script/layers/application/extension_points.rb +24 -0
- data/lib/project_types/script/layers/application/push_script.rb +18 -16
- data/lib/project_types/script/layers/domain/errors.rb +7 -0
- data/lib/project_types/script/layers/domain/extension_point.rb +62 -7
- data/lib/project_types/script/layers/domain/metadata.rb +55 -0
- data/lib/project_types/script/layers/domain/push_package.rb +25 -6
- data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +17 -52
- data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +42 -11
- data/lib/project_types/script/layers/infrastructure/errors.rb +16 -0
- data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +10 -4
- data/lib/project_types/script/layers/infrastructure/project_creator.rb +2 -1
- data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +25 -13
- data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +72 -0
- data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +59 -0
- data/lib/project_types/script/layers/infrastructure/script_service.rb +9 -1
- data/lib/project_types/script/layers/infrastructure/task_runner.rb +4 -3
- data/lib/project_types/script/messages/messages.rb +55 -4
- data/lib/project_types/script/script_project.rb +25 -16
- data/lib/project_types/script/ui/error_handler.rb +59 -1
- data/lib/project_types/theme/cli.rb +40 -0
- data/lib/project_types/theme/commands/connect.rb +54 -0
- data/lib/project_types/theme/commands/create.rb +48 -0
- data/lib/project_types/theme/commands/deploy.rb +38 -0
- data/lib/project_types/theme/commands/generate.rb +20 -0
- data/lib/project_types/theme/commands/generate/env.rb +79 -0
- data/lib/project_types/theme/commands/push.rb +55 -0
- data/lib/project_types/theme/commands/serve.rb +31 -0
- data/lib/project_types/theme/forms/connect.rb +34 -0
- data/lib/project_types/theme/forms/create.rb +22 -0
- data/lib/project_types/theme/messages/messages.rb +147 -0
- data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +78 -0
- data/lib/project_types/theme/themekit.rb +113 -0
- data/lib/shopify-cli/admin_api.rb +42 -2
- data/lib/shopify-cli/api.rb +34 -33
- data/lib/shopify-cli/commands/config.rb +24 -0
- data/lib/shopify-cli/commands/connect.rb +32 -15
- data/lib/shopify-cli/commands/system.rb +10 -1
- data/lib/shopify-cli/context.rb +23 -2
- data/lib/shopify-cli/core/entry_point.rb +1 -1
- data/lib/shopify-cli/core/monorail.rb +6 -4
- data/lib/shopify-cli/feature.rb +0 -2
- data/lib/shopify-cli/http_request.rb +27 -0
- data/lib/shopify-cli/js_deps.rb +1 -1
- data/lib/shopify-cli/messages/messages.rb +31 -7
- data/lib/shopify-cli/method_object.rb +104 -0
- data/lib/shopify-cli/partners_api.rb +25 -3
- data/lib/shopify-cli/process_supervision.rb +1 -1
- data/lib/shopify-cli/project.rb +12 -8
- data/lib/shopify-cli/project_type.rb +18 -2
- data/lib/shopify-cli/resolve_constant.rb +25 -0
- data/lib/shopify-cli/result.rb +432 -0
- data/lib/shopify-cli/shopifolk.rb +87 -0
- data/lib/shopify-cli/task.rb +8 -0
- data/lib/shopify-cli/tasks/create_api_client.rb +13 -2
- data/lib/shopify-cli/tasks/ensure_env.rb +3 -0
- data/lib/shopify-cli/tasks/select_org_and_shop.rb +10 -5
- data/lib/shopify-cli/tunnel.rb +8 -2
- data/lib/shopify-cli/version.rb +1 -1
- data/lib/shopify_cli.rb +5 -1
- data/shopify.fish +1 -1
- data/shopify.sh +1 -1
- data/vendor/deps/cli-kit/REVISION +1 -1
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +2 -2
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +3 -3
- data/vendor/deps/cli-ui/REVISION +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui.rb +26 -22
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +4 -6
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -3
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +8 -9
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +15 -3
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +4 -11
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -5
- data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +10 -10
- data/vendor/deps/cli-ui/lib/cli/ui/version.rb +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +56 -0
- data/vendor/deps/webrick/.gitignore +9 -0
- data/vendor/deps/webrick/Gemfile +3 -0
- data/vendor/deps/webrick/LICENSE.txt +22 -0
- data/vendor/deps/webrick/README.md +61 -0
- data/vendor/deps/webrick/Rakefile +10 -0
- data/vendor/deps/webrick/lib/webrick.rb +232 -0
- data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
- data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
- data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
- data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
- data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
- data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
- data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
- data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
- data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
- data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
- data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
- data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
- data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
- data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
- data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
- data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
- data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
- data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
- data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
- data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
- data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
- data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
- data/vendor/deps/webrick/webrick.gemspec +74 -0
- metadata +77 -27
- data/docs/Gemfile +0 -5
- data/docs/Gemfile.lock +0 -258
- data/docs/_data/nav.yml +0 -35
- data/docs/_includes/footer.html +0 -15
- data/docs/_includes/head.html +0 -19
- data/docs/_includes/sidebar_nav.html +0 -22
- data/docs/_includes/toc.html +0 -112
- data/docs/_layouts/default.html +0 -79
- data/docs/css/docs.css +0 -157
- data/docs/images/header.png +0 -0
- data/docs/installing-ruby.md +0 -28
- data/lib/project_types/extension/features/argo/admin.rb +0 -20
- data/lib/project_types/extension/features/argo/base.rb +0 -129
- data/lib/project_types/extension/features/argo/checkout.rb +0 -20
- data/lib/project_types/extension/models/type.rb +0 -81
- data/lib/project_types/extension/models/types/checkout_post_purchase.rb +0 -23
- data/lib/project_types/extension/models/types/product_subscription.rb +0 -24
- data/lib/project_types/node/commands/generate/billing.rb +0 -39
- data/lib/project_types/node/commands/generate/page.rb +0 -59
- data/lib/project_types/node/commands/generate/webhook.rb +0 -37
- data/lib/project_types/script/layers/domain/script.rb +0 -18
- data/lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb +0 -38
- data/lib/project_types/script/layers/infrastructure/script_repository.rb +0 -59
- data/lib/project_types/script/templates/ts/as-pect.config.js +0 -27
- data/lib/project_types/script/templates/ts/as-pect.d.ts +0 -1
@@ -5,13 +5,12 @@ module CLI
|
|
5
5
|
COLOR_ENVVAR = 'CLI_FRAME_STACK'
|
6
6
|
STYLE_ENVVAR = 'CLI_STYLE_STACK'
|
7
7
|
|
8
|
-
StackItem
|
9
|
-
|
10
|
-
@color ||= CLI::UI.resolve_color(color_name)
|
11
|
-
end
|
8
|
+
class StackItem
|
9
|
+
attr_reader :color, :frame_style
|
12
10
|
|
13
|
-
def
|
14
|
-
@
|
11
|
+
def initialize(color_name, style_name)
|
12
|
+
@color = CLI::UI.resolve_color(color_name)
|
13
|
+
@frame_style = CLI::UI.resolve_style(style_name)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
@@ -55,7 +54,7 @@ module CLI
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
item ||= StackItem.new(color
|
57
|
+
item ||= StackItem.new(color, style)
|
59
58
|
|
60
59
|
curr = items
|
61
60
|
curr << item
|
@@ -85,8 +84,8 @@ module CLI
|
|
85
84
|
styles = []
|
86
85
|
|
87
86
|
items.each do |item|
|
88
|
-
colors << item.
|
89
|
-
styles << item.
|
87
|
+
colors << item.color.name
|
88
|
+
styles << item.frame_style.name
|
90
89
|
end
|
91
90
|
|
92
91
|
ENV[COLOR_ENVVAR] = colors.join(':')
|
@@ -39,7 +39,7 @@ module CLI
|
|
39
39
|
def message
|
40
40
|
keys = FrameStyle.loaded_styles.map(&:inspect).join(',')
|
41
41
|
"invalid frame style: #{@name.inspect}" \
|
42
|
-
"-- must be one of CLI::UI::Frame::FrameStyle.loaded_styles " \
|
42
|
+
" -- must be one of CLI::UI::Frame::FrameStyle.loaded_styles " \
|
43
43
|
"(#{keys})"
|
44
44
|
end
|
45
45
|
end
|
@@ -57,6 +57,7 @@ module CLI
|
|
57
57
|
BUG = new('b', 0x1f41b, '!', Color::WHITE) # Bug emoji (🐛)
|
58
58
|
CHEVRON = new('>', 0xbb, '»', Color::YELLOW) # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (»)
|
59
59
|
HOURGLASS = new('H', [0x231b, 0xfe0e], 'H', Color::BLUE) # HOURGLASS + VARIATION SELECTOR 15 (⌛︎)
|
60
|
+
WARNING = new('!', [0x26a0, 0xfe0f], '!', Color::YELLOW) # WARNING SIGN + VARIATION SELECTOR 16 (⚠️ )
|
60
61
|
|
61
62
|
# Looks up a glyph by name
|
62
63
|
#
|
@@ -18,6 +18,7 @@ module CLI
|
|
18
18
|
# * +:encoding+ - Force the output to be in a certain encoding. Defaults to UTF-8.
|
19
19
|
# * +:format+ - Whether to format the string using CLI::UI.fmt. Defaults to true.
|
20
20
|
# * +:graceful+ - Whether to gracefully ignore common I/O errors. Defaults to true.
|
21
|
+
# * +:wrap+ - Whether to wrap text at word boundaries to terminal width. Defaults to true.
|
21
22
|
#
|
22
23
|
# ==== Returns
|
23
24
|
# Returns whether the message was successfully printed,
|
@@ -25,11 +26,22 @@ module CLI
|
|
25
26
|
#
|
26
27
|
# ==== Example
|
27
28
|
#
|
28
|
-
# CLI::UI::Printer.puts('{x} Ouch',
|
29
|
-
#
|
30
|
-
def self.puts(
|
29
|
+
# CLI::UI::Printer.puts('{{x}} Ouch', to: $stderr)
|
30
|
+
#
|
31
|
+
def self.puts(
|
32
|
+
msg,
|
33
|
+
frame_color:
|
34
|
+
nil,
|
35
|
+
to:
|
36
|
+
$stdout,
|
37
|
+
encoding: Encoding::UTF_8,
|
38
|
+
format: true,
|
39
|
+
graceful: true,
|
40
|
+
wrap: true
|
41
|
+
)
|
31
42
|
msg = (+msg).force_encoding(encoding) if encoding
|
32
43
|
msg = CLI::UI.fmt(msg) if format
|
44
|
+
msg = CLI::UI.wrap(msg) if wrap
|
33
45
|
|
34
46
|
if frame_color
|
35
47
|
CLI::UI::Frame.with_frame_color_override(frame_color) { to.puts(msg) }
|
@@ -334,22 +334,15 @@ module CLI
|
|
334
334
|
end
|
335
335
|
|
336
336
|
def read_char
|
337
|
-
|
338
|
-
|
339
|
-
|
337
|
+
if $stdin.tty? && !ENV['TEST']
|
338
|
+
$stdin.getch # raw mode for tty
|
339
|
+
else
|
340
|
+
$stdin.getc
|
340
341
|
end
|
341
342
|
rescue IOError
|
342
343
|
"\e"
|
343
344
|
end
|
344
345
|
|
345
|
-
def raw_tty!
|
346
|
-
if ENV['TEST'] || !$stdin.tty?
|
347
|
-
yield
|
348
|
-
else
|
349
|
-
$stdin.raw { yield }
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
346
|
def presented_options(recalculate: false)
|
354
347
|
return @presented_options unless recalculate
|
355
348
|
|
@@ -12,11 +12,9 @@ module CLI
|
|
12
12
|
|
13
13
|
RUNES = CLI::UI::OS.current.supports_emoji? ? %w(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏).freeze : %w(\\ | / - \\ | / -).freeze
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
GLYPHS = colors.zip(RUNES).map(&:join)
|
19
|
-
end
|
15
|
+
colors = [CLI::UI::Color::CYAN.code] * (RUNES.size / 2).ceil +
|
16
|
+
[CLI::UI::Color::MAGENTA.code] * (RUNES.size / 2).to_i
|
17
|
+
GLYPHS = colors.zip(RUNES).map(&:join)
|
20
18
|
|
21
19
|
class << self
|
22
20
|
attr_accessor(:index)
|
@@ -23,17 +23,17 @@ module CLI
|
|
23
23
|
|
24
24
|
def self.winsize
|
25
25
|
@winsize ||= begin
|
26
|
-
|
27
|
-
|
26
|
+
winsize = IO.console.winsize
|
27
|
+
setup_winsize_trap
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
if winsize.any?(&:zero?)
|
30
|
+
[DEFAULT_HEIGHT, DEFAULT_WIDTH]
|
31
|
+
else
|
32
|
+
winsize
|
33
|
+
end
|
34
|
+
rescue
|
35
|
+
[DEFAULT_HEIGHT, DEFAULT_WIDTH]
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.setup_winsize_trap
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'cli/ui'
|
3
|
+
require 'cli/ui/frame/frame_stack'
|
4
|
+
require 'cli/ui/frame/frame_style'
|
5
|
+
|
6
|
+
module CLI
|
7
|
+
module UI
|
8
|
+
class Wrap
|
9
|
+
def initialize(input)
|
10
|
+
@input = input
|
11
|
+
end
|
12
|
+
|
13
|
+
def wrap
|
14
|
+
max_width = Terminal.width - Frame.prefix_width
|
15
|
+
width = 0
|
16
|
+
final = []
|
17
|
+
# Create an alternation of format codes of parameter lengths 1-20, since + and {1,n} not allowed in lookbehind
|
18
|
+
format_codes = (1..20).map { |n| /\x1b\[[\d;]{#{n}}m/ }.join('|')
|
19
|
+
codes = ''
|
20
|
+
@input.split(/(?=\s|\x1b\[[\d;]+m|\r)|(?<=\s|#{format_codes})/).each do |token|
|
21
|
+
case token
|
22
|
+
when '\x1B[0?m'
|
23
|
+
codes = ''
|
24
|
+
final << token
|
25
|
+
when /\x1b\[[\d;]+m/
|
26
|
+
codes += token # Track in use format codes so that they are resent after frame coloring
|
27
|
+
final << token
|
28
|
+
when "\n"
|
29
|
+
final << "\n#{codes}"
|
30
|
+
width = 0
|
31
|
+
when /\s/
|
32
|
+
token_width = ANSI.printing_width(token)
|
33
|
+
if width + token_width <= max_width
|
34
|
+
final << token
|
35
|
+
width += token_width
|
36
|
+
else
|
37
|
+
final << "\n#{codes}"
|
38
|
+
width = 0
|
39
|
+
end
|
40
|
+
else
|
41
|
+
token_width = ANSI.printing_width(token)
|
42
|
+
if width + token_width <= max_width
|
43
|
+
final << token
|
44
|
+
width += token_width
|
45
|
+
else
|
46
|
+
final << "\n#{codes}"
|
47
|
+
final << token
|
48
|
+
width = token_width
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
final.join
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Webrick
|
2
|
+
|
3
|
+
WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server.
|
4
|
+
|
5
|
+
WEBrick features complete logging of both server operations and HTTP access.
|
6
|
+
|
7
|
+
WEBrick supports both basic and digest authentication in addition to algorithms not in RFC 2617.
|
8
|
+
|
9
|
+
A WEBrick server can be composed of multiple WEBrick servers or servlets to provide differing behavior on a per-host or per-path basis. WEBrick includes servlets for handling CGI scripts, ERB pages, Ruby blocks and directory listings.
|
10
|
+
|
11
|
+
WEBrick also includes tools for daemonizing a process and starting a process at a higher privilege level and dropping permissions.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'webrick'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install webrick
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
To create a new WEBrick::HTTPServer that will listen to connections on port 8000 and serve documents from the current user's public_html folder:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'webrick'
|
35
|
+
|
36
|
+
root = File.expand_path '~/public_html'
|
37
|
+
server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
|
38
|
+
```
|
39
|
+
|
40
|
+
To run the server you will need to provide a suitable shutdown hook as
|
41
|
+
starting the server blocks the current thread:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
trap 'INT' do server.shutdown end
|
45
|
+
|
46
|
+
server.start
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and Patch are welcome on https://bugs.ruby-lang.org/.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
|
@@ -0,0 +1,232 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
##
|
3
|
+
# = WEB server toolkit.
|
4
|
+
#
|
5
|
+
# WEBrick is an HTTP server toolkit that can be configured as an HTTPS server,
|
6
|
+
# a proxy server, and a virtual-host server. WEBrick features complete
|
7
|
+
# logging of both server operations and HTTP access. WEBrick supports both
|
8
|
+
# basic and digest authentication in addition to algorithms not in RFC 2617.
|
9
|
+
#
|
10
|
+
# A WEBrick server can be composed of multiple WEBrick servers or servlets to
|
11
|
+
# provide differing behavior on a per-host or per-path basis. WEBrick
|
12
|
+
# includes servlets for handling CGI scripts, ERB pages, Ruby blocks and
|
13
|
+
# directory listings.
|
14
|
+
#
|
15
|
+
# WEBrick also includes tools for daemonizing a process and starting a process
|
16
|
+
# at a higher privilege level and dropping permissions.
|
17
|
+
#
|
18
|
+
# == Security
|
19
|
+
#
|
20
|
+
# *Warning:* WEBrick is not recommended for production. It only implements
|
21
|
+
# basic security checks.
|
22
|
+
#
|
23
|
+
# == Starting an HTTP server
|
24
|
+
#
|
25
|
+
# To create a new WEBrick::HTTPServer that will listen to connections on port
|
26
|
+
# 8000 and serve documents from the current user's public_html folder:
|
27
|
+
#
|
28
|
+
# require 'webrick'
|
29
|
+
#
|
30
|
+
# root = File.expand_path '~/public_html'
|
31
|
+
# server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
|
32
|
+
#
|
33
|
+
# To run the server you will need to provide a suitable shutdown hook as
|
34
|
+
# starting the server blocks the current thread:
|
35
|
+
#
|
36
|
+
# trap 'INT' do server.shutdown end
|
37
|
+
#
|
38
|
+
# server.start
|
39
|
+
#
|
40
|
+
# == Custom Behavior
|
41
|
+
#
|
42
|
+
# The easiest way to have a server perform custom operations is through
|
43
|
+
# WEBrick::HTTPServer#mount_proc. The block given will be called with a
|
44
|
+
# WEBrick::HTTPRequest with request info and a WEBrick::HTTPResponse which
|
45
|
+
# must be filled in appropriately:
|
46
|
+
#
|
47
|
+
# server.mount_proc '/' do |req, res|
|
48
|
+
# res.body = 'Hello, world!'
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# Remember that +server.mount_proc+ must precede +server.start+.
|
52
|
+
#
|
53
|
+
# == Servlets
|
54
|
+
#
|
55
|
+
# Advanced custom behavior can be obtained through mounting a subclass of
|
56
|
+
# WEBrick::HTTPServlet::AbstractServlet. Servlets provide more modularity
|
57
|
+
# when writing an HTTP server than mount_proc allows. Here is a simple
|
58
|
+
# servlet:
|
59
|
+
#
|
60
|
+
# class Simple < WEBrick::HTTPServlet::AbstractServlet
|
61
|
+
# def do_GET request, response
|
62
|
+
# status, content_type, body = do_stuff_with request
|
63
|
+
#
|
64
|
+
# response.status = 200
|
65
|
+
# response['Content-Type'] = 'text/plain'
|
66
|
+
# response.body = 'Hello, World!'
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# To initialize the servlet you mount it on the server:
|
71
|
+
#
|
72
|
+
# server.mount '/simple', Simple
|
73
|
+
#
|
74
|
+
# See WEBrick::HTTPServlet::AbstractServlet for more details.
|
75
|
+
#
|
76
|
+
# == Virtual Hosts
|
77
|
+
#
|
78
|
+
# A server can act as a virtual host for multiple host names. After creating
|
79
|
+
# the listening host, additional hosts that do not listen can be created and
|
80
|
+
# attached as virtual hosts:
|
81
|
+
#
|
82
|
+
# server = WEBrick::HTTPServer.new # ...
|
83
|
+
#
|
84
|
+
# vhost = WEBrick::HTTPServer.new :ServerName => 'vhost.example',
|
85
|
+
# :DoNotListen => true, # ...
|
86
|
+
# vhost.mount '/', ...
|
87
|
+
#
|
88
|
+
# server.virtual_host vhost
|
89
|
+
#
|
90
|
+
# If no +:DocumentRoot+ is provided and no servlets or procs are mounted on the
|
91
|
+
# main server it will return 404 for all URLs.
|
92
|
+
#
|
93
|
+
# == HTTPS
|
94
|
+
#
|
95
|
+
# To create an HTTPS server you only need to enable SSL and provide an SSL
|
96
|
+
# certificate name:
|
97
|
+
#
|
98
|
+
# require 'webrick'
|
99
|
+
# require 'webrick/https'
|
100
|
+
#
|
101
|
+
# cert_name = [
|
102
|
+
# %w[CN localhost],
|
103
|
+
# ]
|
104
|
+
#
|
105
|
+
# server = WEBrick::HTTPServer.new(:Port => 8000,
|
106
|
+
# :SSLEnable => true,
|
107
|
+
# :SSLCertName => cert_name)
|
108
|
+
#
|
109
|
+
# This will start the server with a self-generated self-signed certificate.
|
110
|
+
# The certificate will be changed every time the server is restarted.
|
111
|
+
#
|
112
|
+
# To create a server with a pre-determined key and certificate you can provide
|
113
|
+
# them:
|
114
|
+
#
|
115
|
+
# require 'webrick'
|
116
|
+
# require 'webrick/https'
|
117
|
+
# require 'openssl'
|
118
|
+
#
|
119
|
+
# cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
|
120
|
+
# pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'
|
121
|
+
#
|
122
|
+
# server = WEBrick::HTTPServer.new(:Port => 8000,
|
123
|
+
# :SSLEnable => true,
|
124
|
+
# :SSLCertificate => cert,
|
125
|
+
# :SSLPrivateKey => pkey)
|
126
|
+
#
|
127
|
+
# == Proxy Server
|
128
|
+
#
|
129
|
+
# WEBrick can act as a proxy server:
|
130
|
+
#
|
131
|
+
# require 'webrick'
|
132
|
+
# require 'webrick/httpproxy'
|
133
|
+
#
|
134
|
+
# proxy = WEBrick::HTTPProxyServer.new :Port => 8000
|
135
|
+
#
|
136
|
+
# trap 'INT' do proxy.shutdown end
|
137
|
+
#
|
138
|
+
# See WEBrick::HTTPProxy for further details including modifying proxied
|
139
|
+
# responses.
|
140
|
+
#
|
141
|
+
# == Basic and Digest authentication
|
142
|
+
#
|
143
|
+
# WEBrick provides both Basic and Digest authentication for regular and proxy
|
144
|
+
# servers. See WEBrick::HTTPAuth, WEBrick::HTTPAuth::BasicAuth and
|
145
|
+
# WEBrick::HTTPAuth::DigestAuth.
|
146
|
+
#
|
147
|
+
# == WEBrick as a daemonized Web Server
|
148
|
+
#
|
149
|
+
# WEBrick can be run as a daemonized server for small loads.
|
150
|
+
#
|
151
|
+
# === Daemonizing
|
152
|
+
#
|
153
|
+
# To start a WEBrick server as a daemon simple run WEBrick::Daemon.start
|
154
|
+
# before starting the server.
|
155
|
+
#
|
156
|
+
# === Dropping Permissions
|
157
|
+
#
|
158
|
+
# WEBrick can be started as one user to gain permission to bind to port 80 or
|
159
|
+
# 443 for serving HTTP or HTTPS traffic then can drop these permissions for
|
160
|
+
# regular operation. To listen on all interfaces for HTTP traffic:
|
161
|
+
#
|
162
|
+
# sockets = WEBrick::Utils.create_listeners nil, 80
|
163
|
+
#
|
164
|
+
# Then drop privileges:
|
165
|
+
#
|
166
|
+
# WEBrick::Utils.su 'www'
|
167
|
+
#
|
168
|
+
# Then create a server that does not listen by default:
|
169
|
+
#
|
170
|
+
# server = WEBrick::HTTPServer.new :DoNotListen => true, # ...
|
171
|
+
#
|
172
|
+
# Then overwrite the listening sockets with the port 80 sockets:
|
173
|
+
#
|
174
|
+
# server.listeners.replace sockets
|
175
|
+
#
|
176
|
+
# === Logging
|
177
|
+
#
|
178
|
+
# WEBrick can separately log server operations and end-user access. For
|
179
|
+
# server operations:
|
180
|
+
#
|
181
|
+
# log_file = File.open '/var/log/webrick.log', 'a+'
|
182
|
+
# log = WEBrick::Log.new log_file
|
183
|
+
#
|
184
|
+
# For user access logging:
|
185
|
+
#
|
186
|
+
# access_log = [
|
187
|
+
# [log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
|
188
|
+
# ]
|
189
|
+
#
|
190
|
+
# server = WEBrick::HTTPServer.new :Logger => log, :AccessLog => access_log
|
191
|
+
#
|
192
|
+
# See WEBrick::AccessLog for further log formats.
|
193
|
+
#
|
194
|
+
# === Log Rotation
|
195
|
+
#
|
196
|
+
# To rotate logs in WEBrick on a HUP signal (like syslogd can send), open the
|
197
|
+
# log file in 'a+' mode (as above) and trap 'HUP' to reopen the log file:
|
198
|
+
#
|
199
|
+
# trap 'HUP' do log_file.reopen '/path/to/webrick.log', 'a+'
|
200
|
+
#
|
201
|
+
# == Copyright
|
202
|
+
#
|
203
|
+
# Author: IPR -- Internet Programming with Ruby -- writers
|
204
|
+
#
|
205
|
+
# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
|
206
|
+
# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
|
207
|
+
# reserved.
|
208
|
+
#--
|
209
|
+
# $IPR: webrick.rb,v 1.12 2002/10/01 17:16:31 gotoyuzo Exp $
|
210
|
+
|
211
|
+
module WEBrick
|
212
|
+
end
|
213
|
+
|
214
|
+
require 'webrick/compat.rb'
|
215
|
+
|
216
|
+
require 'webrick/version.rb'
|
217
|
+
require 'webrick/config.rb'
|
218
|
+
require 'webrick/log.rb'
|
219
|
+
require 'webrick/server.rb'
|
220
|
+
require_relative 'webrick/utils.rb'
|
221
|
+
require 'webrick/accesslog'
|
222
|
+
|
223
|
+
require 'webrick/htmlutils.rb'
|
224
|
+
require 'webrick/httputils.rb'
|
225
|
+
require 'webrick/cookie.rb'
|
226
|
+
require 'webrick/httpversion.rb'
|
227
|
+
require 'webrick/httpstatus.rb'
|
228
|
+
require 'webrick/httprequest.rb'
|
229
|
+
require 'webrick/httpresponse.rb'
|
230
|
+
require 'webrick/httpserver.rb'
|
231
|
+
require 'webrick/httpservlet.rb'
|
232
|
+
require 'webrick/httpauth.rb'
|