fluid_cli 0.1.9 → 0.2.1
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/README.md +200 -1
- data/exe/fluid +12 -17
- data/lib/fluid_cli/version.rb +1 -1
- data/lib/fluid_cli.rb +4 -62
- metadata +14 -278
- data/Rakefile +0 -26
- data/dev.yml +0 -5
- data/lib/fluid_cli/api.rb +0 -141
- data/lib/fluid_cli/assets/post_auth_page/index.html.erb +0 -34
- data/lib/fluid_cli/assets/post_auth_page/style.css +0 -58
- data/lib/fluid_cli/command.rb +0 -55
- data/lib/fluid_cli/commands/help.rb +0 -21
- data/lib/fluid_cli/commands/login.rb +0 -30
- data/lib/fluid_cli/commands/logout.rb +0 -38
- data/lib/fluid_cli/commands/switch.rb +0 -23
- data/lib/fluid_cli/commands/theme/common/company_helper.rb +0 -15
- data/lib/fluid_cli/commands/theme/common/root_helper.rb +0 -95
- data/lib/fluid_cli/commands/theme/dev.rb +0 -62
- data/lib/fluid_cli/commands/theme/help.rb +0 -21
- data/lib/fluid_cli/commands/theme/init.rb +0 -46
- data/lib/fluid_cli/commands/theme/navigate.rb +0 -57
- data/lib/fluid_cli/commands/theme/pull.rb +0 -68
- data/lib/fluid_cli/commands/theme/push.rb +0 -132
- data/lib/fluid_cli/commands/theme.rb +0 -24
- data/lib/fluid_cli/commands/whoami.rb +0 -23
- data/lib/fluid_cli/commands.rb +0 -19
- data/lib/fluid_cli/company_switcher.rb +0 -69
- data/lib/fluid_cli/context.rb +0 -691
- data/lib/fluid_cli/db.rb +0 -114
- data/lib/fluid_cli/entry_point.rb +0 -10
- data/lib/fluid_cli/environment.rb +0 -32
- data/lib/fluid_cli/file_system_listener.rb +0 -29
- data/lib/fluid_cli/form.rb +0 -42
- data/lib/fluid_cli/git.rb +0 -319
- data/lib/fluid_cli/http_request.rb +0 -60
- data/lib/fluid_cli/identity_auth/servlet.rb +0 -39
- data/lib/fluid_cli/identity_auth.rb +0 -126
- data/lib/fluid_cli/options.rb +0 -38
- data/lib/fluid_cli/packager.rb +0 -36
- data/lib/fluid_cli/theme/dev_server/certificate_manager.rb +0 -79
- data/lib/fluid_cli/theme/dev_server/errors.rb +0 -9
- data/lib/fluid_cli/theme/dev_server/header_hash.rb +0 -98
- data/lib/fluid_cli/theme/dev_server/hooks/file_change_hook.rb +0 -39
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot-reload-no-script.html +0 -27
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot_reload.js +0 -28
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/sse_client.js +0 -43
- data/lib/fluid_cli/theme/dev_server/hot_reload/resources/theme.js +0 -16
- data/lib/fluid_cli/theme/dev_server/hot_reload/script_injector.rb +0 -54
- data/lib/fluid_cli/theme/dev_server/hot_reload.rb +0 -75
- data/lib/fluid_cli/theme/dev_server/local_assets.rb +0 -92
- data/lib/fluid_cli/theme/dev_server/proxy.rb +0 -235
- data/lib/fluid_cli/theme/dev_server/proxy_param_builder.rb +0 -82
- data/lib/fluid_cli/theme/dev_server/reload_mode.rb +0 -34
- data/lib/fluid_cli/theme/dev_server/sse.rb +0 -75
- data/lib/fluid_cli/theme/dev_server/watcher.rb +0 -57
- data/lib/fluid_cli/theme/dev_server/web_server.rb +0 -140
- data/lib/fluid_cli/theme/dev_server.rb +0 -308
- data/lib/fluid_cli/theme/development_theme.rb +0 -101
- data/lib/fluid_cli/theme/file.rb +0 -130
- data/lib/fluid_cli/theme/forms/select.rb +0 -33
- data/lib/fluid_cli/theme/mime_type.rb +0 -34
- data/lib/fluid_cli/theme/navigation/resource_fetcher.rb +0 -25
- data/lib/fluid_cli/theme/navigation/route_navigator.rb +0 -87
- data/lib/fluid_cli/theme/presenters/theme_presenter.rb +0 -49
- data/lib/fluid_cli/theme/presenters/themes_presenter.rb +0 -31
- data/lib/fluid_cli/theme/root.rb +0 -62
- data/lib/fluid_cli/theme/schema_validator.rb +0 -274
- data/lib/fluid_cli/theme/syncer/checksums.rb +0 -66
- data/lib/fluid_cli/theme/syncer/downloader.rb +0 -54
- data/lib/fluid_cli/theme/syncer/error_reporter.rb +0 -45
- data/lib/fluid_cli/theme/syncer/merger.rb +0 -53
- data/lib/fluid_cli/theme/syncer/operation.rb +0 -58
- data/lib/fluid_cli/theme/syncer/standard_reporter.rb +0 -32
- data/lib/fluid_cli/theme/syncer/unsupported_script_warning.rb +0 -90
- data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all.rb +0 -41
- data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all_form.rb +0 -37
- data/lib/fluid_cli/theme/syncer/uploader/forms/base_strategy_form.rb +0 -64
- data/lib/fluid_cli/theme/syncer/uploader/forms/select_delete_strategy.rb +0 -29
- data/lib/fluid_cli/theme/syncer/uploader/forms/select_update_strategy.rb +0 -30
- data/lib/fluid_cli/theme/syncer/uploader/json_delete_handler.rb +0 -49
- data/lib/fluid_cli/theme/syncer/uploader/json_update_handler.rb +0 -71
- data/lib/fluid_cli/theme/syncer/uploader.rb +0 -105
- data/lib/fluid_cli/theme/syncer.rb +0 -500
- data/lib/fluid_cli/theme/theme.rb +0 -186
- data/lib/fluid_cli/theme/ui/sync_progress_bar.rb +0 -22
- data/lib/fluid_cli/thread_pool/job.rb +0 -35
- data/lib/fluid_cli/thread_pool.rb +0 -49
- data/packaging/homebrew/fluid_cli.base.rb +0 -103
- data/vendor/deps/base64/.document +0 -5
- data/vendor/deps/base64/.gitignore +0 -9
- data/vendor/deps/base64/BSDL +0 -22
- data/vendor/deps/base64/COPYING +0 -56
- data/vendor/deps/base64/Gemfile +0 -9
- data/vendor/deps/base64/LEGAL +0 -60
- data/vendor/deps/base64/README.md +0 -48
- data/vendor/deps/base64/Rakefile +0 -31
- data/vendor/deps/base64/base64.gemspec +0 -28
- data/vendor/deps/base64/bin/console +0 -14
- data/vendor/deps/base64/bin/setup +0 -8
- data/vendor/deps/base64/lib/base64.rb +0 -382
- data/vendor/deps/base64/sig/base64.rbs +0 -358
- data/vendor/deps/base64/test/base64/test_base64.rb +0 -115
- data/vendor/deps/base64/test_sig/test_base64.rb +0 -44
- data/vendor/deps/cli-kit/REVISION +0 -1
- data/vendor/deps/cli-kit/lib/cli/kit/args/definition.rb +0 -286
- data/vendor/deps/cli-kit/lib/cli/kit/args/evaluation.rb +0 -215
- data/vendor/deps/cli-kit/lib/cli/kit/args/parser/node.rb +0 -128
- data/vendor/deps/cli-kit/lib/cli/kit/args/parser.rb +0 -125
- data/vendor/deps/cli-kit/lib/cli/kit/args/tokenizer.rb +0 -130
- data/vendor/deps/cli-kit/lib/cli/kit/args.rb +0 -16
- data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +0 -30
- data/vendor/deps/cli-kit/lib/cli/kit/command_help.rb +0 -268
- data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +0 -150
- data/vendor/deps/cli-kit/lib/cli/kit/config.rb +0 -137
- data/vendor/deps/cli-kit/lib/cli/kit/core_ext.rb +0 -28
- data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +0 -166
- data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +0 -92
- data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +0 -91
- data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +0 -92
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +0 -94
- data/vendor/deps/cli-kit/lib/cli/kit/opts.rb +0 -248
- data/vendor/deps/cli-kit/lib/cli/kit/parse_args.rb +0 -55
- data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +0 -66
- data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +0 -260
- data/vendor/deps/cli-kit/lib/cli/kit/support.rb +0 -11
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +0 -290
- data/vendor/deps/cli-kit/lib/cli/kit/util.rb +0 -118
- data/vendor/deps/cli-kit/lib/cli/kit/version.rb +0 -7
- data/vendor/deps/cli-kit/lib/cli/kit.rb +0 -139
- data/vendor/deps/cli-ui/REVISION +0 -1
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +0 -218
- data/vendor/deps/cli-ui/lib/cli/ui/color.rb +0 -101
- data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +0 -219
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +0 -67
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +0 -179
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +0 -152
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +0 -127
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +0 -286
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +0 -92
- data/vendor/deps/cli-ui/lib/cli/ui/os.rb +0 -63
- data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +0 -64
- data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +0 -132
- data/vendor/deps/cli-ui/lib/cli/ui/progress_reporter.rb +0 -209
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +0 -583
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +0 -36
- data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +0 -381
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +0 -48
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +0 -602
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +0 -79
- data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +0 -399
- data/vendor/deps/cli-ui/lib/cli/ui/table.rb +0 -83
- data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +0 -55
- data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +0 -106
- data/vendor/deps/cli-ui/lib/cli/ui/version.rb +0 -8
- data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +0 -46
- data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +0 -79
- data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +0 -89
- data/vendor/deps/cli-ui/lib/cli/ui/work_queue.rb +0 -142
- data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +0 -61
- data/vendor/deps/cli-ui/lib/cli/ui.rb +0 -359
- data/vendor/deps/cli-ui/vendor/reentrant_mutex.rb +0 -78
- data/vendor/deps/webrick/.gitignore +0 -9
- data/vendor/deps/webrick/Gemfile +0 -3
- data/vendor/deps/webrick/LICENSE.txt +0 -22
- data/vendor/deps/webrick/README.md +0 -61
- data/vendor/deps/webrick/Rakefile +0 -10
- data/vendor/deps/webrick/lib/webrick/accesslog.rb +0 -157
- data/vendor/deps/webrick/lib/webrick/cgi.rb +0 -313
- data/vendor/deps/webrick/lib/webrick/compat.rb +0 -36
- data/vendor/deps/webrick/lib/webrick/config.rb +0 -158
- data/vendor/deps/webrick/lib/webrick/cookie.rb +0 -172
- data/vendor/deps/webrick/lib/webrick/htmlutils.rb +0 -30
- data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +0 -117
- data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +0 -116
- data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +0 -395
- data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +0 -132
- data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +0 -97
- data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +0 -158
- data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +0 -53
- data/vendor/deps/webrick/lib/webrick/httpauth.rb +0 -96
- data/vendor/deps/webrick/lib/webrick/httpproxy.rb +0 -354
- data/vendor/deps/webrick/lib/webrick/httprequest.rb +0 -636
- data/vendor/deps/webrick/lib/webrick/httpresponse.rb +0 -564
- data/vendor/deps/webrick/lib/webrick/https.rb +0 -152
- data/vendor/deps/webrick/lib/webrick/httpserver.rb +0 -294
- data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +0 -152
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +0 -47
- data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +0 -126
- data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +0 -88
- data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +0 -552
- data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +0 -47
- data/vendor/deps/webrick/lib/webrick/httpservlet.rb +0 -23
- data/vendor/deps/webrick/lib/webrick/httpstatus.rb +0 -194
- data/vendor/deps/webrick/lib/webrick/httputils.rb +0 -512
- data/vendor/deps/webrick/lib/webrick/httpversion.rb +0 -76
- data/vendor/deps/webrick/lib/webrick/log.rb +0 -156
- data/vendor/deps/webrick/lib/webrick/server.rb +0 -381
- data/vendor/deps/webrick/lib/webrick/ssl.rb +0 -215
- data/vendor/deps/webrick/lib/webrick/utils.rb +0 -265
- data/vendor/deps/webrick/lib/webrick/version.rb +0 -18
- data/vendor/deps/webrick/lib/webrick.rb +0 -232
- data/vendor/deps/webrick/webrick.gemspec +0 -74
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "forwardable"
|
|
4
|
-
|
|
5
|
-
require_relative "uploader/json_delete_handler"
|
|
6
|
-
require_relative "uploader/json_update_handler"
|
|
7
|
-
|
|
8
|
-
module FluidCLI
|
|
9
|
-
module Theme
|
|
10
|
-
class Syncer
|
|
11
|
-
class Uploader
|
|
12
|
-
extend Forwardable
|
|
13
|
-
|
|
14
|
-
include JsonDeleteHandler
|
|
15
|
-
include JsonUpdateHandler
|
|
16
|
-
|
|
17
|
-
attr_reader :syncer
|
|
18
|
-
|
|
19
|
-
def_delegators :syncer,
|
|
20
|
-
# helpers
|
|
21
|
-
:ctx,
|
|
22
|
-
:api_client,
|
|
23
|
-
:theme,
|
|
24
|
-
:overwrite_json?,
|
|
25
|
-
# enqueue
|
|
26
|
-
:enqueue_deletes,
|
|
27
|
-
:enqueue_get,
|
|
28
|
-
:enqueue_union_merges,
|
|
29
|
-
:enqueue_updates,
|
|
30
|
-
# checksums
|
|
31
|
-
:checksums,
|
|
32
|
-
:update_checksums,
|
|
33
|
-
:fetch_checksums!,
|
|
34
|
-
:wait!
|
|
35
|
-
|
|
36
|
-
def initialize(syncer, delete, delay_low_priority_files, &update_progress_bar_block)
|
|
37
|
-
@syncer = syncer
|
|
38
|
-
@delete = delete
|
|
39
|
-
@delay_low_priority_files = delay_low_priority_files
|
|
40
|
-
@update_progress_bar_block = update_progress_bar_block
|
|
41
|
-
@progress_bar_mutex = Mutex.new
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def upload!
|
|
45
|
-
fetch_checksums!
|
|
46
|
-
delete_files!
|
|
47
|
-
async_upload!
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def delete_files!
|
|
51
|
-
return unless delete?
|
|
52
|
-
|
|
53
|
-
files_present_remotely = checksums.keys
|
|
54
|
-
files_present_locally = theme.theme_files.map(&:relative_path)
|
|
55
|
-
|
|
56
|
-
files_to_delete = (files_present_remotely - files_present_locally)
|
|
57
|
-
.map { |file| theme[file] }
|
|
58
|
-
|
|
59
|
-
enqueue_deletes(files_to_delete)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
private
|
|
63
|
-
|
|
64
|
-
def async_upload!
|
|
65
|
-
enqueue_updates(files)
|
|
66
|
-
wait!(&@update_progress_bar_block)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def delete?
|
|
70
|
-
@delete
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def delay_low_priority_files?
|
|
74
|
-
@delay_low_priority_files
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Files
|
|
78
|
-
|
|
79
|
-
def files
|
|
80
|
-
@files ||= begin
|
|
81
|
-
theme.theme_files.select { |file| uploadable?(file) }
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def uploadable?(file)
|
|
86
|
-
return false unless file.exist?
|
|
87
|
-
|
|
88
|
-
checksums.file_has_changed?(file)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# Handler errors
|
|
92
|
-
|
|
93
|
-
def report(file, error)
|
|
94
|
-
file_path = file.relative_path
|
|
95
|
-
error_message = syncer
|
|
96
|
-
.parse_api_errors(file, error)
|
|
97
|
-
.map { |msg| "#{file_path}: #{msg}" }
|
|
98
|
-
.join("\n")
|
|
99
|
-
|
|
100
|
-
syncer.report_file_error(file, error_message)
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "thread"
|
|
4
|
-
require "json"
|
|
5
|
-
require "base64"
|
|
6
|
-
require "forwardable"
|
|
7
|
-
|
|
8
|
-
require_relative "syncer/checksums"
|
|
9
|
-
require_relative "syncer/downloader"
|
|
10
|
-
require_relative "syncer/error_reporter"
|
|
11
|
-
require_relative "syncer/merger"
|
|
12
|
-
require_relative "syncer/operation"
|
|
13
|
-
require_relative "syncer/standard_reporter"
|
|
14
|
-
require_relative "syncer/unsupported_script_warning"
|
|
15
|
-
require "fluid_cli/theme/syncer/uploader"
|
|
16
|
-
|
|
17
|
-
module FluidCLI
|
|
18
|
-
module Theme
|
|
19
|
-
class Syncer
|
|
20
|
-
extend Forwardable
|
|
21
|
-
|
|
22
|
-
QUEUEABLE_METHODS = [
|
|
23
|
-
:get, # - Updates the local file with the remote file content
|
|
24
|
-
:update, # - Updates the remote file with the local file content
|
|
25
|
-
:delete, # - Deletes the remote file
|
|
26
|
-
:union_merge, # - Union merges the local file content with the remote file content,
|
|
27
|
-
:get_asset, # - Downloads a binary asset from a given URL
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
attr_reader :ctx, :theme, :checksums, :error_checksums, :api_client, :pending, :standard_reporter
|
|
31
|
-
|
|
32
|
-
def_delegators :@error_reporter, :has_any_error?
|
|
33
|
-
|
|
34
|
-
def initialize(ctx, theme:, overwrite_json: true, force: false)
|
|
35
|
-
@ctx = ctx
|
|
36
|
-
@theme = theme
|
|
37
|
-
@overwrite_json = overwrite_json
|
|
38
|
-
@force = force
|
|
39
|
-
@error_reporter = ErrorReporter.new(ctx)
|
|
40
|
-
@standard_reporter = StandardReporter.new(ctx)
|
|
41
|
-
@reporters = [@error_reporter, @standard_reporter]
|
|
42
|
-
|
|
43
|
-
# Queue of `Operation`s waiting to be picked up from a thread for processing.
|
|
44
|
-
@queue = Queue.new
|
|
45
|
-
|
|
46
|
-
# `Operation`s will be removed from this Array completed.
|
|
47
|
-
@pending = []
|
|
48
|
-
|
|
49
|
-
# Thread making the API requests.
|
|
50
|
-
@threads = []
|
|
51
|
-
|
|
52
|
-
# Latest theme assets checksums. Updated on each upload.
|
|
53
|
-
@checksums = Checksums.new(theme)
|
|
54
|
-
|
|
55
|
-
# Checksums of assets with errors.
|
|
56
|
-
@error_checksums = []
|
|
57
|
-
|
|
58
|
-
# Initialize `api_client` on main thread
|
|
59
|
-
@api_client = FluidCLI::API.new(ctx)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def lock_io!
|
|
63
|
-
@reporters.each(&:disable!)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def unlock_io!
|
|
67
|
-
@reporters.each(&:enable!)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def enqueue_updates(files)
|
|
71
|
-
files.each { |file| enqueue(:update, file) }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def enqueue_get(files)
|
|
75
|
-
files.each { |file| enqueue(:get, file) }
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def enqueue_deletes(files)
|
|
79
|
-
files.each { |file| enqueue(:delete, file) }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def enqueue_union_merges(files)
|
|
83
|
-
files.each { |file| enqueue(:union_merge, file) }
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def size
|
|
87
|
-
@pending.size
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def empty?
|
|
91
|
-
@pending.empty?
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def pending_updates
|
|
95
|
-
@pending.select { |op| op.method == :update }.map(&:file)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def remote_file?(file)
|
|
99
|
-
checksums.has?(file)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def broken_file?(file)
|
|
103
|
-
error_checksums.include?(checksums[file.relative_path])
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def wait!
|
|
107
|
-
raise ThreadError, "No syncer threads" if @threads.empty?
|
|
108
|
-
|
|
109
|
-
total = size
|
|
110
|
-
last_size = size
|
|
111
|
-
until empty? || @queue.closed?
|
|
112
|
-
if block_given? && last_size != size
|
|
113
|
-
yield size, total
|
|
114
|
-
last_size = size
|
|
115
|
-
end
|
|
116
|
-
Thread.pass
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def fetch_checksums!
|
|
121
|
-
_status, response = api_client.get(
|
|
122
|
-
path: "application_themes/#{theme.id}/resources"
|
|
123
|
-
)
|
|
124
|
-
update_checksums(response["application_theme_resources"])
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def get_theme_resources!
|
|
129
|
-
_status, response = api_client.get(
|
|
130
|
-
path: "application_themes/#{theme.id}/resources"
|
|
131
|
-
)
|
|
132
|
-
update_checksums(response["application_theme_resources"])
|
|
133
|
-
|
|
134
|
-
response["application_theme_resources"].each do |resource|
|
|
135
|
-
file = theme[resource["key"]]
|
|
136
|
-
next unless file
|
|
137
|
-
|
|
138
|
-
if resource["resource_type"] == "FileResource" && !file.text?
|
|
139
|
-
enqueue(:get_asset, file, { url: resource["url"] })
|
|
140
|
-
else
|
|
141
|
-
file.write(resource["content"])
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def shutdown
|
|
147
|
-
@queue.close unless @queue.closed?
|
|
148
|
-
ensure
|
|
149
|
-
@threads.each { |thread| thread.join if thread.alive? }
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def start_threads(count = 2)
|
|
153
|
-
count.times do
|
|
154
|
-
@threads << Thread.new do
|
|
155
|
-
loop do
|
|
156
|
-
operation = @queue.pop
|
|
157
|
-
break if operation.nil? # shutdown was called
|
|
158
|
-
|
|
159
|
-
perform(operation)
|
|
160
|
-
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
161
|
-
error_suffix = ": #{e}"
|
|
162
|
-
error_suffix += + "\n\t#{e.backtrace.join("\n\t")}" if @ctx.debug?
|
|
163
|
-
report_error(operation, error_suffix)
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def upload_theme!(delay_low_priority_files: false, delete: true, &block)
|
|
170
|
-
uploader = Uploader.new(self, delete, delay_low_priority_files, &block)
|
|
171
|
-
uploader.upload!
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def download_theme!(delete: true, &block)
|
|
175
|
-
downloader = Downloader.new(self, delete, &block)
|
|
176
|
-
downloader.download!
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def enqueueable?(operation)
|
|
180
|
-
file = operation.file
|
|
181
|
-
method = operation.method
|
|
182
|
-
|
|
183
|
-
# Already enqueued or ignored
|
|
184
|
-
return false if @pending.include?(operation)
|
|
185
|
-
if [:update, :get].include?(method) && file.exist?
|
|
186
|
-
# File is fixed (and it has been never updated)
|
|
187
|
-
if !!@error_checksums.delete(file.checksum)
|
|
188
|
-
@standard_reporter.report(operation.as_fix_message)
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
return checksums.file_has_changed?(file)
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
true
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def handle_operation_error(operation, error)
|
|
198
|
-
error_suffix = ":\n " + parse_api_errors(operation.file, error).join("\n ")
|
|
199
|
-
report_error(operation, error_suffix)
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
def overwrite_json?
|
|
203
|
-
theme_created_at_runtime? || @overwrite_json
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def update_checksums(api_response)
|
|
207
|
-
api_response.each do |asset|
|
|
208
|
-
next unless asset["key"]
|
|
209
|
-
|
|
210
|
-
checksums[asset["key"]] = asset["checksum"]
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
checksums.reject_duplicated_checksums!
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
def report_file_error(file, error_message = "")
|
|
217
|
-
path = file.relative_path
|
|
218
|
-
|
|
219
|
-
@error_checksums << checksums[path]
|
|
220
|
-
@error_reporter.report(error_message)
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def parse_api_errors(file, exception)
|
|
224
|
-
parsed_body = {}
|
|
225
|
-
|
|
226
|
-
if exception.respond_to?(:response)
|
|
227
|
-
response = exception.response
|
|
228
|
-
|
|
229
|
-
parsed_body = if response&.is_a?(Hash)
|
|
230
|
-
response&.[](:body)
|
|
231
|
-
else
|
|
232
|
-
JSON.parse(response&.body)
|
|
233
|
-
end
|
|
234
|
-
errors = parsed_body.dig("errors") # either nil or another type
|
|
235
|
-
errors = errors.dig("asset") if errors&.is_a?(Hash)
|
|
236
|
-
|
|
237
|
-
["#{parsed_body['error_message']}\n#{errors}"]
|
|
238
|
-
elsif exception.respond_to?(:message)
|
|
239
|
-
[exception.message]
|
|
240
|
-
else
|
|
241
|
-
["An unknown error occurred while syncing the asset #{file}"]
|
|
242
|
-
end
|
|
243
|
-
rescue JSON::ParserError
|
|
244
|
-
[exception.message]
|
|
245
|
-
rescue StandardError => e
|
|
246
|
-
cause = "(cause: #{e.message})"
|
|
247
|
-
backtrace = e.backtrace.join("\n")
|
|
248
|
-
["The asset #{file} could not be synced #{cause} #{backtrace}"]
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
private
|
|
252
|
-
|
|
253
|
-
def download_and_write_binary(url, file)
|
|
254
|
-
uri = URI.parse(url)
|
|
255
|
-
response = HttpRequest.get(uri, nil, { "Content-Type" => "application/octet-stream" })
|
|
256
|
-
|
|
257
|
-
case response.code.to_i
|
|
258
|
-
when 200..399
|
|
259
|
-
file.write(response.body)
|
|
260
|
-
else
|
|
261
|
-
raise "Failed to download binary asset from #{url}: #{response.code} #{response.body}"
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
def report_error(operation, error_suffix = "")
|
|
266
|
-
file = operation.file
|
|
267
|
-
error_message = "#{operation.as_error_message}#{error_suffix}"
|
|
268
|
-
|
|
269
|
-
report_file_error(file, error_message)
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
def enqueue(method, file, options = {})
|
|
273
|
-
raise ArgumentError, "file required" unless file
|
|
274
|
-
raise ArgumentError, "method '#{method}' cannot be queued" unless QUEUEABLE_METHODS.include?(method)
|
|
275
|
-
|
|
276
|
-
operation = Operation.new(@ctx, method, @theme[file], options)
|
|
277
|
-
|
|
278
|
-
return unless enqueueable?(operation)
|
|
279
|
-
|
|
280
|
-
@pending << operation
|
|
281
|
-
@queue << operation unless @queue.closed?
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
def report_performed_operation(operation)
|
|
285
|
-
file = operation.file
|
|
286
|
-
|
|
287
|
-
if file.warnings.any?
|
|
288
|
-
warning_message =
|
|
289
|
-
operation.as_synced_message(color: :yellow) +
|
|
290
|
-
UnsupportedScriptWarning.new(@ctx, file).to_s
|
|
291
|
-
|
|
292
|
-
return @error_reporter.report(warning_message)
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
@standard_reporter.report(operation.as_synced_message)
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
def perform(operation)
|
|
299
|
-
return if @queue.closed?
|
|
300
|
-
|
|
301
|
-
@ctx.debug(operation.to_s)
|
|
302
|
-
|
|
303
|
-
response = send(operation.method, operation.file, operation.options)
|
|
304
|
-
|
|
305
|
-
report_performed_operation(operation)
|
|
306
|
-
rescue StandardError => error
|
|
307
|
-
handle_operation_error(operation, error)
|
|
308
|
-
ensure
|
|
309
|
-
@pending.delete(operation)
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
def update(file, _options = {})
|
|
313
|
-
application_theme_resource = { key: file.relative_path }
|
|
314
|
-
path = "application_themes/#{@theme.id}/resources"
|
|
315
|
-
|
|
316
|
-
if file.text?
|
|
317
|
-
if file.liquid? && !@force
|
|
318
|
-
file.validate_schema_and_raise
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
application_theme_resource[:content] = file.read
|
|
322
|
-
_status, body, response = api_client.put(
|
|
323
|
-
path: path,
|
|
324
|
-
body: JSON.generate(application_theme_resource: application_theme_resource),
|
|
325
|
-
)
|
|
326
|
-
else
|
|
327
|
-
asset_path_response = create_dam_asset_with_placeholder(file)[1]
|
|
328
|
-
auth_response = api_client.post(path: "dam/assets/imagekit_auth", body: JSON.generate({}))[1]
|
|
329
|
-
imagekit_folder = convert_canonical_path_to_imagekit_folder(asset_path_response.dig("asset", "canonical_path"))
|
|
330
|
-
imagekit_response = upload_to_imagekit(file, imagekit_folder, auth_response)[1]
|
|
331
|
-
backfill_response = backfill_dam_asset_from_imagekit(file, imagekit_response, asset_path_response)[1]
|
|
332
|
-
|
|
333
|
-
application_theme_resource[:dam_asset] = {
|
|
334
|
-
dam_asset_code: backfill_response.dig("asset", "code"),
|
|
335
|
-
content_type: file.mime_type.name,
|
|
336
|
-
content_size: imagekit_response.dig("size"),
|
|
337
|
-
filename: file.name,
|
|
338
|
-
handle: backfill_response.dig("asset", "code"),
|
|
339
|
-
url: backfill_response.dig("asset", "default_variant_url"),
|
|
340
|
-
preview_image_url: imagekit_response.dig("thumbnailUrl")
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
_status, body, response = api_client.put(
|
|
344
|
-
path: path,
|
|
345
|
-
body: JSON.generate(application_theme_resource: application_theme_resource)
|
|
346
|
-
)
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
update_checksums([body["application_theme_resource"]])
|
|
350
|
-
|
|
351
|
-
response
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
def create_dam_asset_with_placeholder(file)
|
|
355
|
-
api_client.post(path: "dam/assets", body: JSON.generate({
|
|
356
|
-
placeholder_asset: {
|
|
357
|
-
description: "Uploaded via FilePicker: #{file.name}",
|
|
358
|
-
mime_type: file.mime_type.name,
|
|
359
|
-
name: file.name
|
|
360
|
-
}
|
|
361
|
-
}))
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
def convert_canonical_path_to_imagekit_folder(canonical_path)
|
|
365
|
-
parts = canonical_path.split(".")
|
|
366
|
-
if parts.length < 2
|
|
367
|
-
throw new Error(`Invalid canonical path format: ${canonical_path}`)
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
company_id = parts[0]
|
|
371
|
-
category = parts[1]
|
|
372
|
-
asset_code = parts[2]
|
|
373
|
-
|
|
374
|
-
# Map DAM categories to ImageKit folder structure
|
|
375
|
-
folder_mapping = {
|
|
376
|
-
images: "images",
|
|
377
|
-
videos: "videos",
|
|
378
|
-
audio: "audio",
|
|
379
|
-
documents: "documents",
|
|
380
|
-
files: "files", # fallback
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
folder_type = category ? folder_mapping[category] || "files" : "files"
|
|
384
|
-
|
|
385
|
-
"#{company_id}/#{folder_type}/#{asset_code}"
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
def upload_to_imagekit(file, imagekit_folder, auth_response)
|
|
389
|
-
::File.open(file.path) do |f|
|
|
390
|
-
_status, body, response = api_client.multipart_post(
|
|
391
|
-
path: "v1/files/upload",
|
|
392
|
-
host: "upload.imagekit.io",
|
|
393
|
-
body: {
|
|
394
|
-
file: UploadIO.new(f, file.mime_type.name, file.name),
|
|
395
|
-
token: auth_response.dig("token"),
|
|
396
|
-
signature: auth_response.dig("signature"),
|
|
397
|
-
expire: auth_response.dig("expire"),
|
|
398
|
-
folder: imagekit_folder,
|
|
399
|
-
fileName: file.name,
|
|
400
|
-
publicKey: 'public_j7s4Ih9ETh/OCp41mVQH7tlXBdU='
|
|
401
|
-
}
|
|
402
|
-
)
|
|
403
|
-
end
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
def backfill_dam_asset_from_imagekit(file, imagekit_response, asset_path_response)
|
|
407
|
-
payload = {
|
|
408
|
-
asset: {
|
|
409
|
-
id: asset_path_response.dig("asset", "id"),
|
|
410
|
-
imagekit_file_id: imagekit_response.dig("fileId"),
|
|
411
|
-
imagekit_url: imagekit_response.dig("url"),
|
|
412
|
-
mime_type: file.mime_type.name,
|
|
413
|
-
name: file.name,
|
|
414
|
-
file_size: imagekit_response.dig("size"),
|
|
415
|
-
expected_path: asset_path_response.dig("asset", "canonical_path")
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
payload[:asset][:height] = imagekit_response.dig("height") if imagekit_response.dig("height")
|
|
420
|
-
payload[:asset][:width] = imagekit_response.dig("width") if imagekit_response.dig("width")
|
|
421
|
-
api_client.post(path: "dam/assets/backfill_imagekit", body: JSON.generate(payload))
|
|
422
|
-
end
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
def get(file, _options = {})
|
|
426
|
-
_status, body, response = api_client.get(
|
|
427
|
-
path: "themes/#{@theme.id}/assets.json",
|
|
428
|
-
query: URI.encode_www_form("asset[key]" => file.relative_path),
|
|
429
|
-
)
|
|
430
|
-
|
|
431
|
-
update_checksums(body)
|
|
432
|
-
|
|
433
|
-
attachment = body.dig("asset", "attachment")
|
|
434
|
-
if attachment
|
|
435
|
-
file.write(Base64.decode64(attachment))
|
|
436
|
-
else
|
|
437
|
-
file.write(body.dig("asset", "value"))
|
|
438
|
-
end
|
|
439
|
-
|
|
440
|
-
response
|
|
441
|
-
end
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
def get_asset(file, options = {})
|
|
445
|
-
url = options[:url]
|
|
446
|
-
uri = URI.parse(url)
|
|
447
|
-
response = HttpRequest.get(uri, nil, { "Content-Type" => "application/octet-stream" })
|
|
448
|
-
|
|
449
|
-
case response.code.to_i
|
|
450
|
-
when 200..399
|
|
451
|
-
file.write(response.body)
|
|
452
|
-
else
|
|
453
|
-
raise "Failed to download binary asset from #{url}: #{response.code} #{response.body}"
|
|
454
|
-
end
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
def delete(file, _options = {})
|
|
458
|
-
_status, _body, response = api_client.delete(
|
|
459
|
-
path: "application_themes/#{@theme.id}/resources",
|
|
460
|
-
body: JSON.generate(:application_theme_resource => {
|
|
461
|
-
key: file.relative_path,
|
|
462
|
-
}),
|
|
463
|
-
)
|
|
464
|
-
|
|
465
|
-
checksums.delete(file) if checksums.has?(file)
|
|
466
|
-
|
|
467
|
-
response
|
|
468
|
-
end
|
|
469
|
-
|
|
470
|
-
def union_merge(file, _options = {})
|
|
471
|
-
_status, body, response = api_client.get(
|
|
472
|
-
path: "themes/#{@theme.id}/assets.json",
|
|
473
|
-
query: URI.encode_www_form("asset[key]" => file.relative_path),
|
|
474
|
-
)
|
|
475
|
-
|
|
476
|
-
return response unless file.text?
|
|
477
|
-
|
|
478
|
-
remote_content = body.dig("asset", "value")
|
|
479
|
-
|
|
480
|
-
return response if remote_content.nil?
|
|
481
|
-
|
|
482
|
-
content = Merger.union_merge(file, remote_content)
|
|
483
|
-
|
|
484
|
-
file.write(content)
|
|
485
|
-
|
|
486
|
-
enqueue(:update, file)
|
|
487
|
-
|
|
488
|
-
response
|
|
489
|
-
end
|
|
490
|
-
|
|
491
|
-
def theme_created_at_runtime?
|
|
492
|
-
@theme.created_at_runtime?
|
|
493
|
-
end
|
|
494
|
-
|
|
495
|
-
def wait(duration)
|
|
496
|
-
sleep(duration)
|
|
497
|
-
end
|
|
498
|
-
end
|
|
499
|
-
end
|
|
500
|
-
end
|