cocoapods-bb-PodAssistant 0.3.8.0 → 0.3.10.0

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.
@@ -0,0 +1,55 @@
1
+ # 设置默认编码
2
+ Encoding.default_external = Encoding::UTF_8
3
+ Encoding.default_internal = Encoding::UTF_8
4
+
5
+ require 'find'
6
+ module BBItools
7
+ class CodeCouner
8
+ attr_accessor :file_path, :line_number
9
+ def initialize(path)
10
+ @file_path = path
11
+ @line_number = 0
12
+ end
13
+ # 统计行数
14
+ def calculate_line_number
15
+ puts "\033[33m正在统计#{@file_path} 代码行数,请稍后...\033[0m"
16
+ if File.file?(@file_path)
17
+ File.read(@file_path).each_line do |line|
18
+ if line.match(/^\/\/|^$/) == nil #去掉单行注释和空行
19
+ @line_number = @line_number + 1
20
+ end
21
+ end
22
+
23
+ return
24
+ end
25
+ if File::directory?(@file_path)
26
+ Find.find(@file_path) do |file|
27
+ if File.file?(file) #判断是否是文件
28
+ #只统计.h/.m/.mm/.cpp/.swift几个文件
29
+ # if File.extname(file).match(/^.[hm]m?$|.cpp|.swift/)
30
+ if File.extname(file).match(/\.(h|hpp|m|mm|cpp|swift)$/)
31
+ File.read(file).each_line do |line|
32
+ if line.match(/^\/\/|^$/) == nil #去掉单行注释和空行
33
+ @line_number = @line_number + 1
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ return
40
+ end
41
+ puts "\033[31m找不到指定路径的文件或者文件夹,请重新输入路径\033[0m"
42
+ end
43
+
44
+ def self.count_line(args)
45
+ file = args[0]
46
+ if file.nil?
47
+ puts "\033[31m参数异常,请传入一个参数(项目目录/要统计的文件目录/要统计的文件)\033[0m"
48
+ return
49
+ end
50
+ counter = CodeCouner.new(file)
51
+ counter.calculate_line_number
52
+ puts "\033[32m统计#{counter.file_path}结束,共#{counter.line_number}行\033[0m"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,78 @@
1
+ require 'find'
2
+ require 'spreadsheet'
3
+ module BBItools
4
+ class FileResult
5
+ attr_accessor :keyword, :file_path, :file_name
6
+ def initialize(temp_path,temp_name)
7
+ @file_path = temp_path
8
+ @file_name = temp_name
9
+ end
10
+ end
11
+ class FileSearcher
12
+ # path:搜索的路径,files要搜索的文件,支持数组用逗号隔开即可。支持模糊搜索
13
+ attr_accessor :path ,:files, :search_result
14
+ def initialize(temp_path,temp_files)
15
+ @path = temp_path
16
+ @files = temp_files
17
+ @search_result = []
18
+ end
19
+ def search
20
+ puts "\033[32m开始查找...\033[0m"
21
+ if File::directory?(@path)
22
+ Find.find(@path) do |file|
23
+ if File.file?(file)
24
+ file_name = File.basename(file)
25
+ if file_name.include?(@files)
26
+ fr = FileResult.new(file,file_name)
27
+ @search_result << fr
28
+ end
29
+ else
30
+ # puts "查找#{file}..."
31
+ end
32
+ end
33
+ else
34
+ puts "\033[31m文件夹有误,请输入文件夹路径作为第一个参数\033[0m"
35
+ end
36
+ end
37
+ # 对外暴露方法
38
+ def self.searchFile(args)
39
+ path = args[0]
40
+ files = args[1]
41
+ if path.nil? || files.nil?
42
+ puts "\033[31m参数异常,请传入两个参数,第一个为路径,第二个为要搜索的文件名\033[0m"
43
+ return
44
+ end
45
+ # temp_files = files.split(",")
46
+ file_searcher = FileSearcher.new(path,files)
47
+ file_searcher.search
48
+ if file_searcher.search_result.size == 0
49
+ puts "\033[32m没有找到符合条件的文件\033[0m"
50
+ return
51
+ end
52
+ # 输出
53
+ # 输出搜索的内容
54
+
55
+ Spreadsheet.client_encoding = 'utf-8'
56
+ book = Spreadsheet::Workbook.new
57
+ sheet1 = book.create_worksheet
58
+ sheet1.row(0)[0] = "序号"
59
+ sheet1.row(0)[1] = "文件名"
60
+ sheet1.row(0)[2] = "文件所在路径"
61
+
62
+
63
+ puts "\033[32m找到共#{file_searcher.search_result.size}个文件结果如下;\033[0m"
64
+ file_searcher.search_result.each_with_index {|item,i|
65
+ puts item.file_name
66
+ sheet1.row(i+1)[0] = i + 1
67
+ sheet1.row(i+1)[1] = item.file_name
68
+ sheet1.row(i+1)[2] = item.file_path
69
+ sheet1.row(i+1).height = 20
70
+ }
71
+ sheet1.column(0).width = 4
72
+ sheet1.column(1).width = 45
73
+ sheet1.column(2).width = 100
74
+ book.write "#{File.dirname(path)}/search_#{files}_result.xls"
75
+ puts "\033[32m查找成功,共#{file_searcher.search_result.size}个文件,内容已经保存到#{File.dirname(path)}/search_#{files}_result.xls,请点击查看\033[0m"
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,132 @@
1
+ require 'find'
2
+ require 'spreadsheet'
3
+ module BBItools
4
+ class FindResult
5
+ attr_accessor :name , :path
6
+ def initialize(name,path)
7
+ @name = name
8
+ @path = path
9
+ end
10
+
11
+ end
12
+ # --------------------------------------------
13
+ class ImgFinder
14
+ #
15
+ attr_accessor :image_count, :images, :unuse_images,:find_path
16
+ attr_accessor :search_files
17
+ def initialize
18
+ @image_count = 0
19
+ @images = []
20
+ @search_files = []
21
+ end
22
+ # 得到所有图片名称字符
23
+ def get_img_name_strs
24
+ result_arr = []
25
+ @images.each {|item|
26
+ item_name = Image.get_image_name(File.basename(item.name, ".*"))
27
+ result_arr << item_name
28
+ }
29
+ return result_arr
30
+ end
31
+ def get_image_path(image)
32
+ @images.each {|item|
33
+ if item.name.eql?(image)
34
+ return item.path
35
+ end
36
+ }
37
+ end
38
+ # 查找
39
+ def self.find(temp_find_dir)
40
+ imgFinder = ImgFinder.new
41
+ imgFinder.find_path = temp_find_dir
42
+ # 第一步:找到该文件夹下所有的图片文件
43
+ Find.find(temp_find_dir) do |filename|
44
+ if File.file?(filename) #如果是文件,则从文件中查找,忽略文件夹
45
+ if Image.is_image_format(File.extname(filename))
46
+ # p File.basename(filename)
47
+ # exit
48
+ imgFinder.image_count = imgFinder.image_count + 1
49
+ imageResult = FindResult.new(Image.get_image_name(File.basename(filename,".*")),filename)
50
+ imgFinder.images << imageResult
51
+ elsif File.extname(filename).eql?(".m") || File.extname(filename).eql?(".swift")
52
+ imgFinder.search_files << filename
53
+ end
54
+ end
55
+ end
56
+ if imgFinder.images.size == 0
57
+ puts "\033[32m查找成功,未发现图片\033[0m"
58
+ return
59
+ else
60
+ puts "\033[32m查找成功,共发现图片#{imgFinder.images.size}张\033[0m"
61
+ end
62
+ # 第二步:找到图片是否使用
63
+ imags = imgFinder.get_img_name_strs.uniq #要查找的图片名称数组
64
+
65
+ puts "\033[32m需要查找的图片有#{imags.size}张\033[0m"
66
+ # imgFinder.search_files #要查找的文件
67
+ imgFinder.search_files.each {|file|
68
+ File.read(file).each_line do |line|
69
+ haveStr = StringHandle.containsStr(line,imags)
70
+ if haveStr != -1
71
+ puts "#{imags[haveStr]}在使用...,剩余查找项#{imags.size-1}个"
72
+ imags.delete_at(haveStr)
73
+ end
74
+ end
75
+ }
76
+ puts "\033[32m无用图片#{imags.size}张,图片名称如下:\033[0m"
77
+ unuse_total_size = 0
78
+
79
+ Spreadsheet.client_encoding = 'utf-8'
80
+ book = Spreadsheet::Workbook.new
81
+ sheet1 = book.create_worksheet
82
+ sheet1.row(0)[0] = "文件名"
83
+ sheet1.row(0)[1] = "文件路径"
84
+ sheet1.row(0)[2] = "文件大小(B)"
85
+ imags.each_with_index {|item,idx|
86
+ sheet1.row(idx+1)[0] = item
87
+ path = imgFinder.get_image_path(item)
88
+ sheet1.row(idx+1)[1] = path
89
+ unuse_total_size = unuse_total_size + File.size(path)
90
+ sheet1.row(idx+1)[2] = File.size(path)
91
+ puts item
92
+ }
93
+ book.write "#{imgFinder.find_path}/search_result.xls"
94
+ puts "\033[32m文件已经保存到#{imgFinder.find_path}/search_result.xls,无用图片大小:#{unuse_total_size}B\033[0m"
95
+ puts "\033[32m内容仅供参考,具体还要自己通过结果查看一下\033[0m"
96
+ end
97
+ end
98
+ # 字符串操作类
99
+ class StringHandle
100
+ # originStr中是否包含targetStrs中的内容
101
+ def self.containsStr(originStr,targetStrs)
102
+ targetStrs.each_with_index {|item,idx|
103
+ if originStr.include?(item)
104
+ return idx
105
+ end
106
+ }
107
+ return -1
108
+ end
109
+ end
110
+ # ----------------------------
111
+ class Image
112
+
113
+ # 是否是图片格式,这里只判断了jpg、png和gif
114
+ def self.is_image_format(temp_ext_name)
115
+ if ['.jpg','.png','.gif'].include?(temp_ext_name)
116
+ return true
117
+ else
118
+ return false
119
+ end
120
+ end
121
+ def self.get_image_name(file)
122
+ return file.gsub(/@2x|@3x/,"")
123
+ end
124
+ end
125
+ # class ObjectiveC
126
+ # def self.is_h_file(temp_ext_name)
127
+ # if ['.h']
128
+
129
+ # end
130
+ # end
131
+ # end
132
+ end
@@ -0,0 +1,94 @@
1
+ require 'find'
2
+ module BBItools
3
+ class Memory
4
+ attr_accessor :pro
5
+ # 分发吹
6
+ def hand_cal_size(file,prop)
7
+ if prop.nil?
8
+ @pro = 1024
9
+ elsif prop == 0
10
+ @pro = 1024
11
+ else
12
+ @pro = prop
13
+ end
14
+ handle_method = ''
15
+ if File.file?(file)
16
+ puts "\033[32m开始计算文件的大小...\033[0m"
17
+ handle_method = 'cal_file'
18
+ elsif File::directory?(file)
19
+ handle_method = 'cal_folder'
20
+ puts "\033[32m开始计算文件夹的大小...\033[0m"
21
+ else
22
+ puts "\033[31m参数异常,请确保传入的第一个参数是文件路径或者文件夹路径\033[0m"
23
+ return
24
+ end
25
+ self.send(handle_method,file)
26
+ end
27
+ # 计算单个文件
28
+ def cal_file(file)
29
+ puts "\033[32m文件的大小为:#{get_show_size(File.size(file))}.\033[0m"
30
+ end
31
+ # 计算整个文件夹
32
+ def cal_folder(folder)
33
+ print "\033[32m请输入要查找文件后缀\033[0m(例如想文件夹中图片大小则输入:{png,jpg,gif},不输入则默认计算文件夹下所有文件大小之和):"
34
+ file_exts_string = STDIN.gets
35
+ file_exts_string.chomp! #过滤换行符
36
+ if file_exts_string.size == 0
37
+ file_exts = []
38
+ else
39
+ file_exts = file_exts_string.split(",")
40
+ end
41
+ sum = 0
42
+ file_count = 0
43
+ total_count = 0
44
+ total_size = 0
45
+ file_size = 0
46
+ Find.find(folder) do |filename|
47
+ if File.file?(filename)
48
+ total_count = total_count + 1
49
+ total_size = total_size + File.size(filename)
50
+ if file_exts.size == 0 #说明计算所有文件
51
+ sum = sum + File.size(filename)
52
+ file_count = file_count + 1
53
+ elsif file_exts.include?(File.extname(filename).delete(".")) #查找指定后缀的文件
54
+ sum = sum + File.size(filename)
55
+ file_count = file_count + 1
56
+ file_size = file_size + File.size(filename)
57
+ else
58
+ #不做任何处理
59
+ end
60
+ end
61
+ end
62
+ if file_exts.size == 0
63
+ puts "\033[32m文件夹中共#{total_count}个文件,共#{get_show_size(total_size)}(#{total_size})\033[0m"
64
+ else
65
+ puts "\033[32m文件夹中共#{total_count}个文件,共#{get_show_size(total_size)}(#{total_size});找到后缀为(#{file_exts_string})的文件#{file_count}个,共#{get_show_size(file_size)}(#{file_size}).\033[0m"
66
+ end
67
+
68
+ # puts `du -b #{folder} | awk '{print $1}'`.to_i
69
+ end
70
+ # get_show_size
71
+ def get_show_size(size)
72
+ if size > @pro * @pro * @pro
73
+ return format("%.2f",(size.to_f/(@pro*@pro*@pro))) + "GB"
74
+ elsif size > @pro * @pro
75
+ return format("%.2f",(size.to_f/(@pro*@pro))) + "MB"
76
+ elsif size > @pro
77
+ return format("%.2f",(size.to_f/@pro)) + "KB"
78
+ else
79
+ return size.to_s + "B"
80
+ end
81
+ end
82
+ # 对外暴露方法
83
+ def self.sizeFor(proport)
84
+ file = proport[0]
85
+ pro = proport[1].to_i
86
+ if file.nil?
87
+ puts "\033[31m参数异常,请传入一个参数\033[0m"
88
+ return
89
+ end
90
+ memory = Memory.new
91
+ memory.hand_cal_size(file,pro)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,42 @@
1
+ require 'colored2'
2
+
3
+ module BBItools
4
+ class GitSets
5
+ def self.commit_msg_init(args)
6
+ # folder_path = args[0]
7
+ # if folder_path.nil?
8
+ # puts "传入的参数不能为空".red
9
+ # return
10
+ # end
11
+ # if !File::directory?(folder_path)
12
+ # puts "参数不是文件夹".red
13
+ # return
14
+ # end
15
+ puts "开始配置CommitLint,用于校验commit message的工具...".yellow
16
+ system('touch ./.git/commit_msg')
17
+ system('git config commit.template "`pwd`/.git/commit_msg"')
18
+ a = <<-EOF
19
+ #!/bin/sh
20
+ echo "$(git symbolic-ref --short HEAD) subject" > `pwd`/.git/commit_msg
21
+ echo "" >> `pwd`/.git/commit_msg
22
+ echo "Cause:" >> `pwd`/.git/commit_msg
23
+ echo "Solution:" >> `pwd`/.git/commit_msg
24
+ echo "Releated Doc Address:" >> `pwd`/.git/commit_msg
25
+ echo '''\n#TYPE类型\n#新功能 feature/feat\n#bug修复 bugfix/fixbug/fix\n#性能优化 perf\n#代码重构 refactor/review\n#线上修复 hotfix\n#发布版本 release\n#文档变更 docs\n#更新 update\n#新增 add\n#标签 tag\n#代码回退 revert\n#更新lock lock''' >> `pwd`/.git/commit_msg
26
+ EOF
27
+ File.open('.git/hooks/pre-commit', 'w') do |f|
28
+ f.puts a
29
+ end
30
+ puts "写入CommitLint规则"
31
+ logo_path = File.join( File.dirname(__FILE__), 'temple-commit-msg.dat' )
32
+ content = File.read( logo_path )
33
+ File.open('.git/hooks/commit-msg', 'w') do |f|
34
+ f.puts content
35
+ end
36
+ puts "更新权限"
37
+ system('chmod a+x .git/hooks/pre-commit')
38
+ system('chmod a+x .git/hooks/commit-msg')
39
+ puts "配置成功,后续请直接使用git commit ,不要加 -m".green
40
+ end
41
+ end
42
+ end