Class: Stool::Command::Util::LibsCheck

Inherits:
Stool::Command::Util show all
Defined in:
lib/stool/Command/Util/LibsCheck.rb

Instance Method Summary collapse

Methods inherited from Stool::Command

#checkConfigFile, options, #pp

Constructor Details

#initialize(argv) ⇒ LibsCheck

self.arguments = [

CLAide::Argument.new('close', false),

]



16
17
18
19
20
21
22
23
# File 'lib/stool/Command/Util/LibsCheck.rb', line 16

def initialize(argv)
  if @@config.checkRepos.count > 0
    Spreadsheet.client_encoding="utf-8"
    #创建表格对象
    @book = Spreadsheet::Workbook.new
  end
  super
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stool/Command/Util/LibsCheck.rb', line 25

def run
  @@config.checkRepos.map { |e|
    summary_repo e
  }
  #在指定路径下面创建test1.xls表格,并写book对象
  path = File.join(Config.logsDirPath,'pod_summary.xls')
  Dir.chdir(Config.logsDirPath)
  @book.write path

  puts "已经生成Excel文件<#{path}>"

  `open #{path}`
end

#summary_repo(repo) ⇒ Object

统计某一个pod库



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/stool/Command/Util/LibsCheck.rb', line 40

def summary_repo(repo)
  repoPath = File.join(Dir.home,'.cocoapods/repos',repo)

  unless Dir.exist?(repoPath)
    puts "#{repoPath} does not exist!!".red
    return
  end

  puts `pod repo update #{repo}`

  #创建工作表
  sheet1 = @book.create_worksheet :name => "pod_summary_" + repo
  #在表格第一行设置分类
  sheet1.row(0)[0]="名字"
  sheet1.row(0)[1]="简介"
  sheet1.row(0)[1]="主页"

  Dir.chdir(repoPath)

  libs = []
  Dir.entries(repoPath).sort.uniq.each do |dir|
    unless dir['.']
      arr = Dir.entries(File.join(repoPath,dir)).sort
      if arr.last
        puts
        fname = Dir.entries(File.join(repoPath,dir,arr.last)).last
        libinfo = LibInfo.loadFromPath(File.join(repoPath,dir,arr.last))
        if libinfo
          libs.push(libinfo)
        end
      end
    end
  end

  puts Dir.entries(repoPath).count

  libs.each_with_index {|lib,idx|
    sheet1.row(idx+1)[0]= lib.name
    sheet1.row(idx+1)[1]= lib.summary
    sheet1.row(idx+1)[2]= lib.homepage
  }
end