Module: QCloudHive::HiveModule

Defined in:
lib/qcloudhive/module.rb

Class Method Summary collapse

Class Method Details

.add(cmd, opts) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/qcloudhive/module.rb', line 17

def HiveModule.add(cmd, opts)
  name = GetOptValue(cmd, opts, :c_name)
  rootPath = Config.projectRootDirectory
  pwd = Dir.pwd
  projectPath = opts[:i_path]
  if projectPath == nil
    if pwd.start_with? rootPath
      projectPath = pwd[rootPath.length..-1]
      L.warn "您没有给定具体的目录 将使用当前目录#{projectPath}"
    else
      Error "您没有给定具体的目录,并且当前不在Hive工程中!!!!"
    end
  end
  addModuleByName(name, projectPath)
end

.addModuleByCreate(name, projectPath) ⇒ Object



63
64
65
66
67
# File 'lib/qcloudhive/module.rb', line 63

def HiveModule.addModuleByCreate(name, projectPath)
  gitProject = createModuleByName(name, projectPath)
  Config.manifest.addModule(gitProject.http_url_to_repo, projectPath)
  Config.manifest.flushStorage
end

.addModuleByName(name, projectPath) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/qcloudhive/module.rb', line 33

def HiveModule.addModuleByName(name, projectPath)
  L.debug "#{Config.manifest}"
  if Config.manifest.existModule?(name)
    L.warn "#{name} 已经在项目中,请不要重复添加"
  end
  if CodeOA.exist?(name)
    gitProject = CodeOA.existProjectByName?(name)
    if CodeOA.empty?(gitProject)
      addModuleByCreate(name, projectPath)
      return
    end
    Config.manifest.addModule(gitProject.http_url_to_repo, projectPath)
    Config.manifest.flushStorage
    L.debug "模块已经在git.code.oa.com上存在"
    puts "已经添加模块#{name}"
    podspec = HivePod.search(name)
    if podspec == nil
      L.warn"#{name} 已经存在于git.code.oa.com上,但是没有发布到cocoapods私有仓库,无法解析其依赖关系,将不进行依赖添加"
    else
      dependencies = podspec.specification.dependencies
      L.debug "#{name}依赖以下库 #{dependencies}"
      dependencies.each { |dependency|
         addModuleByName(dependency.name, projectPath)
      }
    end
  else
      L.warn "#{name} 不再git.code.oa.com上面"
      addModuleByCreate(name, projectPath)
  end
end

.createLocalModule(name, path) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/qcloudhive/module.rb', line 69

def HiveModule.createLocalModule(name, path)
  aimPodspecPath = "#{path}/#{name}.podspec"
  podspecTempPath = Config.templatesPath+"template.podspec"
  if Pathname(aimPodspecPath).exist?
    L.info "#{aimPodspecPath} exsit"
    return
  end
  tempFile= File.new(podspecTempPath, "r")
  if not Pathname(path).exist?
    FileUtils.mkdir_p(path)
  end

  if tempFile
    content = tempFile.read
    content = content.gsub(/<POD_NAME>/,"#{name}")
    File.open(aimPodspecPath, "w") { |f|
      f.write content
    }
    classPath = "#{path}/Pod/Classes"
    FileUtils.mkdir_p(classPath)
    File.open(classPath+"/replace.m", "w") { |f|
      f.write "//replace me !!!"
    }
    File.open("#{path}/README.md", "w") { |f|
      f.write "README"
    }
    g = Git.init(path)
    g.add(:all=>true)
    g.commit_all("mudule init")
  else
    Error "模版文件不存在 #{podspecTempPath}"
  end
end

.createModuleByName(name, projectPath) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/qcloudhive/module.rb', line 104

def HiveModule.createModuleByName(name, projectPath)
    if File.exist?(name)
      L.warn "#{name} 已经存在于当前目录下,生成新模块将会覆盖他"
    end
    g = Git.init(name)
    oaProject = CodeOA.createProject(name)
    originRemote = nil
    g.remotes.each { |r|
      if r.name == "origin"
        originRemote = r
      end
    }
    if originRemote != nil
      if originRemote.url == oaProject.http_url_to_repo
        L.warn "当前Git仓库已经有 remote origin 为 #{oaProject.http_url_to_repo}"
      else
        Error "当前仓库已经有remote 但是不是#{oaProject.http_url_to_repo}"
      end
    else
      g.add_remote("origin",oaProject.http_url_to_repo)
    end
    createLocalModule(name, name)
    g.push
    return oaProject
end


211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/qcloudhive/module.rb', line 211

def HiveModule.dislink(cmd, opts)
  name = GetOptValue(cmd, opts, :i_name)
  manifestProjcet = Config.manifest.moduleByName(name)
  if manifestProjcet == nil
    Error "您要dislink的模块#{name}不在改项目中"
  end
  realetivePath = manifestProjcet.path
  gitPath = Pathname(Config.projectRootDirectory).join(realetivePath).to_path
  if File.exist?(gitPath)
    tryRmGit?(gitPath)
  end
  Config.manifest.deleteModuleByName(name)
  Config.manifest.flushStorage
  FileUtils.rm_rf(gitPath)
end

.release(cmd, opts) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/qcloudhive/module.rb', line 130

def HiveModule.release(cmd, opts)
  rootPath = Dir.pwd
  path = Pathname(rootPath)
  podspec = nil
  path.entries.each { |entry|
    if (entry.extname == '.podspec' )
        podspec = entry
    end
  }
  if podspec == nil
    puts "当前目录下没有Podspec文件,请在有Podspec文件的目录下进行该操作"
    exit(1)
  end
  spec = Pod::Specification.from_file(podspec)
  version = spec.version.version
  git = Git.open(rootPath)

  versionExsit = false

  git.tags.each { |t|
    if t.name == version
      versionExsit = true
      break
    end
  }

  if versionExsit
    git.delete_tag(version)
    git.push("origin", ":refs/tags/"+version)
  end
  git.add_tag(version)
  git.push("origin",version)
  specStorage = "oa-qcloud-terminal-qcloudpodspecs "
  Rake::sh " pod repo push #{specStorage} #{podspec} --allow-warnings"
  Rake::sh "cd ~/.cocoapods/repos/#{specStorage} \n"+
  '''
  git add .
  ''' +
  "git commit -m #{podspec}" +
  '''
  git pull
  git push
  '''
end

.tryRmGit?(gitPath) ⇒ Boolean

Returns:

  • (Boolean)


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/qcloudhive/module.rb', line 176

def HiveModule.tryRmGit?(gitPath)
  git = Git.open(gitPath)
  L.info "git is #{git}"
  if git == nil
    puts "您给的目录不是一个Git目录#{path}"
    exit(1)
  end
  remoteUrl = nil
  git.remotes.each { |r|
    if r.name == "origin"
      remoteUrl = r.url
    end
  }
  if remoteUrl == nil
    puts "您输入的Git目录没有设置远端地址#{path},您可能没没有提交的修改,暂不执行删除操作"
    exit(1)
  end
  if git.status.changed.count > 0
    puts "您输入的Git目录存在未提交的修改,暂不执行删除操作"
    exit(1)
  end
  if git.status.deleted.count > 0
    puts "您输入的Git目录存在未提交的修改,暂不执行删除操作"
    exit(1)
  end
  if git.status.added.count > 0
    puts "您输入的Git目录存在未提交的修改,暂不执行删除操作"
    exit(1)
  end
  if git.status.untracked.count > 0
    puts "您输入的Git目录存在未提交的修改,暂不执行删除操作"
    exit(1)
  end
  return true
end