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 +4 -4
- data/bin/img-lint +2 -57
- data/lib/img_lint/cli.rb +79 -0
- data/lib/img_lint/config.rb +1 -0
- data/lib/img_lint/constants.rb +1 -1
- data/lib/img_lint/linter.rb +3 -3
- data/lib/img_lint/rake_task.rb +2 -4
- data/lib/img_lint/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c40d6bbcc1ec9690a2d4ca2a41d1e814838dbd11
|
4
|
+
data.tar.gz: e14e808b66b8dfb712a99e66a88a368c244cbbdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c5ff65e4f72daeae5c723f1a5c4f0c96fa78d261fe39bbfdc7de1ad93fbc34e8aca35f6a89fd339c52e0333e62886e529ca79ad7925a0f6f48a8558cfadaab7
|
7
|
+
data.tar.gz: 8b45ddbfecd0337696f450a48ecce58db87bbc5074fd192bcc99cef8a721a6a94ce7db8dac3714b6ff5732fea24f5851c3225e5d9b60720b35a26b56ecbc7721
|
data/bin/img-lint
CHANGED
@@ -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/
|
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
|
-
|
61
|
-
end
|
6
|
+
exit IMGLint::CLI.new.run(ARGV)
|
data/lib/img_lint/cli.rb
ADDED
@@ -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
|
data/lib/img_lint/config.rb
CHANGED
data/lib/img_lint/constants.rb
CHANGED
data/lib/img_lint/linter.rb
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/img_lint/rake_task.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/img_lint/version.rb
CHANGED
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.
|
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
|