Class: BB::PodUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb

Class Method Summary collapse

Class Method Details

.compare_xcode_14_versionObject

xcode14以上,14以后不再支持armv7(32位设备)



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 104

def self.compare_xcode_14_version
    current_version = xcode_version
    if current_version.nil?
        puts "未找到安装的Xcode版本。".red
    else
        puts "当前Xcode版本:#{current_version}"
        num_ver = current_version.to_i
        return  num_ver >= 14
    end
    return false
end

.compare_xcode_15_versionObject

xcode15以上



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 116

def self.compare_xcode_15_version
    current_version = xcode_version
    if current_version.nil?
        puts "未找到安装的Xcode版本。".red
    else
        puts "当前Xcode版本:#{current_version}"
        num_ver = current_version.to_i
        return  num_ver >= 15
    end
    return false
end

.getInfoPlistPathObject

获取info配置文件路径

Raises:

  • (Informative)


74
75
76
77
78
79
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 74

def self.getInfoPlistPath
    path = File.join(getProjectPath, "bbframework/Resources/Info.plist")
    # puts "InfoPlist:#{path}"
    raise Informative,  "#{path} File no exist, please check" unless File.exist?(path)
    return path
end

.getProjectBundleIdentifierObject

获取包名



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 32

def self.getProjectBundleIdentifier
    projectBundleIdentifierKey = "PRODUCT_BUNDLE_IDENTIFIER"
    value = getValueFromInfoPlist(projectBundleIdentifierKey)
    if #{value} == #{projectBundleIdentifierKey}
        project = Xcodeproj::Project.open(getXcodeprojPath)
        project.targets.each do |target|
            target.build_configurations.each do |config|
                value = config.build_settings['PRODUCT_BUNDLE_IDENTIFIER']
                if value && !value.empty?
                    break
                end
            end
            
            if value && !value.empty?
                break
            end
        end
        puts "xcodeproj BundleIdentifier:#{value}"
        return value
    else
        puts "info BundleIdentifier:#{value}"
        return value
    end
end

.getProjectDevelopmentTeamObject

证书团队id



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 57

def self.getProjectDevelopmentTeam
    value = ""
    project = Xcodeproj::Project.open(getXcodeprojPath)
    project.targets.each do |target|
    target.build_configurations.each do |config|
        value = config.build_settings['DEVELOPMENT_TEAM']
        
        if value && !value.empty?
            # 做你的处理
            break
        end
    end
    end
    puts "xcodeproj DevelopmentTeam:#{value}"
    return value
end

.getProjectPathObject

获取工程路径

Raises:

  • (Informative)


17
18
19
20
21
22
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 17

def self.getProjectPath
    path = Dir.pwd
    # puts "Project Path:#{path}".yellow
    raise Informative,  "#{path} File no exist, please check" unless File.exist?(path)
    return path
end

.getProjectRootPathObject

获取工程根目录路径

Raises:

  • (Informative)


10
11
12
13
14
15
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 10

def self.getProjectRootPath
    path = File.expand_path("..", getProjectPath)
    # puts "Project Root Path:#{path}".red
    raise Informative,  "#{path} File no exist, please check" unless File.exist?(path)
    return path
end

.getValueFromInfoPlist(key) ⇒ Object

获取info配置key对应的值



81
82
83
84
85
86
87
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 81

def self.getValueFromInfoPlist(key)
    plistPath = getInfoPlistPath
    value = `/usr/libexec/PlistBuddy -c "Print #{key}" #{plistPath}`
    value = value.rstrip()
    puts "#{key} => #{value}"
    return value
end

.getXcodeprojPathObject

xcode目录

Raises:

  • (Informative)


24
25
26
27
28
29
30
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 24

def self.getXcodeprojPath
    name = Dir.glob("*.xcodeproj")[0]
    path = File.join(getProjectPath, name)
    # puts "xcodeproj:#{path}"
    raise Informative,  "#{path} File no exist, please check" unless File.exist?(path)
    return path
end

.xcode_versionObject

获取Xcode版本



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 89

def self.xcode_version
    xcode_version_output = `xcode-select -p`
    return nil if xcode_version_output.empty?
    
    xcode_path = xcode_version_output.chomp
    version_output = `xcodebuild -version`
    
    # Extract the Xcode version number
    version_match = version_output.match(/Xcode (\d+(\.\d+)+)/)
    return nil if version_match.nil?
    
    xcode_version = version_match[1]
    return xcode_version
end