From 71c13bf8a315960c2c73afe98de433b7ae30987a Mon Sep 17 00:00:00 2001 From: hahwul Date: Mon, 15 Aug 2022 22:59:41 +0900 Subject: [PATCH] y --- scripts/migration.rb | 46 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/scripts/migration.rb b/scripts/migration.rb index fbc3b6a..d499d67 100644 --- a/scripts/migration.rb +++ b/scripts/migration.rb @@ -1,20 +1,42 @@ require 'json' +require 'yaml' + +def get_os install + lst = [] + if install['Linux'].length > 1 + lst.push 'linux' + end + if install['MacOS'].length > 1 + lst.push 'macos' + end + if install['Windows'].length > 1 + lst.push 'windows' + end + return lst +end file = File.read('./data.json') data_hash = JSON.parse(file) data_hash.each do | name, obj | - puts "filename: "+name+".yaml" - + filename = name.gsub(' ','_')+".yaml" # Make object - obj = {} - obj['name'] = name - obj['description'] = obj['Description'] - obj['url'] = '' # parse DATA - obj['category'] = 'tool' - obj['types'] = [] - obj['lang'] = [] # parse DATA - obj['tags'] = [] - - # Save file + new_obj = {} + new_obj['name'] = name + new_obj['description'] = obj['Description'] + new_obj['url'] = '' # parse DATA + new_obj['category'] = 'tool' + new_obj['types'] = [] + if obj['Install'] != nil + new_obj['os'] = get_os(obj['Install']) + end + new_obj['lang'] = [] # parse DATA + new_obj['tags'] = [] + + # Convert to YAML + yaml_data = YAML.dump(new_obj) + + # Save yaml file + puts filename + #File.write("./data/#{filename}", yaml_data) end \ No newline at end of file