Skip to content

Commit

Permalink
Match old dist whitespace generation (#506)
Browse files Browse the repository at this point in the history
A few more tweaks to `dist` generation to precisely match the old behaviour.

* Ensure all files end with newlines
* Use an older version of the `json` gem to match whitespace behaviour for empty arrays
* Ensure we're using bundler gem versions in `bin/product_taxonomy`
  • Loading branch information
danielpgross authored Dec 16, 2024
2 parents 957fe66 + 35b8584 commit f000935
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions dev/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source "https://rubygems.org"
gem "thor", "~> 1.3"
gem "activesupport"
gem "activemodel"
gem "json", "~> 2.7.2"

group :development do
gem "rubocop-shopify", require: false
Expand Down
3 changes: 2 additions & 1 deletion dev/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GEM
drb (2.2.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.8.1)
json (2.7.6)
language_server-protocol (3.17.0.3)
logger (1.6.1)
minitest (5.25.1)
Expand Down Expand Up @@ -91,6 +91,7 @@ PLATFORMS
DEPENDENCIES
activemodel
activesupport
json (~> 2.7.2)
mocha
rubocop-shopify
thor (~> 1.3)
Expand Down
1 change: 1 addition & 0 deletions dev/bin/product_taxonomy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require_relative "../lib/product_taxonomy"

ProductTaxonomy::Cli.start(ARGV)
4 changes: 2 additions & 2 deletions dev/lib/product_taxonomy/commands/generate_dist_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def generate_txt_file(locale:, type:)
when "attribute_values" then Value.to_txt(version: @version, locale:)
end

File.write("#{OUTPUT_PATH}/#{locale}/#{type}.txt", txt_data)
File.write("#{OUTPUT_PATH}/#{locale}/#{type}.txt", txt_data + "\n")
end

def generate_json_file(locale:, type:)
Expand All @@ -68,7 +68,7 @@ def generate_json_file(locale:, type:)
Value.to_json(version: @version, locale:)
end

File.write("#{OUTPUT_PATH}/#{locale}/#{type}.json", JSON.pretty_generate(json_data))
File.write("#{OUTPUT_PATH}/#{locale}/#{type}.json", JSON.pretty_generate(json_data) + "\n")
end
end
end
6 changes: 3 additions & 3 deletions dev/lib/product_taxonomy/models/integration_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def load_from_source(integration_path:, current_shopify_version: nil)
def generate_all_mappings_file(mappings:, current_shopify_version:, output_path:)
File.write(
File.expand_path("all_mappings.json", integrations_output_path(output_path)),
JSON.pretty_generate(to_json(mappings:, current_shopify_version:)),
JSON.pretty_generate(to_json(mappings:, current_shopify_version:)) + "\n",
)
end

Expand Down Expand Up @@ -147,11 +147,11 @@ def generate_distribution(output_path:, direction:)
json = self.class.to_json(mappings: [to_json(direction:)], current_shopify_version: @current_shopify_version)
File.write(
File.expand_path("#{distribution_filename(direction:)}.json", output_dir),
JSON.pretty_generate(json),
JSON.pretty_generate(json) + "\n",
)
File.write(
File.expand_path("#{distribution_filename(direction:)}.txt", output_dir),
to_txt(direction:),
to_txt(direction:) + "\n",
)
end

Expand Down

0 comments on commit f000935

Please sign in to comment.