CheckSwiftGen 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/check_swiftgen.rb +113 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9a21abdefa94daa74697037e0017f16296b12c109a1600790ecb44b3e1e08104
4
+ data.tar.gz: 594b178789cac18199a23ad97d7a3bc3d2484caf6e49868c1f2bce1f9e6b5f99
5
+ SHA512:
6
+ metadata.gz: 9cd148cf611e5fa5ae16c79d8c2560aaec31fab958be2772d6df6ae257ee7335d42f4306ef8b02ef21d2fdc4ee934ecc5f699b09832fdb9f0674d735602b0234
7
+ data.tar.gz: ecb80e093f768b866ac8197242d11a39f7125e9c7a631bceef5a12ada2b12401dd3c3510f4de871e19ce11c7ab36a91c9c362a60146c31ee73afde53bfb05fe2
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ require 'digest'
4
+ require 'json'
5
+ require 'find'
6
+ require 'yaml'
7
+
8
+ class CheckSwiftGen
9
+
10
+ def cache_invalidate(configuration_file, lock_path)
11
+
12
+ if File.file?("#{configuration_file}") == false
13
+ puts("Configuration File not found")
14
+ return
15
+ end
16
+
17
+ if lock_path.nil? {}
18
+ puts("Please input the lock path")
19
+ return
20
+ end
21
+
22
+ text = File.read(configuration_file)
23
+ dictionary = YAML.load(text)
24
+
25
+ assets_inputs = []
26
+ if (dictionary.has_key?('xcassets'))
27
+ xcassets = dictionary['xcassets']
28
+ if (xcassets.has_key?('inputs'))
29
+ assets_inputs = xcassets['inputs']
30
+ end
31
+ end
32
+
33
+ strings_inputs = []
34
+ if (dictionary.has_key?('strings'))
35
+ strings = dictionary['strings']
36
+ if (strings.has_key?('inputs'))
37
+ strings_inputs = strings['inputs']
38
+ end
39
+ end
40
+
41
+ return exist_new_files(
42
+ assets_hash(assets_inputs),
43
+ strings_hash(strings_inputs),
44
+ lock_path
45
+ )
46
+ end
47
+
48
+ def exist_new_files(assets_map, strings_map, lock_path)
49
+
50
+ tmp_name_file = "SwiftGen.tmp.lock"
51
+ lock_name_file = "SwiftGen.lock"
52
+
53
+ tmp_path_file = lock_path + "/" + tmp_name_file
54
+ lock_path_file = lock_path + "/" + lock_name_file
55
+
56
+ lock_file = Hash.new
57
+ lock_file["assets"] = assets_map
58
+ lock_file["strings"] = strings_map
59
+
60
+
61
+ if File.file?("#{tmp_path_file}")
62
+ File.delete(tmp_path_file)
63
+ end
64
+
65
+ File.write(tmp_path_file, lock_file.to_json)
66
+ new_hash = Digest::SHA512.file tmp_path_file
67
+ File.delete(tmp_path_file)
68
+
69
+ old_hash = ""
70
+ if File.file?("#{lock_path_file}")
71
+ old_hash = Digest::SHA512.file "#{lock_path_file}"
72
+ end
73
+
74
+ if old_hash != new_hash
75
+ old_hash = new_hash
76
+ File.write(lock_path_file, lock_file.to_json)
77
+ return true
78
+ else
79
+ return false
80
+ end
81
+ end
82
+
83
+ def assets_hash(assets_file_paths)
84
+ assets_map = Hash.new
85
+ assets_file_paths.each do |asset_file_paths|
86
+
87
+ files = Find.find(asset_file_paths).select { |p| /.*\.json$/ =~ p }
88
+ asset_map = Hash.new
89
+
90
+ files.each do |img_file|
91
+ sha512 = Digest::SHA512.file img_file
92
+ asset_map[img_file] = sha512
93
+ end
94
+
95
+ assets_map[asset_file_paths] = asset_map
96
+ end
97
+
98
+ return assets_map
99
+ end
100
+
101
+ def strings_hash(strings_file_paths)
102
+ strings_map = Hash.new
103
+ strings_file_paths.each do |string|
104
+ keys = string.split('/')[-2] + "/" + string.split('/').last
105
+ sha512 = Digest::SHA512.file string
106
+ strings_map[keys] = sha512
107
+ end
108
+ return strings_map
109
+ end
110
+ end
111
+
112
+ CheckSwiftGen.new.cache_invalidate(ARGV[0], ARGV[1])
113
+
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: CheckSwiftGen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ruslan Prokofev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple checking for repeat call swiftgen
14
+ email: mefilt@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/check_swiftgen.rb
20
+ homepage: http://instagram.com/mefilt
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.2.15
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Hola!
43
+ test_files: []