cocoapods-scancode 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cocoapods-scancode/command/scancode.rb +38 -0
- data/lib/cocoapods-scancode/command.rb +1 -0
- data/lib/cocoapods-scancode/gem_version.rb +3 -0
- data/lib/cocoapods-scancode/trig.rb +226 -0
- data/lib/cocoapods-scancode.rb +1 -0
- data/lib/cocoapods_plugin.rb +1 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d426792416ef88663bea134490c0fa6bf73e821439c68556ba68425889f5c53
|
4
|
+
data.tar.gz: 9e79580b6967aaea6ef4268dc957473af890482caae229f9fbbdd7d2e7b6543d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f3e65773cc1d2d90fbdc2025e0d58862487b21bc9ae339b0a64ea23f7864b34c2d87aeb0bc3e09a2d6806ff1e747e38c2d8b74ed77725bb6fe003850047b596
|
7
|
+
data.tar.gz: a7b0429376e11884f353c6606ffebd54e4293fa1d21f2ec476bd17ca200b44313df6ac42508e015c4a90d494bd2c3a224d4c1e39418c9cebb1f27ec291d8a08a
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'cocoapods-scancode/trig'
|
2
|
+
|
3
|
+
module Pod
|
4
|
+
class Command
|
5
|
+
# This is an example of a cocoapods plugin adding a top-level subcommand
|
6
|
+
# to the 'pod' command.
|
7
|
+
#
|
8
|
+
# You can also create subcommands of existing or new commands. Say you
|
9
|
+
# wanted to add a subcommand to `list` to show newly deprecated pods,
|
10
|
+
# (e.g. `pod list deprecated`), there are a few things that would need
|
11
|
+
# to change.
|
12
|
+
#
|
13
|
+
# - move this file to `lib/pod/command/list/deprecated.rb` and update
|
14
|
+
# the class to exist in the the Pod::Command::List namespace
|
15
|
+
# - change this class to extend from `List` instead of `Command`. This
|
16
|
+
# tells the plugin system that it is a subcommand of `list`.
|
17
|
+
# - edit `lib/cocoapods_plugins.rb` to require this file
|
18
|
+
#
|
19
|
+
# @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
|
20
|
+
# in the `plugins.json` file, once your plugin is released.
|
21
|
+
#
|
22
|
+
class Scancode < Command
|
23
|
+
self.summary = 'scanc undefine key in code'
|
24
|
+
|
25
|
+
self.description = <<-DESC
|
26
|
+
help user scanc undefine key in code
|
27
|
+
DESC
|
28
|
+
|
29
|
+
self.arguments = []
|
30
|
+
|
31
|
+
|
32
|
+
def run
|
33
|
+
# UI.puts "Add your implementation for the cocoapods-scancode plugin in #{__FILE__}"
|
34
|
+
LocalizedScan.pipLine
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-scancode/command/scancode'
|
@@ -0,0 +1,226 @@
|
|
1
|
+
|
2
|
+
# require 'file'
|
3
|
+
# $LOAD_PATH << '.'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'find'
|
6
|
+
# -*- coding: UTF-8 -*-
|
7
|
+
|
8
|
+
class UnDefineKeyItem
|
9
|
+
def initialize(key,path)
|
10
|
+
@key = key
|
11
|
+
@filePath = path
|
12
|
+
end
|
13
|
+
|
14
|
+
def printKey
|
15
|
+
@key
|
16
|
+
end
|
17
|
+
|
18
|
+
def printFilePath
|
19
|
+
@filePath
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
keystring = @key.decoder('utf-8')
|
24
|
+
"未定义key:#{keystring},filePath:#{@filePath}" # 对象的字符串格式
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class LanguageModel
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@key = ''
|
32
|
+
@map = {"key"=>"key"}
|
33
|
+
end
|
34
|
+
|
35
|
+
def setKey(key)
|
36
|
+
@key = key
|
37
|
+
end
|
38
|
+
|
39
|
+
def setLanguageValue(newKey,value)
|
40
|
+
@map.store(newKey,value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
"(key:#{@key},map:#{@map})" # 对象的字符串格式
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class LocalizedScan
|
49
|
+
@@defineKeyDic = Hash.new
|
50
|
+
@@undefineKeyDic = Hash.new
|
51
|
+
#把资源包中的key都load进内存
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.loadBundleKey
|
58
|
+
bundPath = nil
|
59
|
+
#查找bundle路径
|
60
|
+
Find.find("./") do |filePath|
|
61
|
+
if filePath.end_with?("LMFramework.bundle")
|
62
|
+
bundPath = filePath
|
63
|
+
break
|
64
|
+
end
|
65
|
+
end
|
66
|
+
puts bundPath
|
67
|
+
Find.find(bundPath) do |filePath|
|
68
|
+
if filePath.end_with?("Localizable.strings")
|
69
|
+
self.findKey(filePath)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#提取出key
|
75
|
+
def self.findKey(filePath)
|
76
|
+
if File.exist?(filePath) == false
|
77
|
+
puts "#{filePath} 不存在-"
|
78
|
+
return
|
79
|
+
end
|
80
|
+
str = filePath.split('/')[-2]
|
81
|
+
lang = str.split('.')[0]
|
82
|
+
# puts "lang:#{lang}"
|
83
|
+
block = ""
|
84
|
+
File.open(filePath,"r").each_line{|line|
|
85
|
+
block += line
|
86
|
+
if line.end_with?("\";\n") and line.end_with?("\\\";\n") == false
|
87
|
+
left = block.index('"')
|
88
|
+
right = block.index('"',left+1)
|
89
|
+
key = block[left+1...right]
|
90
|
+
left = block.index('"',right+1)
|
91
|
+
right = block.rindex('"')
|
92
|
+
value = block[left+1...right]
|
93
|
+
if @@defineKeyDic[key] == nil
|
94
|
+
model = LanguageModel.new
|
95
|
+
model.setKey key
|
96
|
+
@@defineKeyDic[key] = model
|
97
|
+
else
|
98
|
+
# puts lang,value
|
99
|
+
model = @@defineKeyDic[key]
|
100
|
+
model.setLanguageValue(lang,value)
|
101
|
+
end
|
102
|
+
block = ""
|
103
|
+
end
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.scan
|
108
|
+
|
109
|
+
Find.find ("./") do |fileName|
|
110
|
+
# puts fileName
|
111
|
+
if fileName.end_with?".m"
|
112
|
+
self.scanKeyInOcCode(fileName)
|
113
|
+
elsif fileName.end_with?".swift"
|
114
|
+
self.scanKeyInSwiftCode(fileName)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.scanKeyInOcCode(path)
|
120
|
+
|
121
|
+
file = File.open(path,"r:utf-8") do |file|
|
122
|
+
block = ""
|
123
|
+
file.each_line do |line|
|
124
|
+
block += line
|
125
|
+
if line.end_with?";\n"
|
126
|
+
#处理block
|
127
|
+
self.filterKeyInOcBLock(block,path)
|
128
|
+
block = ""
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
file.close
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.scanKeyInSwiftCode(path)
|
137
|
+
|
138
|
+
file = File.open(path,"r:utf-8") do |file|
|
139
|
+
block = ""
|
140
|
+
file.each_line do |line|
|
141
|
+
block += line
|
142
|
+
if line.end_with?"\n"
|
143
|
+
#处理block
|
144
|
+
self.filterKeyInSwiftBLock(block,path)
|
145
|
+
block = ""
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
file.close
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.filterKeyInSwiftBLock(block,filePath)
|
154
|
+
keywords = ['LMBundleNSLocalizedString(','LHLocalizedTool.localizedString(forKey:']
|
155
|
+
keywords.each do |keyword|
|
156
|
+
tempBlock = block
|
157
|
+
while tempBlock.index(keyword) != nil do
|
158
|
+
#左引号
|
159
|
+
left = tempBlock.index(keyword)
|
160
|
+
# puts left
|
161
|
+
# puts tempBlock[left]
|
162
|
+
left = tempBlock.index('"',left+1)
|
163
|
+
right = tempBlock.index('"',left+1)
|
164
|
+
# puts right
|
165
|
+
# puts tempBlock[right]
|
166
|
+
key = tempBlock[left+1...right]
|
167
|
+
if @@defineKeyDic[key] == nil
|
168
|
+
print 'swift未定义的key:',key,"\n"
|
169
|
+
item = UnDefineKeyItem.new(key,filePath)
|
170
|
+
@@undefineKeyDic[key] = item
|
171
|
+
end
|
172
|
+
tempBlock = tempBlock[right+1..tempBlock.length-1]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.filterKeyInOcBLock(block,filePath)
|
178
|
+
keywords = ['localizedStringForKey:@"',
|
179
|
+
'LMCALanuage(@"',
|
180
|
+
'LMCTLanuage(@"',
|
181
|
+
'LMIrcodeLocalizedString(@"',
|
182
|
+
'LMLTLanuage(@"',
|
183
|
+
'LMMDLocalizedString(@"',
|
184
|
+
'kLMPositionFrameworkNSLocalized(@"']
|
185
|
+
keywords.each do |keyword|
|
186
|
+
tempBlock = block
|
187
|
+
while tempBlock.index(keyword) != nil do
|
188
|
+
#左引号
|
189
|
+
left = tempBlock.index(keyword) + keyword.length-1
|
190
|
+
# puts left
|
191
|
+
# puts tempBlock[left]
|
192
|
+
right = tempBlock.index('"',left+1)
|
193
|
+
# puts right
|
194
|
+
# puts tempBlock[right]
|
195
|
+
key = tempBlock[left+1...right]
|
196
|
+
#
|
197
|
+
if @@defineKeyDic[key] == nil
|
198
|
+
# print '未定义的key:',key,"\n"
|
199
|
+
item = UnDefineKeyItem.new(key,filePath)
|
200
|
+
@@undefineKeyDic[key] = item
|
201
|
+
end
|
202
|
+
tempBlock = tempBlock[right+1..tempBlock.length-1]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def self.pipLine
|
208
|
+
self.loadBundleKey
|
209
|
+
self.scan
|
210
|
+
# @@defineKeyDic.each_value do |model|
|
211
|
+
# puts model
|
212
|
+
# end
|
213
|
+
|
214
|
+
num = 0
|
215
|
+
@@undefineKeyDic.each_value do |item|
|
216
|
+
num += 1
|
217
|
+
puts "#{num}:#{item.printKey} filepath:#{item.printFilePath}"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
# str = 'localizedStringForKey:@"key"'
|
225
|
+
# LocalizedScan.filterKeyInBLock(str)
|
226
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-scancode/gem_version'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-scancode/command'
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cocoapods-scancode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jeremylu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A short description of cocoapods-scancode.
|
42
|
+
email:
|
43
|
+
- 1509028992@qq.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/cocoapods-scancode.rb
|
49
|
+
- lib/cocoapods-scancode/command.rb
|
50
|
+
- lib/cocoapods-scancode/command/scancode.rb
|
51
|
+
- lib/cocoapods-scancode/gem_version.rb
|
52
|
+
- lib/cocoapods-scancode/trig.rb
|
53
|
+
- lib/cocoapods_plugin.rb
|
54
|
+
homepage: https://github.com/EXAMPLE/cocoapods-scancode
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.3.26
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: A longer description of cocoapods-scancode.
|
77
|
+
test_files: []
|