Method: ShopifyCLI::Theme::File#write

Defined in:
lib/shopify_cli/theme/file.rb

#write(content) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/shopify_cli/theme/file.rb', line 27

def write(content)
  path.parent.mkpath unless path.parent.directory?
  if text?
    path.write(content, universal_newline: true)
  else
    path.write(content, 0, mode: "wb")
  end
rescue Encoding::UndefinedConversionError
  ##
  # The CLI tries to write the file and normalize EOL characters to avoid
  # errors on Windows when files are shared across different operational systems.
  #
  # The CLI fallbacks any error during the conversion by writing the file
  # in binary mode when the normalization fails (e.g., ASCII files), so no data is lost.
  #
  path.write(content, 0, mode: "wb")
end