Class: KZ::KZGlobalHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-kz/helpers/kz_global_helper.rb

Constant Summary collapse

@@instance =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKZGlobalHelper

Returns a new instance of KZGlobalHelper.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 57

def initialize
  @kz_pod_enable = false
  @specify_pod_mode = :kz_pod_origin_mode
  @pods_config_cache = {}
  @debug = false
  @kz_config_lock = {}
  @disable_generate_framework = false
  @generate_kz_pod_targets = false
  @olde_lock_file_content = nil
  @debug_shell_log_tag = "&> /dev/null"
  @arm64_simulator = false
end

Instance Attribute Details

#arm64_simulatorObject

Returns the value of attribute arm64_simulator.



53
54
55
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 53

def arm64_simulator
  @arm64_simulator
end

#debugObject

Returns the value of attribute debug.



48
49
50
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 48

def debug
  @debug
end

#debug_shell_log_tagObject

Returns the value of attribute debug_shell_log_tag.



52
53
54
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 52

def debug_shell_log_tag
  @debug_shell_log_tag
end

#disable_generate_frameworkObject

Returns the value of attribute disable_generate_framework.



50
51
52
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 50

def disable_generate_framework
  @disable_generate_framework
end

#generate_kz_pod_targetsObject

Returns the value of attribute generate_kz_pod_targets.



51
52
53
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 51

def generate_kz_pod_targets
  @generate_kz_pod_targets
end

#kz_analyzerObject

Returns the value of attribute kz_analyzer.



44
45
46
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 44

def kz_analyzer
  @kz_analyzer
end

#kz_config_lockObject

Returns the value of attribute kz_config_lock.



49
50
51
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 49

def kz_config_lock
  @kz_config_lock
end

#kz_generatorObject

Returns the value of attribute kz_generator.



45
46
47
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 45

def kz_generator
  @kz_generator
end

#kz_pod_configObject

Returns the value of attribute kz_pod_config.



43
44
45
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 43

def kz_pod_config
  @kz_pod_config
end

#kz_pod_enableObject

Returns the value of attribute kz_pod_enable.



42
43
44
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 42

def kz_pod_enable
  @kz_pod_enable
end

#specify_pod_modeObject

Returns the value of attribute specify_pod_mode.



47
48
49
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 47

def specify_pod_mode
  @specify_pod_mode
end

#specify_pod_namesObject

Returns the value of attribute specify_pod_names.



46
47
48
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 46

def specify_pod_names
  @specify_pod_names
end

Class Method Details

.instanceObject



78
79
80
81
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 78

def self.instance
  FileUtils.mkdir_p(KZ_POD_CONFIG_ROOT) unless File.exist?(KZ_POD_CONFIG_ROOT)
  @@instance ||= new
end

Instance Method Details

#analyze_special_parameters(use_code_tag, use_framework_tag, pod_names) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 115

def analyze_special_parameters(use_code_tag, use_framework_tag, pod_names)
  specify_pod_names = []
  if pod_names.count > 0
    pod_names.each do |param|
      if param.include?(',')
        specify_pod_names.concat(param.split(","))
      else
        specify_pod_names << param
      end
    end
  end
  @specify_pod_names = specify_pod_names
  if use_code_tag
    @specify_pod_mode = :kz_pod_code_mode
  elsif use_framework_tag
    @specify_pod_mode = :kz_pod_framework_mode
  end
end

#have_flexLib_pod_targetObject



146
147
148
149
150
151
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 146

def have_flexLib_pod_target
  @kz_analyzer.all_kz_pod_targets.values.each do |target|
    return true if target.root_name == 'FlexLib' || target.root_name == 'KZSwiftUI'
  end
  false
end

#olde_lock_file_contentObject



174
175
176
177
178
179
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 174

def olde_lock_file_content
  if File.exist?(KZ_LOCK_FILE_PATH)
    @olde_lock_file_content ||= JSON.parse(File.read(KZ_LOCK_FILE_PATH))
  end
  @olde_lock_file_content
end

#pod_config_result_with_target(kz_pod_target) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 134

def pod_config_result_with_target(kz_pod_target)
  return nil unless @kz_pod_enable
  return nil unless kz_pod_target && kz_pod_target.config_pod_mode == :kz_pod_framework_mode

  return @pods_config_cache[kz_pod_target.name] if @pods_config_cache.has_key?(kz_pod_target.name)

  result = KZFrameworkManager.validate_framework_and_get_result(kz_pod_target)

  @pods_config_cache[kz_pod_target.name] = result if result
  result
end

#prepareObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 83

def prepare
  if Pod::Config.instance.podfile && Pod::Config.instance.podfile.plugins.has_key?("cocoapods-kz")
    if olde_lock_file_content == nil || olde_lock_file_content['version'] != KZ_POD_CONFIG_VERSION
      FileUtils.rm_rf(KZ_POD_CONFIG_ROOT)
      FileUtils.mkdir_p(KZ_POD_CONFIG_ROOT)
    end
    FileUtils.mkdir_p(KZ_POD_CONFIG_SUPPORT_FILES) unless File.exist?(KZ_POD_CONFIG_SUPPORT_FILES)
    FileUtils.mkdir_p(KZ_POD_CONFIG_POD_TARGETS) unless File.exist?(KZ_POD_CONFIG_POD_TARGETS)
    FileUtils.mkdir_p(KZ_POD_CONFIG_POD_TEMPDIR) unless File.exist?(KZ_POD_CONFIG_POD_TEMPDIR)

    FileUtils.rm(FLEX_COMPLIER_PATH) if File.exist?(FLEX_COMPLIER_PATH)
    FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler', FLEX_COMPLIER_PATH)
    system("chmod +x #{FLEX_COMPLIER_PATH}")

    FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_generator_framework.sh', KZ_GENERATOR_FRAMEWORK_PATH)
    system("chmod +x #{KZ_GENERATOR_FRAMEWORK_PATH}")

    FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_xml_build.sh', KZ_XML_BUILD_PATH)
    system("chmod +x #{KZ_XML_BUILD_PATH}")

    FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_fix_force_load_exe.sh', KZ_FIX_FORCE_LOAD_EXE)
    system("chmod +x #{KZ_FIX_FORCE_LOAD_EXE}")

    FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_refresh_pods_pbxproj.rb', KZ_FEFRESH_PODS_PBXPROJ)

    Pod::Config.instance.podfile.use_frameworks!(:linkage => :static)
  else
    @kz_pod_enable = false
    @generate_kz_pod_targets = false
  end
end

#write_lock_fileObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/cocoapods-kz/helpers/kz_global_helper.rb', line 153

def write_lock_file
  self.kz_analyzer.all_kz_pod_targets.values.each do |kz_pod_target|
    result = pod_config_result_with_target(kz_pod_target)

    @kz_config_lock['version'] = KZ_POD_CONFIG_VERSION
    @kz_config_lock['pod_targets'] ||= {}

    @kz_config_lock['pod_targets'][kz_pod_target.name] ||= {}
    @kz_config_lock['pod_targets'][kz_pod_target.name]["dev_pod"] = kz_pod_target.is_dev_pod
    @kz_config_lock['pod_targets'][kz_pod_target.name]["use_framework"] = (result != nil)
    @kz_config_lock['pod_targets'][kz_pod_target.name]["version"] = kz_pod_target.version
  end

  if @kz_config_lock.count > 0
    lock_file_content = JSON.pretty_generate(@kz_config_lock)
    File.open(KZ_LOCK_FILE_PATH, 'w') do |file|
      file.write(lock_file_content)
    end
  end
end