-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'fileutils' | ||
require 'json' | ||
require "debug" | ||
|
||
def run(input_path, base, merge_json_path, output, processed_path) | ||
FileUtils.mkdir_p(processed_path) | ||
FileUtils.mkdir_p(input_path) | ||
|
||
puts "Consuming files in #{input_path} path" | ||
|
||
files = Dir.open(input_path) do |input_dir| | ||
FileUtils.touch File.join(Dir.pwd, input_dir, '.gitkeep') | ||
|
||
Dir.glob(File.join(Dir.pwd, input_dir, '*.json')) | ||
end | ||
|
||
puts "Merging files to #{output}, using #{base} as base" | ||
|
||
base = JSON.load_file!(base) | ||
base_dest = base.dig(*merge_json_path.split(".")) | ||
|
||
files.each do |input_path| | ||
json = JSON.load_file!(input_path) | ||
|
||
base_dest.append(json) | ||
end | ||
|
||
output_json = JSON.pretty_generate(base) | ||
|
||
puts "Writing to #{output}:" | ||
puts output_json | ||
puts '<EOF>' | ||
|
||
File.open(output, 'w') do |f| | ||
f.write(output_json) | ||
end | ||
|
||
# Move files to processed_path folder | ||
FileUtils.mv files, processed_path, verbose: true | ||
end | ||
|
||
run(*ARGV) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.