Icarus-Mod-Tools 1.9.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fba522a3f41d8d1c77402e95f59684594bb7be97a8227966e4b647777152f05
4
- data.tar.gz: 933ee795c5f13f964e1a866c0ce06549912c6e99c06c78fd687e5c25886bf148
3
+ metadata.gz: bc9f1796a92ebce3c0cdac2b87012e3c411f2f04e2308dc725872daf08846416
4
+ data.tar.gz: 707de57a940c21f20f2c47853f8083a121fceed70b6a5d8bbc358038c608a805
5
5
  SHA512:
6
- metadata.gz: 0cd6a08a77be86801059b2b63a81fb662583ca404391afa2fd9544dbda8549e0652ce4c7db9a5ff64edb04afd07b50b742e1473861639ea190eddd22dda70f03
7
- data.tar.gz: 1f28bff449d31ea47fa9166586dd10b996c466ed898ff53449a2cfd84fff98a5454418214fa479fa9976c0700ca88b12724c8b1f166b059093658d32862ee938
6
+ metadata.gz: 11179ce087f3c5b1d6dc8d6a76758410513bba8d53a1a02a2b0fd44e3b3ab58c5a0f14c81667edfaffbdf129ea917bcb256b71a75a0b8bc2220ef3863ecfcb98
7
+ data.tar.gz: 45d746e5bd59b6342ec9cec813d72e520fbbc8d1cc55d41e8c725b745c377f3aaba135b56b746281a80f5a1588e66a9426a80026cf423c49a80c85f029f1d586
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Icarus-Mod-Tools (1.9.0)
4
+ Icarus-Mod-Tools (2.0.1)
5
5
  google-cloud-firestore (~> 2.7)
6
6
  octokit (~> 6.0)
7
7
  paint (~> 2.3)
@@ -38,7 +38,7 @@ GEM
38
38
  google-cloud-env (1.6.0)
39
39
  faraday (>= 0.17.3, < 3.0)
40
40
  google-cloud-errors (1.3.0)
41
- google-cloud-firestore (2.9.0)
41
+ google-cloud-firestore (2.9.1)
42
42
  concurrent-ruby (~> 1.0)
43
43
  google-cloud-core (~> 1.5)
44
44
  google-cloud-firestore-v1 (~> 0.0)
@@ -86,7 +86,7 @@ GEM
86
86
  guard-compat (~> 1.1)
87
87
  rspec (>= 2.99.0, < 4.0)
88
88
  json (2.6.3)
89
- jwt (2.6.0)
89
+ jwt (2.7.0)
90
90
  listen (3.8.0)
91
91
  rb-fsevent (~> 0.10, >= 0.10.3)
92
92
  rb-inotify (~> 0.9, >= 0.9.10)
@@ -122,7 +122,7 @@ GEM
122
122
  rspec-core (~> 3.12.0)
123
123
  rspec-expectations (~> 3.12.0)
124
124
  rspec-mocks (~> 3.12.0)
125
- rspec-core (3.12.0)
125
+ rspec-core (3.12.1)
126
126
  rspec-support (~> 3.12.0)
127
127
  rspec-expectations (3.12.2)
128
128
  diff-lcs (>= 1.2.0, < 2.0)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "firestore"
4
+ require "tools/modinfo"
4
5
 
5
6
  module Icarus
6
7
  module Mod
@@ -10,7 +11,7 @@ module Icarus
10
11
  desc "modinfo", "Adds an entry to 'meta/modinfo/list'"
11
12
  def modinfo(item)
12
13
  firestore = Firestore.new
13
- payload = [firestore.list(:modinfo), item].flatten.compact
14
+ payload = [firestore.modinfo, item].flatten.compact
14
15
 
15
16
  puts firestore.update(:modinfo, payload, merge: true) ? "Success" : "Failure"
16
17
  end
@@ -18,7 +19,7 @@ module Icarus
18
19
  desc "toolinfo", "Adds an entry to 'meta/toolinfo/list'"
19
20
  def toolinfo(item)
20
21
  firestore = Firestore.new
21
- payload = [firestore.list(:toolinfo), item].flatten.compact
22
+ payload = [firestore.toolinfo, item].flatten.compact
22
23
 
23
24
  puts firestore.update(:toolinfo, payload, merge: true) ? "Success" : "Failure"
24
25
  end
@@ -26,10 +27,33 @@ module Icarus
26
27
  desc "repos", "Adds an entry to 'meta/repos/list'"
27
28
  def repos(item)
28
29
  firestore = Firestore.new
29
- payload = [firestore.list(:repositories), item].flatten.compact
30
+ payload = [firestore.repositories, item].flatten.compact
30
31
 
31
32
  puts firestore.update(:repositories, payload, merge: true) ? "Success" : "Failure"
32
33
  end
34
+
35
+ desc "mod", "Adds an entry to 'mods'"
36
+ method_option :modinfo, type: :string, required: true, default: "modinfo.json", desc: "Path to the modinfo.json file"
37
+ def mod
38
+ firestore = Firestore.new
39
+ data = options[:modinfo]
40
+
41
+ if data.nil? || !File.exist?(data)
42
+ warn "Invalid data file: #{data}"
43
+ exit 1
44
+ end
45
+
46
+ JSON.parse(File.read(data), symbolize_names: true)[:mods].each do |mod|
47
+ modinfo = Icarus::Mod::Tools::Modinfo.new(mod)
48
+
49
+ unless modinfo.valid?
50
+ warn "Invalid modinfo: #{modinfo.errors}"
51
+ exit 1
52
+ end
53
+
54
+ puts firestore.update(:mod, modinfo, merge: true) ? "Success" : "Failure"
55
+ end
56
+ end
33
57
  end
34
58
  end
35
59
  end
@@ -10,21 +10,21 @@ module Icarus
10
10
  class List < SubcommandBase
11
11
  desc "modinfo", "Displays data from 'meta/modinfo/list'"
12
12
  def modinfo
13
- modinfo_array = Firestore.new.list(:modinfo)
13
+ modinfo_array = Firestore.new.send(:modinfo)
14
14
  puts modinfo_array
15
15
  puts "Total: #{modinfo_array.count}" if verbose > 1
16
16
  end
17
17
 
18
18
  desc "toolinfo", "Displays data from 'meta/toolinfo/list'"
19
19
  def toolinfo
20
- toolinfo_array = Firestore.new.list(:toolinfo)
20
+ toolinfo_array = Firestore.new.send(:toolinfo)
21
21
  puts toolinfo_array
22
22
  puts "Total: #{toolinfo_array.count}" if verbose > 1
23
23
  end
24
24
 
25
25
  desc "repos", "Displays data from 'meta/repos/list'"
26
26
  def repos
27
- repos = Firestore.new.list(:repositories)
27
+ repos = Firestore.new.send(:repositories)
28
28
  puts repos
29
29
  puts "Total: #{repos.count}" if verbose > 1
30
30
  end
@@ -64,7 +64,7 @@ module Icarus
64
64
  puts "Sorted by #{sort_field}" if sort_field && verbose > 2
65
65
  puts "Filtered by #{filter_field} = #{filter_value}" if filter_field && verbose > 2
66
66
 
67
- items = Firestore.new.list(type)
67
+ items = Firestore.new.send(type)
68
68
 
69
69
  # Filter by field
70
70
  items.select! { |item| item.send(filter_field).downcase =~ /#{filter_value&.downcase}/ } if filter_field
@@ -85,6 +85,8 @@ module Icarus
85
85
  def sync_list(type)
86
86
  sync = (type == :mods ? Icarus::Mod::Tools::Sync::Mods : Icarus::Mod::Tools::Sync::Tools).new(client: firestore)
87
87
 
88
+ puts "Syncing #{type} to #{Config.firebase.collections.send(type)}" if verbose > 1
89
+
88
90
  puts "Retrieving Info Data..." if verbose?
89
91
  info_array = sync.info_array
90
92
 
@@ -13,10 +13,15 @@ module Icarus
13
13
  def initialize
14
14
  @client = Google::Cloud::Firestore.new(credentials: Config.firebase.credentials.to_h)
15
15
  @collections = Config.firebase.collections
16
+ @repositories = repositories
17
+ @modinfo = modinfo
18
+ @toolinfo = toolinfo
19
+ @mods = mods
20
+ @tools = tools
16
21
  end
17
22
 
18
- def repos
19
- @repos ||= list(:repositories)
23
+ def repositories
24
+ @repositories ||= list(:repositories)
20
25
  end
21
26
 
22
27
  def modinfo
@@ -36,35 +41,7 @@ module Icarus
36
41
  end
37
42
 
38
43
  def find_by_type(type:, name:, author:)
39
- list(type).find { |obj| obj.name == name && obj.author == author }
40
- end
41
-
42
- def get_list(type)
43
- raise "Invalid type: #{type} - unknown collection" unless collections.respond_to?(type)
44
-
45
- @client.doc(collections.send(type)).get[:list]
46
- end
47
-
48
- def list(type)
49
- case type.to_sym
50
- when :modinfo, :toolinfo, :repositories
51
- get_list(type)
52
- when :mods, :tools
53
- @client.col(collections.send(type)).get.map do |doc|
54
- klass = type == :mods ? Icarus::Mod::Tools::Modinfo : Icarus::Mod::Tools::Toolinfo
55
- klass.new(doc.data, id: doc.document_id, created: doc.create_time, updated: doc.update_time)
56
- end
57
- else
58
- raise "Invalid type: #{type}"
59
- end
60
- end
61
-
62
- def update_or_create(type, payload, merge:)
63
- doc_id = payload.id || find_by_type(type:, name: payload.name, author: payload.author)&.id
64
-
65
- return @client.doc("#{collections.send(type)}/#{doc_id}").set(payload.to_h, merge:) if doc_id
66
-
67
- @client.col(collections.send(type)).add(payload.to_h)
44
+ instance_variable_get("@#{type}").find { |obj| obj.name == name && obj.author == author }
68
45
  end
69
46
 
70
47
  def update(type, payload, merge: false)
@@ -98,6 +75,28 @@ module Icarus
98
75
 
99
76
  private
100
77
 
78
+ def list(type)
79
+ case type.to_sym
80
+ when :modinfo, :toolinfo, :repositories
81
+ @client.doc(collections.send(type)).get[:list]
82
+ when :mods, :tools
83
+ @client.col(collections.send(type)).get.map do |doc|
84
+ klass = type == :mods ? Icarus::Mod::Tools::Modinfo : Icarus::Mod::Tools::Toolinfo
85
+ klass.new(doc.data, id: doc.document_id, created: doc.create_time, updated: doc.update_time)
86
+ end
87
+ else
88
+ raise "Invalid type: #{type}"
89
+ end
90
+ end
91
+
92
+ def update_or_create(type, payload, merge:)
93
+ doc_id = payload.id || find_by_type(type:, name: payload.name, author: payload.author)&.id
94
+
95
+ return @client.doc("#{collections.send(type)}/#{doc_id}").set(payload.to_h, merge:) if doc_id
96
+
97
+ @client.col(collections.send(type)).add(payload.to_h)
98
+ end
99
+
101
100
  def pluralize(type)
102
101
  type.to_s.end_with?("s") ? type.to_s : "#{type}s"
103
102
  end
@@ -7,7 +7,7 @@ module Icarus
7
7
  class Baseinfo
8
8
  attr_reader :data, :id, :created_at, :updated_at
9
9
 
10
- HASHKEYS = %i[name author version compatibility description fileType fileURL imageURL readmeURL].freeze
10
+ HASHKEYS = %i[name author version compatibility description files imageURL readmeURL].freeze
11
11
 
12
12
  def initialize(data, id: nil, created: nil, updated: nil)
13
13
  @id = id
@@ -52,14 +52,14 @@ module Icarus
52
52
  end
53
53
 
54
54
  def valid?
55
- @warnings << "Version should be a version string" unless validate_version(version)
55
+ validate_version
56
+ validate_files if @data.key?(:files)
57
+ validate_filetype(fileType) if @data.key?(:fileType)
56
58
 
57
59
  %w[name author description].each do |key|
58
60
  @errors << "#{key.capitalize} cannot be blank" unless validate_string(@data[key.to_sym])
59
61
  end
60
62
 
61
- @errors << "Invalid fileType: #{fileType || "blank"}" unless validate_filetype(fileType)
62
-
63
63
  %w[fileURL imageURL readmeURL].each do |key|
64
64
  @errors << "Invalid URL #{key.capitalize}: #{@data[key.to_sym] || "blank"}" unless validate_url(@data[key.to_sym])
65
65
  end
@@ -67,12 +67,20 @@ module Icarus
67
67
  !errors?
68
68
  end
69
69
 
70
+ def file_types
71
+ files&.keys || []
72
+ end
73
+
74
+ def file_urls
75
+ files&.values || []
76
+ end
77
+
70
78
  def method_missing(method_name, *_args, &_block)
71
- @data[method_name.to_sym]&.strip
79
+ @data[method_name.to_sym] if @data.keys.include?(method_name.to_sym)
72
80
  end
73
81
 
74
82
  def respond_to_missing?(method_name, include_private = false)
75
- HASHKEYS.include?(method_name.to_sym) || super
83
+ @data.keys.include?(method_name.to_sym) || super
76
84
  end
77
85
 
78
86
  private
@@ -81,22 +89,32 @@ module Icarus
81
89
  /(zip|pak|exmodz?)/i
82
90
  end
83
91
 
92
+ def validate_string(string)
93
+ !(string.nil? || string.empty?)
94
+ end
95
+
84
96
  def validate_url(url)
85
97
  return true if url.nil? || url.empty?
86
98
 
87
99
  url =~ URI::DEFAULT_PARSER.make_regexp
88
100
  end
89
101
 
90
- def validate_filetype(filetype)
91
- filetype.match?(filetype_pattern)
102
+ def validate_files
103
+ @errors << "files cannot be blank" if @data.key?(:files) && @data[:files].keys.empty?
104
+
105
+ file_types.each { |file_type| validate_filetype(file_type) }
106
+
107
+ file_urls.each do |file_url|
108
+ @errors << "Invalid URL: #{file_url}" unless validate_url(file_url)
109
+ end
92
110
  end
93
111
 
94
- def validate_string(string)
95
- !(string.nil? || string.empty?)
112
+ def validate_filetype(file_type)
113
+ @errors << "Invalid fileType: #{file_type.upcase}" unless file_type&.match?(filetype_pattern)
96
114
  end
97
115
 
98
- def validate_version(version)
99
- version =~ /\d+\.\d+[.\d+]?/
116
+ def validate_version
117
+ @warnings << "Version should be a version string" unless version =~ /^\d+[.\d+]*/
100
118
  end
101
119
  end
102
120
  end
@@ -7,7 +7,25 @@ module Icarus
7
7
  module Tools
8
8
  # Sync methods
9
9
  class Modinfo < Baseinfo
10
- HASHKEYS = %i[name author version compatibility description long_description fileType fileURL imageURL readmeURL].freeze
10
+ HASHKEYS = %i[name author version compatibility description long_description files fileType fileURL imageURL readmeURL].freeze
11
+
12
+ def to_h
13
+ HASHKEYS.each_with_object({}) do |key, hash|
14
+ next if key == :files && @data[:files].nil?
15
+ next if %i[fileType fileURL].include?(key.to_sym) && !@data[:files].nil?
16
+ next if key == :long_description && @data[:long_description].nil?
17
+
18
+ hash[key] = @data[key]
19
+ end
20
+ end
21
+
22
+ def file_types
23
+ files&.keys || [@data[:fileType] || "pak"]
24
+ end
25
+
26
+ def file_urls
27
+ files&.values || [@data[:fileURL]].compact
28
+ end
11
29
 
12
30
  # rubocop:disable Naming/MethodName
13
31
  def fileType
@@ -19,7 +19,7 @@ module Icarus
19
19
  end
20
20
 
21
21
  def repositories
22
- @firestore.repos
22
+ @firestore.repositories
23
23
  end
24
24
 
25
25
  def update(modinfo_array)
@@ -19,7 +19,7 @@ module Icarus
19
19
  end
20
20
 
21
21
  def repositories
22
- @firestore.repos
22
+ @firestore.repositories
23
23
  end
24
24
 
25
25
  def update(toolinfo_array)
@@ -7,6 +7,8 @@ module Icarus
7
7
  module Tools
8
8
  # Sync methods
9
9
  class Toolinfo < Baseinfo
10
+ HASHKEYS = %i[name author version compatibility description fileType fileURL imageURL readmeURL].freeze
11
+
10
12
  # rubocop:disable Naming/MethodName
11
13
  def fileType
12
14
  @data[:fileType] || "zip"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Icarus
4
4
  module Mod
5
- VERSION = "1.9.0"
5
+ VERSION = "2.0.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Icarus-Mod-Tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donovan Young
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-28 00:00:00.000000000 Z
11
+ date: 2023-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-firestore