img-lint 0.0.15 → 0.0.16

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
  SHA1:
3
- metadata.gz: 2e7ca6a6af39812e6438eb53872af32cbb718d35
4
- data.tar.gz: da145a07ec130eb64ac94651919a8be299f6600b
3
+ metadata.gz: c40d6bbcc1ec9690a2d4ca2a41d1e814838dbd11
4
+ data.tar.gz: e14e808b66b8dfb712a99e66a88a368c244cbbdc
5
5
  SHA512:
6
- metadata.gz: a3f36936ee512865675b65c7635875fb1ebe3fc670e1c0d8b6d31120683f5af870d38ba85f12d5cb5dd0e61b7611698b866f7e2301fe8f5c813b4d4f01071df2
7
- data.tar.gz: 57df00b95ee7b621991fd1ce8c6e2054c5f335a95982cba16a927a005c5c4b5ce78fbdb7de2d2edda9bce58572050fb8a4dbec5770f0496ade8e00b837fc431c
6
+ metadata.gz: 6c5ff65e4f72daeae5c723f1a5c4f0c96fa78d261fe39bbfdc7de1ad93fbc34e8aca35f6a89fd339c52e0333e62886e529ca79ad7925a0f6f48a8558cfadaab7
7
+ data.tar.gz: 8b45ddbfecd0337696f450a48ecce58db87bbc5074fd192bcc99cef8a721a6a94ce7db8dac3714b6ff5732fea24f5851c3225e5d9b60720b35a26b56ecbc7721
@@ -1,61 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH << File.expand_path("../../lib", __FILE__)
4
-
5
3
  require "img_lint"
6
- require "img_lint/config"
7
- require "img_lint/linter"
8
- require "optparse"
9
-
10
- if ARGV.first == "install"
11
- require "fileutils"
12
-
13
- target_file = File.join(Dir.pwd, ".img-lint.yml")
14
- config_file = File.join(File.expand_path(File.dirname(__FILE__)), "..", "config", "default.yml")
15
-
16
- FileUtils.cp(config_file, target_file)
17
- else
18
- options = {}
19
- OptionParser.new do |opts|
20
- def unindent(s)
21
- s.gsub(/^#{s.scan(/^[ \t]+(?=\S)/).min}/, "")
22
- end
23
-
24
- opts.banner = unindent(<<-TEXT)
25
- img-lint help
26
-
27
- 1. img-lint install
28
-
29
- This will copy default config to your local .img-lint.yml file
30
-
31
- 2. img-lint [options]
32
- TEXT
33
-
34
- opts.on("-v", "--version", "Prints current version of img-lint") do |v|
35
- puts IMGLint::VERSION
36
- exit 0
37
- end
38
-
39
- opts.on("-p", "--path PATH", "Path to a folder with images") do |v|
40
- options["path"] = v
41
- end
42
-
43
- opts.on("-m", "--max-size MAX_SIZE", "Max image size allowed, '150' by default (150Kb)") do |v|
44
- options["max_file_size"] = v.to_i
45
- end
46
-
47
- opts.on("-f", "--format IMAGE_FORMATS", "Image formats, 'jpg,png,gif' by default") do |v|
48
- options["image_formats"] = v
49
- end
50
- end.parse!
51
-
52
- config = IMGLint::Config.load
53
- config.merge!(options)
54
-
55
- path = config.delete("path")
56
-
57
- linter = IMGLint::Linter.new(config: config)
58
- fat_images = linter.lint(path: path)
4
+ require "img_lint/cli"
59
5
 
60
- exit fat_images.empty? ? 0 : 2
61
- end
6
+ exit IMGLint::CLI.new.run(ARGV)
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "img_lint/config"
4
+ require "img_lint/linter"
5
+ require "optparse"
6
+
7
+ $LOAD_PATH << File.expand_path(__dir__)
8
+
9
+ module IMGLint
10
+ # CLI class
11
+ #
12
+ class CLI
13
+ def run(args = [])
14
+ if args.first == "install"
15
+ require "fileutils"
16
+
17
+ target_file = File.join(Dir.pwd, ".img-lint.yml")
18
+ config_file = File.join(File.expand_path(__dir__), "..", "config", "default.yml")
19
+
20
+ FileUtils.cp(config_file, target_file)
21
+
22
+ 0
23
+ else
24
+ options = extract_options(args)
25
+
26
+ config = IMGLint::Config.load
27
+ config.merge!(options)
28
+
29
+ path = config.delete("path")
30
+
31
+ linter = IMGLint::Linter.new(config: config)
32
+ fat_images = linter.lint(path: path)
33
+
34
+ fat_images.empty? ? 0 : 2
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def unindent(str)
41
+ str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, "")
42
+ end
43
+
44
+ def extract_options(args)
45
+ options = {}
46
+
47
+ OptionParser.new do |opts|
48
+ opts.banner = unindent(<<-TEXT)
49
+ img-lint help
50
+
51
+ 1. img-lint install
52
+
53
+ This will copy default config to your local .img-lint.yml file
54
+
55
+ 2. img-lint [options]
56
+ TEXT
57
+
58
+ opts.on("-v", "--version", "Prints current version of img-lint") do
59
+ puts IMGLint::VERSION
60
+ exit 0
61
+ end
62
+
63
+ opts.on("-p", "--path PATH", "Path to a folder with images") do |v|
64
+ options["path"] = v
65
+ end
66
+
67
+ opts.on("-m", "--max-size MAX_SIZE", "Max image size allowed, '150' by default (150Kb)") do |v|
68
+ options["max_file_size"] = v.to_i
69
+ end
70
+
71
+ opts.on("-f", "--format IMAGE_FORMATS", "Image formats, 'jpg,png,gif' by default") do |v|
72
+ options["image_formats"] = v
73
+ end
74
+ end.parse!(args)
75
+
76
+ options
77
+ end
78
+ end
79
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "yaml"
4
+ require "img_lint/constants"
4
5
 
5
6
  module IMGLint
6
7
  # Config class is responsible to load img-lint either a user defined config
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IMGLint
4
- IMG_LINT_HOME = File.realpath(File.join(File.dirname(__FILE__), "..", ".."))
4
+ IMG_LINT_HOME = File.realpath(File.join(__dir__, "..", ".."))
5
5
  end
@@ -29,11 +29,11 @@ module IMGLint
29
29
  puts "No images found in #{path}" if verbose && images.empty?
30
30
 
31
31
  images.each_with_object({}) do |file, o|
32
+ next if excluded_file?(file)
33
+
32
34
  image_size = File.new(file).size / 1024
33
35
 
34
- if !excluded_file?(file) && image_size > config["max_file_size"]
35
- o[file] = image_size
36
- end
36
+ o[file] = image_size if image_size > config["max_file_size"]
37
37
  end
38
38
  end
39
39
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rake"
4
4
  require "rake/tasklib"
5
+ require "img_lint/cli"
5
6
 
6
7
  module IMGLint
7
8
  # Rake task
@@ -21,10 +22,7 @@ module IMGLint
21
22
  task(@name) do |_task|
22
23
  require "img_lint"
23
24
 
24
- linter = IMGLint::Linter.new
25
- fat_images = linter.lint
26
-
27
- exit fat_images.empty? ? 0 : 2
25
+ exit IMGLint::CLI.new.run
28
26
  end
29
27
  end
30
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IMGLint
4
- VERSION = "0.0.15".freeze
4
+ VERSION = "0.0.16".freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: img-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoli Makarevich
@@ -78,6 +78,7 @@ files:
78
78
  - bin/img-lint
79
79
  - config/default.yml
80
80
  - lib/img_lint.rb
81
+ - lib/img_lint/cli.rb
81
82
  - lib/img_lint/config.rb
82
83
  - lib/img_lint/constants.rb
83
84
  - lib/img_lint/linter.rb