mmi 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,83 @@
1
+ require 'fileutils'
2
+ require 'open-uri'
3
+
4
+ require 'mmi/modrinth_api'
5
+ require 'mmi/option_attributes'
6
+
7
+ module Mmi
8
+ module Source
9
+ class Modrinth
10
+ include Mmi::OptionAttributes
11
+
12
+ opt_accessor :name
13
+ opt_accessor :version
14
+ opt_accessor :version_file
15
+
16
+ opt_accessor :install_dir
17
+ opt_accessor :filename
18
+
19
+ def initialize(options)
20
+ @options = options
21
+
22
+ parse!
23
+ end
24
+
25
+ def parse!
26
+ if self.name
27
+ if self.version
28
+ if self.version_file
29
+ if self.install_dir
30
+ # Pass.
31
+ else
32
+ raise Mmi::MissingAttributeError, 'Missing "source.install_dir" from asset.'
33
+ end
34
+ else
35
+ raise Mmi::MissingAttributeError, 'Missing "source.version_file" from asset.'
36
+ end
37
+ else
38
+ raise Mmi::MissingAttributeError, 'Missing "source.version" from asset.'
39
+ end
40
+ else
41
+ raise Mmi::MissingAttributeError, 'Missing "source.name" from asset.'
42
+ end
43
+ end
44
+
45
+ def cached_mod_id
46
+ @cached_mod_id ||= Mmi::ModrinthApi.mod(self.name)['id']
47
+ end
48
+
49
+ def cached_mod_versions
50
+ @cached_mod_versions ||= Mmi::ModrinthApi.mod_versions(cached_mod_id)
51
+ end
52
+
53
+ def download_url
54
+ cached_mod_versions.select do |version|
55
+ version['name'] == self.version
56
+ end.first['files'].select do |files|
57
+ files['filename'] == self.version_file
58
+ end.first['url'].gsub(/ /, '%20')
59
+ end
60
+
61
+ def install(dir)
62
+ install_dir = File.expand_path(self.install_dir, dir)
63
+ filepath = File.join(install_dir, self.filename || self.version_file)
64
+
65
+ Mmi.info "Downloading #{download_url.inspect} into #{filepath.inspect}."
66
+
67
+ FileUtils.mkdir_p(install_dir)
68
+
69
+ begin
70
+ stream = URI.parse(download_url).open
71
+
72
+ IO.copy_stream(stream, filepath)
73
+ rescue OpenURI::HTTPError => e
74
+ Mmi.fail! "Error when requesting asset.\n#{e.inspect}"
75
+ end
76
+ end
77
+
78
+ def display_name
79
+ "https://modrinth.com/mod/#{name}"
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,59 @@
1
+ require 'fileutils'
2
+ require 'open-uri'
3
+
4
+ require 'mmi/option_attributes'
5
+
6
+ module Mmi
7
+ module Source
8
+ class Url
9
+ include Mmi::OptionAttributes
10
+
11
+ opt_accessor :url
12
+ opt_accessor :install_dir
13
+ opt_accessor :filename
14
+
15
+ def initialize(options)
16
+ @options = options
17
+
18
+ parse!
19
+ end
20
+
21
+ def parse!
22
+ if self.url
23
+ if self.install_dir
24
+ # Pass.
25
+ else
26
+ raise Mmi::MissingAttributeError, 'Missing "source.install_dir" from asset.'
27
+ end
28
+ else
29
+ raise Mmi::MissingAttributeError, 'Missing "source.name" from asset.'
30
+ end
31
+ end
32
+
33
+ def download_uri
34
+ @download_uri ||= URI.parse(url)
35
+ end
36
+
37
+ def install(dir)
38
+ install_dir = File.expand_path(self.install_dir, dir)
39
+ filepath = File.join(install_dir, self.filename || File.basename(download_uri.path))
40
+
41
+ Mmi.info "Downloading #{url.inspect} into #{filepath.inspect}."
42
+
43
+ FileUtils.mkdir_p(install_dir)
44
+
45
+ begin
46
+ stream = download_uri.open
47
+
48
+ IO.copy_stream(stream, filepath)
49
+ rescue OpenURI::HTTPError => e
50
+ Mmi.fail! "Error when requesting asset.\n#{e.inspect}"
51
+ end
52
+ end
53
+
54
+ def display_name
55
+ url
56
+ end
57
+ end
58
+ end
59
+ end
data/lib/mmi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mmi
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/mmi.rb CHANGED
@@ -1,8 +1,3 @@
1
- require 'open-uri'
2
- require 'fileutils'
3
- require 'digest'
4
- require 'github_api'
5
-
6
1
  require 'mmi/version'
7
2
  require 'mmi/mod_file_processor'
8
3
 
@@ -23,7 +18,7 @@ module Mmi
23
18
  class InvalidAttributeError < ValidationError; end
24
19
 
25
20
  def self.debug(text)
26
- if ENV['MMI_ENV']=='dev'
21
+ if ENV['MMI_ENV'] == 'dev'
27
22
  puts text
28
23
  end
29
24
  end
@@ -37,7 +32,7 @@ module Mmi
37
32
  end
38
33
 
39
34
  def self.fail!(text)
40
- STDERR.puts text
35
+ Kernel.warn text
41
36
  Kernel.exit 1
42
37
  end
43
38
  end
metadata CHANGED
@@ -1,57 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - expeehaa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-15 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: github_api
14
+ name: cli-ui
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.19'
19
+ version: 1.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.19'
26
+ version: 1.5.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: cli-ui
28
+ name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.0
33
+ version: '1.11'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.0
40
+ version: '1.11'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: octokit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.2'
47
+ version: '4.22'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.22'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.13'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '2.2'
68
+ version: '0.13'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +81,61 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '13.0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: pry
84
+ name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.13'
89
+ version: '3.10'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.13'
96
+ version: '3.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: warbler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.0'
83
139
  description:
84
140
  email:
85
141
  - expeehaa@outlook.com
@@ -93,18 +149,27 @@ files:
93
149
  - exe/mmi
94
150
  - lib/mmi.rb
95
151
  - lib/mmi/assets_processor.rb
152
+ - lib/mmi/cached_download.rb
153
+ - lib/mmi/github_api.rb
96
154
  - lib/mmi/interactive.rb
155
+ - lib/mmi/interactive/assets.rb
156
+ - lib/mmi/interactive/modloader.rb
97
157
  - lib/mmi/interactive/updater.rb
98
158
  - lib/mmi/mod_file_processor.rb
99
159
  - lib/mmi/modloader/fabric.rb
100
160
  - lib/mmi/modloader/none.rb
161
+ - lib/mmi/modrinth_api.rb
162
+ - lib/mmi/option_attributes.rb
101
163
  - lib/mmi/semver.rb
102
164
  - lib/mmi/source/github.rb
165
+ - lib/mmi/source/modrinth.rb
166
+ - lib/mmi/source/url.rb
103
167
  - lib/mmi/version.rb
104
168
  homepage: https://github.com/expeehaa/mmi
105
169
  licenses:
106
170
  - GPL-3.0-only
107
- metadata: {}
171
+ metadata:
172
+ rubygems_mfa_required: 'true'
108
173
  post_install_message:
109
174
  rdoc_options: []
110
175
  require_paths:
@@ -113,14 +178,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
178
  requirements:
114
179
  - - ">="
115
180
  - !ruby/object:Gem::Version
116
- version: '0'
181
+ version: '3.0'
117
182
  required_rubygems_version: !ruby/object:Gem::Requirement
118
183
  requirements:
119
184
  - - ">="
120
185
  - !ruby/object:Gem::Version
121
186
  version: '0'
122
187
  requirements: []
123
- rubygems_version: 3.2.3
188
+ rubygems_version: 3.3.3
124
189
  signing_key:
125
190
  specification_version: 4
126
191
  summary: Program to install minecraft modloaders, mods and other assets through a