Class: Tuya::PodSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/tycli/repo/spec.rb

Class Method Summary collapse

Class Method Details

.ask_pod_specObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tycli/repo/spec.rb', line 14

def self.ask_pod_spec

  files = podspec_files(nil)

  answer = ""

  if files.size == 1
    answer = files[0]
  elsif files.size > 1
    require 'tycli/util/ask'

    podspecs = Array.new
    files.each do |podspec_path|
      podspecs.push File.basename(podspec_path)
    end

    require 'tuya/ci/core'
    answer = TYCiCore::TYAsk.ask_with_answers("which podspec will be pushed", podspecs)
  end

  answer

end

.local_pod_version_exist(version, spec, lib_name) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/tycli/repo/spec.rb', line 4

def self.local_pod_version_exist(version, spec, lib_name)

  require 'tycli/system'

  system = Tuya::System.instance
  local_path = system.pod_config.repos_dir + spec + lib_name + version

  File.directory?(local_path)
end

.pod_spec_version(podspec) ⇒ Object



38
39
40
41
42
# File 'lib/tycli/repo/spec.rb', line 38

def self.pod_spec_version(podspec)
  content = File.read("./#{podspec}")
  version = (content.match(/s.version[\s]*=[\s]*'([\d]+.){2}[\d]+'/)[0]).match(/([\d]+.){2}[\d]+/)[0]
  version.gsub(/(\d+)$/, ((version.split(".")[-1]).to_i + 1).to_s)
end

.podspec_files(podspec) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tycli/repo/spec.rb', line 88

def self.podspec_files(podspec)
  if podspec
    path = Pathname(podspec)
    raise Informative, "Couldn't find #{podspec}" unless path.exist?
    [path]
  else
    files = Pathname.glob('*.podspec{,.json}')
    # raise Informative, "Couldn't find any podspec files in current directory" if files.empty?
    puts "Couldn't find any podspec files in current directory".red if files.empty?
    files
  end
end

.repair_lib_spec(path, file, config) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tycli/repo/spec.rb', line 70

def self.repair_lib_spec(path, file, config)

  podspec = "#{path}/#{file}"

  if File.exist? podspec
    spec_content = File.read(podspec)
    spec_content = repair_source(spec_content, config.url)

    fh = File.new(podspec, "w")
    fh.puts spec_content
    fh.close
  end
end

.repair_source(podspec, git_url) ⇒ Object



84
85
86
# File 'lib/tycli/repo/spec.rb', line 84

def self.repair_source(podspec, git_url)
  podspec.gsub!(/:git => (.*),/, ":git => '#{git_url}',")
end

.update(podspec, version) ⇒ Object



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
# File 'lib/tycli/repo/spec.rb', line 44

def self.update(podspec, version)

  result = Array.new

  files = podspec_files(podspec)

  files.each do |podspec_path|

    spec_content = File.read(podspec_path)

    res = spec_content.scan(/.version\s*=\s*'#{version}'/)

    if res.size == 0
      spec_content.gsub!(/s.version\s*=(.*?)'$/, "s.version          = '#{version}'")

      fh = File.new(podspec_path, "w")
      fh.puts spec_content
      fh.close

      result.push(podspec_path)
    end

    result
  end
end