copy_tuner_incompatible_search 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -0
- data/Rakefile +2 -2
- data/exe/copy_tuner_incompatible_search +6 -1
- data/lib/copy_tuner_incompatible_search/command.rb +67 -88
- data/lib/copy_tuner_incompatible_search/version.rb +1 -1
- data/lib/copy_tuner_incompatible_search/xlsx_writer.rb +78 -0
- data/lib/copy_tuner_incompatible_search.rb +3 -2
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea523148710e0770c70a4777d23d84ae93b02c1d7e4d92e7b96080f0a2188a6f
|
4
|
+
data.tar.gz: c5f2a3729156ca2dfe2871e6f78776bd0996772c1e123209f1ecf46126a2fbc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d615646ece07c67dee19035058beffe7c57608477d247faf1eac486aaefcbe860fb25cbe1d2a4f686b52a3e81901501796742f7f8682408b268a8b379988a7f5
|
7
|
+
data.tar.gz: 63a79cdd22595f74d16faf6f4337ac9be4939539adf230cdd0ed7616d113e8a560b33e4c07a51d98a7cbd211a7434a59b7dd21d68ea4da1b2baf99cb16f881ef
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
inherit_gem:
|
4
|
+
sgcop: ruby/rubocop.yml
|
5
|
+
require:
|
6
|
+
- rubocop-rake
|
7
|
+
- rubocop-rspec
|
8
|
+
|
9
|
+
Bundler/GemComment:
|
10
|
+
Enabled: false
|
11
|
+
RSpec/DescribedClass:
|
12
|
+
Enabled: false
|
13
|
+
RSpec/ReceiveMessages:
|
14
|
+
Enabled: false
|
15
|
+
RSpec/NestedGroups:
|
16
|
+
Enabled: false
|
data/Rakefile
CHANGED
@@ -2,4 +2,9 @@
|
|
2
2
|
|
3
3
|
require_relative '../lib/copy_tuner_incompatible_search/command'
|
4
4
|
|
5
|
-
|
5
|
+
project_name = File.basename(Dir.pwd)
|
6
|
+
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
7
|
+
output_path = "tmp/usages-#{project_name}-#{timestamp}.xlsx"
|
8
|
+
CopyTunerIncompatibleSearch::Command.run(output_path)
|
9
|
+
puts "open #{output_path}"
|
10
|
+
`open #{output_path}`
|
@@ -5,53 +5,19 @@ require 'set'
|
|
5
5
|
|
6
6
|
module CopyTunerIncompatibleSearch
|
7
7
|
class Command
|
8
|
-
def self.run
|
9
|
-
self.new.run
|
8
|
+
def self.run(output_path)
|
9
|
+
self.new.run(output_path)
|
10
10
|
end
|
11
11
|
|
12
|
-
def run
|
13
|
-
puts
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# 完全一致する翻訳キー
|
22
|
-
puts "Searching #{keys.count} keys"
|
23
|
-
count = 0
|
24
|
-
results = {}
|
25
|
-
keys.each do |key|
|
26
|
-
count += 1
|
27
|
-
puts "#{count} / #{keys.count}" if count % 100 == 0
|
28
|
-
|
29
|
-
results[key] ||= Result.new(:static, key)
|
30
|
-
result = `git grep -n "#{Regexp.escape(key)}"`.strip
|
31
|
-
unless result.empty?
|
32
|
-
results[key].add_usage(result)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# .で始まる翻訳キー
|
37
|
-
grep_result = `git grep -n -P "\\btt?[ \\(]['\\"]\\.\\w+"`
|
38
|
-
results['lazy'] = Result.new(:lazy, "")
|
39
|
-
results['lazy'].add_usage(grep_result)
|
40
|
-
|
41
|
-
# 変数を含む翻訳キー
|
42
|
-
grep_result = `git grep -n -P "\\btt?[ \\(]['\\"][\\w.-]*[#$]"`
|
43
|
-
results['with vars'] = Result.new(:dynamic, "")
|
44
|
-
results['with vars'].add_usage(grep_result)
|
45
|
-
|
46
|
-
# Excelに出力
|
47
|
-
project_name = File.basename(Dir.pwd)
|
48
|
-
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
|
49
|
-
output_path = "tmp/usages-#{project_name}-#{timestamp}.xlsx"
|
50
|
-
dump_to_xlsx(results, keys, output_path)
|
51
|
-
|
52
|
-
puts "Finish"
|
53
|
-
puts "open #{output_path}"
|
54
|
-
`open #{output_path}`
|
12
|
+
def run(output_path)
|
13
|
+
puts 'Start'
|
14
|
+
incompatible_keys = search_incompatible_keys
|
15
|
+
results = search_static_usages(incompatible_keys)
|
16
|
+
results << search_lazy_usages
|
17
|
+
results << search_dynamic_usages
|
18
|
+
ignored_keys = Set[*eval(ignored_keys_text)] # rubocop:disable Security/Eval
|
19
|
+
XlsxWriter.dump_to_xlsx(results, incompatible_keys, ignored_keys, output_path)
|
20
|
+
puts 'Finish'
|
55
21
|
end
|
56
22
|
|
57
23
|
private
|
@@ -65,6 +31,10 @@ module CopyTunerIncompatibleSearch
|
|
65
31
|
@usages = []
|
66
32
|
end
|
67
33
|
|
34
|
+
def static?
|
35
|
+
@type == :static
|
36
|
+
end
|
37
|
+
|
68
38
|
def lazy?
|
69
39
|
@type == :lazy
|
70
40
|
end
|
@@ -90,7 +60,7 @@ module CopyTunerIncompatibleSearch
|
|
90
60
|
attr_reader :file, :line, :code, :lazy_key
|
91
61
|
|
92
62
|
def initialize(grep_result, lazy_key = nil)
|
93
|
-
file, line, code = grep_result.split(
|
63
|
+
file, line, code = grep_result.split(':', 3)
|
94
64
|
@file = file
|
95
65
|
@line = line
|
96
66
|
@code = code.strip
|
@@ -98,53 +68,62 @@ module CopyTunerIncompatibleSearch
|
|
98
68
|
end
|
99
69
|
end
|
100
70
|
|
101
|
-
def
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
71
|
+
def search_incompatible_keys
|
72
|
+
stdout = detect_html_incompatible_keys
|
73
|
+
keys = stdout.lines(chomp: true).map do |line|
|
74
|
+
line.split('.', 2).last
|
75
|
+
end.uniq.sort
|
76
|
+
Set[*keys]
|
106
77
|
end
|
107
78
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
# freeze pane
|
116
|
-
sheet.sheet_view.pane do |pane|
|
117
|
-
pane.top_left_cell = 'A2'
|
118
|
-
pane.state = :frozen_split
|
119
|
-
pane.y_split = 1
|
120
|
-
pane.x_split = 0
|
121
|
-
pane.active_pane = :bottom_right
|
122
|
-
end
|
79
|
+
def search_static_usages(incompatible_keys)
|
80
|
+
puts "Searching #{incompatible_keys.count} keys"
|
81
|
+
count = 0
|
82
|
+
incompatible_keys.map do |key|
|
83
|
+
count += 1
|
84
|
+
puts "#{count} / #{incompatible_keys.count}" if (count % 100).zero?
|
123
85
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
path = usage.file.sub(/^app\/views\//, '').sub(/\..+$/, '').sub('/_', '/').gsub('/', '.')
|
129
|
-
path + usage.lazy_key
|
130
|
-
else
|
131
|
-
result.key
|
132
|
-
end
|
133
|
-
already_migrated = usage.file == 'config/initializers/copy_tuner.rb' || usage.code.include?("#{usage.lazy_key || result.key}_html")
|
134
|
-
if (!result.lazy? || keys.include?(key)) && !already_migrated
|
135
|
-
ignored = unless result.dynamic? then ignored_keys.include?(key) ? "Y" : "N" end
|
136
|
-
sheet.add_row [result.type, key, ignored.to_s, usage.file, usage.line, usage.code], style: monospace_style
|
137
|
-
added = true
|
138
|
-
end
|
139
|
-
end
|
140
|
-
if !added && !result.lazy?
|
141
|
-
ignored = ignored_keys.include?(result.key) ? "Y" : "N"
|
142
|
-
sheet.add_row [result.type, result.key, ignored.to_s, "", "", ""], style: monospace_style
|
143
|
-
end
|
144
|
-
end
|
86
|
+
result = Result.new(:static, key)
|
87
|
+
usage = grep_usage(key).strip
|
88
|
+
unless usage.empty?
|
89
|
+
result.add_usage(usage)
|
145
90
|
end
|
146
|
-
|
91
|
+
result
|
147
92
|
end
|
148
93
|
end
|
94
|
+
|
95
|
+
def search_lazy_usages
|
96
|
+
grep_result = grep_lazy_keys
|
97
|
+
result = Result.new(:lazy, '')
|
98
|
+
result.add_usage(grep_result)
|
99
|
+
result
|
100
|
+
end
|
101
|
+
|
102
|
+
def search_dynamic_usages
|
103
|
+
grep_result = grep_dynamic_keys
|
104
|
+
result = Result.new(:dynamic, '')
|
105
|
+
result.add_usage(grep_result)
|
106
|
+
result
|
107
|
+
end
|
108
|
+
|
109
|
+
def detect_html_incompatible_keys
|
110
|
+
`rails copy_tuner:detect_html_incompatible_keys`
|
111
|
+
end
|
112
|
+
|
113
|
+
def grep_lazy_keys
|
114
|
+
`git grep -n -P "\\btt?[ \\(]['\\"]\\.\\w+"`
|
115
|
+
end
|
116
|
+
|
117
|
+
def grep_dynamic_keys
|
118
|
+
`git grep -n -P "\\btt?[ \\(]['\\"][\\w.-]*[#$]"`
|
119
|
+
end
|
120
|
+
|
121
|
+
def grep_usage(key)
|
122
|
+
`git grep -n "#{Regexp.escape(key)}"`
|
123
|
+
end
|
124
|
+
|
125
|
+
def ignored_keys_text
|
126
|
+
`rails r "p CopyTunerClient::configuration.ignored_keys"`
|
127
|
+
end
|
149
128
|
end
|
150
129
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CopyTunerIncompatibleSearch
|
4
|
+
class XlsxWriter
|
5
|
+
def self.dump_to_xlsx(results, incompatible_keys, ignored_keys, output_path)
|
6
|
+
self.new(results, incompatible_keys, ignored_keys).dump_to_xlsx(output_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(results, incompatible_keys, ignored_keys)
|
10
|
+
@results = results
|
11
|
+
@incompatible_keys = incompatible_keys
|
12
|
+
@ignored_keys = ignored_keys
|
13
|
+
end
|
14
|
+
|
15
|
+
def dump_to_xlsx(output_path)
|
16
|
+
Axlsx::Package.new do |p|
|
17
|
+
p.workbook.add_worksheet(name: 'Data') do |sheet|
|
18
|
+
style = sheet.styles.add_style(font_name: 'Courier New', sz: 14)
|
19
|
+
sheet.add_row %w[Type Key Ignored File Line Code], style: style
|
20
|
+
sheet.auto_filter = 'A1:F1'
|
21
|
+
freeze_pane(sheet)
|
22
|
+
|
23
|
+
results.each do |result|
|
24
|
+
add_result_rows(sheet, result, style)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
p.serialize(output_path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :results, :incompatible_keys, :ignored_keys
|
34
|
+
|
35
|
+
def freeze_pane(sheet)
|
36
|
+
sheet.sheet_view.pane do |pane|
|
37
|
+
pane.top_left_cell = 'A2'
|
38
|
+
pane.state = :frozen_split
|
39
|
+
pane.y_split = 1
|
40
|
+
pane.x_split = 0
|
41
|
+
pane.active_pane = :bottom_right
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_result_rows(sheet, result, style)
|
46
|
+
added = false
|
47
|
+
result.usages.each do |usage|
|
48
|
+
key = build_key(result, usage)
|
49
|
+
next unless should_output?(usage, result, key)
|
50
|
+
|
51
|
+
ignored = ignored_flag(key) unless result.dynamic?
|
52
|
+
sheet.add_row [result.type, key, ignored.to_s, usage.file, usage.line, usage.code], style: style
|
53
|
+
added = true
|
54
|
+
end
|
55
|
+
if !added && result.static?
|
56
|
+
sheet.add_row [result.type, result.key, ignored_flag(result.key), '', '', ''], style: style
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_key(result, usage)
|
61
|
+
if result.lazy?
|
62
|
+
path = usage.file.sub(%r{^app/views/}, '').sub(/\..+$/, '').sub('/_', '/').gsub('/', '.')
|
63
|
+
path + usage.lazy_key
|
64
|
+
else
|
65
|
+
result.key
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def should_output?(usage, result, key)
|
70
|
+
already_migrated = usage.file == 'config/initializers/copy_tuner.rb' || usage.code.include?("#{usage.lazy_key || result.key}_html")
|
71
|
+
(!result.lazy? || incompatible_keys.include?(key)) && !already_migrated
|
72
|
+
end
|
73
|
+
|
74
|
+
def ignored_flag(key)
|
75
|
+
ignored_keys.include?(key) ? 'Y' : 'N'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative 'copy_tuner_incompatible_search/version'
|
4
|
+
require_relative 'copy_tuner_incompatible_search/command'
|
5
|
+
require_relative 'copy_tuner_incompatible_search/xlsx_writer'
|
5
6
|
|
6
7
|
module CopyTunerIncompatibleSearch
|
7
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy_tuner_incompatible_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Junichi Ito
|
@@ -33,6 +33,7 @@ extensions: []
|
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
35
|
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
36
37
|
- CHANGELOG.md
|
37
38
|
- CODE_OF_CONDUCT.md
|
38
39
|
- LICENSE.txt
|
@@ -42,6 +43,7 @@ files:
|
|
42
43
|
- lib/copy_tuner_incompatible_search.rb
|
43
44
|
- lib/copy_tuner_incompatible_search/command.rb
|
44
45
|
- lib/copy_tuner_incompatible_search/version.rb
|
46
|
+
- lib/copy_tuner_incompatible_search/xlsx_writer.rb
|
45
47
|
- sig/copy_tuner_incompatible_search.rbs
|
46
48
|
homepage: https://github.com/JunichiIto/copy_tuner_incompatible_search
|
47
49
|
licenses:
|
@@ -50,6 +52,7 @@ metadata:
|
|
50
52
|
allowed_push_host: https://rubygems.org
|
51
53
|
homepage_uri: https://github.com/JunichiIto/copy_tuner_incompatible_search
|
52
54
|
changelog_uri: https://github.com/JunichiIto/copy_tuner_incompatible_search/CHANGELOG.md
|
55
|
+
rubygems_mfa_required: 'true'
|
53
56
|
post_install_message:
|
54
57
|
rdoc_options: []
|
55
58
|
require_paths:
|