cocoapods-mPaaS 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/cocoapods-mPaaS/baselineTools.rb +493 -0
- data/lib/cocoapods-mPaaS/checkUpdateTools.rb +42 -0
- data/lib/cocoapods-mPaaS/cocoapods_hook.rb +929 -0
- data/lib/cocoapods-mPaaS/command/mPaaS.rb +44 -0
- data/lib/cocoapods-mPaaS/command/mpaas/dev.rb +17 -0
- data/lib/cocoapods-mPaaS/command/mpaas/info.rb +170 -0
- data/lib/cocoapods-mPaaS/command/mpaas/init.rb +112 -0
- data/lib/cocoapods-mPaaS/command/mpaas/local_command.rb +49 -0
- data/lib/cocoapods-mPaaS/command/mpaas/open.rb +17 -0
- data/lib/cocoapods-mPaaS/command/mpaas/update.rb +223 -0
- data/lib/cocoapods-mPaaS/command/mpaas/version.rb +32 -0
- data/lib/cocoapods-mPaaS/command.rb +1 -0
- data/lib/cocoapods-mPaaS/dsl.rb +498 -0
- data/lib/cocoapods-mPaaS/gem_version.rb +5 -0
- data/lib/cocoapods-mPaaS/installNew.rb +303 -0
- data/lib/cocoapods-mPaaS/locales/en.yml +140 -0
- data/lib/cocoapods-mPaaS/locales/zh-Hans.yml +144 -0
- data/lib/cocoapods-mPaaS/localization.rb +238 -0
- data/lib/cocoapods-mPaaS/logTools.rb +67 -0
- data/lib/cocoapods-mPaaS/mPaaSPodfile.rb +117 -0
- data/lib/cocoapods-mPaaS/module_config.rb +298 -0
- data/lib/cocoapods-mPaaS/podfileTools.rb +48 -0
- data/lib/cocoapods-mPaaS/post_install_hook_processor.rb +61 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/DemoViewController.h +13 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/DemoViewController.m +43 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/Contents.json +6 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery.imageset/TabBar_Discovery@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery.imageset/TabBar_Discovery@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery_Sel.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery_Sel.imageset/TabBar_Discovery_Sel@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery_Sel.imageset/TabBar_Discovery_Sel@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends.imageset/TabBar_Friends@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends.imageset/TabBar_Friends@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends_Sel.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends_Sel.imageset/TabBar_Friends_Sel@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends_Sel.imageset/TabBar_Friends_Sel@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar.imageset/icon30-line@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar.imageset/icon30-line@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar_Sel.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar_Sel.imageset/icon30@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar_Sel.imageset/icon30@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService.imageset/TabBar_PublicService@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService.imageset/TabBar_PublicService@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService_Sel.imageset/Contents.json +22 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService_Sel.imageset/TabBar_PublicService_Sel@2x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService_Sel.imageset/TabBar_PublicService_Sel@3x.png +0 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPAppDelegate.h +10 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPAppDelegate.m +43 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerController.h +8 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerController.m +135 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLauncherAppDelegate.h +10 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLauncherAppDelegate.m +43 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLeftView.h +16 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLeftView.m +86 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerMainViewController.h +21 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerMainViewController.m +104 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPLauncherAppDelegate.h +10 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPLauncherAppDelegate.m +91 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationController.h +8 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationController.m +25 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationLauncherAppDelegate.h +10 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationLauncherAppDelegate.m +43 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPTabBarController.h +8 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPTabBarController.m +27 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPViewController.h +8 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPViewController.m +19 -0
- data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MobileRuntime.plist +26 -0
- data/lib/cocoapods-mPaaS/write_info_list_mPaaSApp.rb +125 -0
- data/lib/cocoapods-mPaaS/xcode_helper.rb +334 -0
- data/lib/cocoapods-mPaaS.rb +41 -0
- data/lib/cocoapods_plugin.rb +15 -0
- metadata +160 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'pathname'
|
|
3
|
+
require 'fileutils' # 用于创建目录
|
|
4
|
+
|
|
5
|
+
module Pod
|
|
6
|
+
module MPAAS
|
|
7
|
+
module Localization
|
|
8
|
+
@translations = {}
|
|
9
|
+
@current_language = nil
|
|
10
|
+
@fallback_language = 'en' # 默认回退语言
|
|
11
|
+
|
|
12
|
+
# 用于控制内部调试日志的开关,通过环境变量 MPAAS_DEBUG_LOGS=true 开启
|
|
13
|
+
def self.internal_verbose?
|
|
14
|
+
ENV['MPAAS_DEBUG_LOGS'] == 'true'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# 定义配置文件的路径
|
|
18
|
+
def self.config_file_path
|
|
19
|
+
Pathname.new(Dir.home) + '.cocoapods' + 'mpaas_config.yml'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# 加载配置
|
|
23
|
+
def self.load_config
|
|
24
|
+
path = config_file_path
|
|
25
|
+
if path.exist?
|
|
26
|
+
begin
|
|
27
|
+
config_data = YAML.load_file(path.to_s) || {}
|
|
28
|
+
# 内部调试信息,使用 Ruby puts
|
|
29
|
+
puts "MPAAS (Internal): Loaded config from '#{path}'." if internal_verbose?
|
|
30
|
+
config_data
|
|
31
|
+
rescue Psych::SyntaxError => e
|
|
32
|
+
# 用户可见的警告信息,使用防御性写法
|
|
33
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: Failed to parse config file '#{path}': #{e.message}. Using default settings."
|
|
34
|
+
{}
|
|
35
|
+
end
|
|
36
|
+
else
|
|
37
|
+
puts "MPAAS (Internal): Config file not found at '#{path}'." if internal_verbose?
|
|
38
|
+
{}
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# 保存配置
|
|
43
|
+
def self.save_config(config_data)
|
|
44
|
+
path = config_file_path
|
|
45
|
+
FileUtils.mkdir_p(path.dirname) unless path.dirname.exist? # 确保目录存在
|
|
46
|
+
File.write(path.to_s, config_data.to_yaml)
|
|
47
|
+
puts "MPAAS (Internal): Saved config to '#{path}'." if internal_verbose?
|
|
48
|
+
rescue => e
|
|
49
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: Failed to save config to '#{path}': #{e.message}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# -------------------------------------------------------------
|
|
53
|
+
# 语言检测和映射
|
|
54
|
+
# -------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
# 尝试获取并规范化系统语言
|
|
57
|
+
def self.detect_system_language
|
|
58
|
+
# Use debug logs for tracing language detection
|
|
59
|
+
puts "find_language_detect: --- Entering detect_system_language method ---" if internal_verbose?
|
|
60
|
+
|
|
61
|
+
lang_env = ENV['LANG'] || ENV['LC_ALL'] || ENV['LANGUAGE']
|
|
62
|
+
puts "find_language_detect: Raw language environment variable: '#{lang_env}'" if internal_verbose?
|
|
63
|
+
|
|
64
|
+
if lang_env
|
|
65
|
+
base_lang = lang_env.split('.').first.split('_').first.downcase
|
|
66
|
+
puts "find_language_detect: Detected base language: '#{base_lang}'" if internal_verbose?
|
|
67
|
+
|
|
68
|
+
case base_lang
|
|
69
|
+
when 'zh'
|
|
70
|
+
lang_region = lang_env.split('.').first.split('_').last.downcase
|
|
71
|
+
puts "find_language_detect: Detected Chinese region: '#{lang_region}'" if internal_verbose?
|
|
72
|
+
|
|
73
|
+
# Explicitly choose Simplified Chinese
|
|
74
|
+
if ['cn', 'hans', 'tw', 'hk', 'hant'].include?(lang_region) # Treat all Chinese variants as Simplified Chinese for now
|
|
75
|
+
puts "find_language_detect: Normalized Chinese to 'zh-Hans'." if internal_verbose?
|
|
76
|
+
'zh-Hans'
|
|
77
|
+
else
|
|
78
|
+
puts "find_language_detect: Unrecognized Chinese region, defaulting to 'zh-Hans'." if internal_verbose?
|
|
79
|
+
'zh-Hans' # Default all other Chinese to Simplified Chinese
|
|
80
|
+
end
|
|
81
|
+
when 'en'
|
|
82
|
+
puts "find_language_detect: Detected English: 'en'." if internal_verbose?
|
|
83
|
+
'en'
|
|
84
|
+
else
|
|
85
|
+
# If the detected base language is neither 'zh' nor 'en', default to 'en'
|
|
86
|
+
puts "find_language_detect: Unsupported base language '#{base_lang}', defaulting to 'en'." if internal_verbose?
|
|
87
|
+
'en'
|
|
88
|
+
end
|
|
89
|
+
else
|
|
90
|
+
# If no language environment variable is found, default to 'en'
|
|
91
|
+
puts "find_language_detect: No language environment variable found, defaulting to 'en'." if internal_verbose?
|
|
92
|
+
'en'
|
|
93
|
+
end
|
|
94
|
+
ensure
|
|
95
|
+
puts "find_language_detect: --- Exiting detect_system_language method ---" if internal_verbose?
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# -------------------------------------------------------------
|
|
99
|
+
# 以下是语言加载和设置逻辑
|
|
100
|
+
# -------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
def self.load_translations(language_code)
|
|
103
|
+
return if @translations[language_code]
|
|
104
|
+
|
|
105
|
+
locales_dir = Pathname.new(__FILE__).dirname + 'locales'
|
|
106
|
+
file_path = locales_dir + "#{language_code}.yml"
|
|
107
|
+
|
|
108
|
+
if file_path.exist?
|
|
109
|
+
begin
|
|
110
|
+
@translations[language_code] = YAML.load_file(file_path.to_s)
|
|
111
|
+
puts "MPAAS (Internal): Loaded translations for '#{language_code}'." if internal_verbose?
|
|
112
|
+
rescue Psych::SyntaxError => e
|
|
113
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: Failed to parse locale file '#{file_path}': #{e.message}"
|
|
114
|
+
@translations[language_code] = {}
|
|
115
|
+
end
|
|
116
|
+
else
|
|
117
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: No locale file found for '#{language_code}' at '#{file_path}'."
|
|
118
|
+
@translations[language_code] = {}
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def self.set_language(language_code)
|
|
123
|
+
normalized_language = language_code.to_s
|
|
124
|
+
|
|
125
|
+
if @translations[normalized_language].nil?
|
|
126
|
+
load_translations(normalized_language)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
if @translations[normalized_language].nil? || @translations[normalized_language][normalized_language].nil?
|
|
130
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: Language '#{language_code}' not fully supported, falling back to '#{@fallback_language}'."
|
|
131
|
+
load_translations(@fallback_language) unless @translations[@fallback_language]
|
|
132
|
+
@current_language = @fallback_language
|
|
133
|
+
else
|
|
134
|
+
@current_language = normalized_language
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
config = load_config
|
|
138
|
+
config['language'] = @current_language
|
|
139
|
+
save_config(config)
|
|
140
|
+
|
|
141
|
+
# 这里的日志可以根据需要决定是否也使用 internal_verbose?
|
|
142
|
+
# 如果你希望用户在 --verbose 模式下也能看到这个确认信息,那就用 Pod::UI.puts
|
|
143
|
+
# 否则就用 puts internal_verbose?
|
|
144
|
+
# 这里我暂时保持为 internal_verbose?
|
|
145
|
+
puts "MPAAS (Internal): Current plugin language set to '#{@current_language}'." if internal_verbose?
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def self.current_language
|
|
149
|
+
return @current_language if @current_language
|
|
150
|
+
|
|
151
|
+
config = load_config
|
|
152
|
+
saved_language = config['language']
|
|
153
|
+
return saved_language if saved_language && !saved_language.empty?
|
|
154
|
+
|
|
155
|
+
system_language = detect_system_language
|
|
156
|
+
return system_language if system_language
|
|
157
|
+
|
|
158
|
+
@fallback_language
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# 查找本地化字符串的核心方法
|
|
162
|
+
def self.t(key, **options)
|
|
163
|
+
puts "find_language_path: --- 进入 t 方法 ---" if internal_verbose?
|
|
164
|
+
puts "find_language_path: 接收到的键 (key): '#{key}'" if internal_verbose?
|
|
165
|
+
puts "find_language_path: 接收到的选项 (options): #{options.inspect}" if internal_verbose?
|
|
166
|
+
|
|
167
|
+
path_elements = key.to_s.split('.')
|
|
168
|
+
puts "find_language_path: 从键中解析出的路径元素: #{path_elements.inspect}" if internal_verbose?
|
|
169
|
+
|
|
170
|
+
actual_current_lang = current_language
|
|
171
|
+
puts "find_language_path: 确定的实际当前语言: '#{actual_current_lang}'" if internal_verbose?
|
|
172
|
+
|
|
173
|
+
# 获取当前语言或回退语言的原始已加载翻译数据
|
|
174
|
+
loaded_translations_for_lang = @translations[actual_current_lang]
|
|
175
|
+
if loaded_translations_for_lang.nil? # 如果当前语言未加载,尝试回退语言
|
|
176
|
+
puts "find_language_path: '#{actual_current_lang}' 的翻译未直接加载。尝试回退语言。" if internal_verbose?
|
|
177
|
+
loaded_translations_for_lang = @translations[@fallback_language]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# --- 关键修复在这里 ---
|
|
181
|
+
# 'en:' 或 'zh-Hans:' 这样的键是加载的 YAML 文件的根。
|
|
182
|
+
# 我们需要进入这个键内部,才能获取实际用于查找的内容。
|
|
183
|
+
if loaded_translations_for_lang.is_a?(Hash) && loaded_translations_for_lang.key?(actual_current_lang)
|
|
184
|
+
current_hash = loaded_translations_for_lang[actual_current_lang]
|
|
185
|
+
puts "find_language_path: 初始查找哈希设置为 '#{actual_current_lang}' 键的内容: #{current_hash.inspect[0..100]}..." if internal_verbose?
|
|
186
|
+
elsif loaded_translations_for_lang.is_a?(Hash) && loaded_translations_for_lang.key?(@fallback_language) && actual_current_lang != @fallback_language # 如果使用了回退语言且它也有自己的根键
|
|
187
|
+
current_hash = loaded_translations_for_lang[@fallback_language]
|
|
188
|
+
puts "find_language_path: 初始查找哈希设置为回退语言 '#{@fallback_language}' 键的内容: #{current_hash.inspect[0..100]}..." if internal_verbose?
|
|
189
|
+
else # 如果无论如何都找不到有效的根语言键
|
|
190
|
+
puts "find_language_path: !!! 错误: 在加载的翻译中,找不到 '#{actual_current_lang}' 或回退语言的有效根语言键。" if internal_verbose?
|
|
191
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: 在加载的翻译中,找不到 '#{key}' 的有效根语言键。"
|
|
192
|
+
return "MISSING_TRANSLATION_ROOT_#{key}" # 添加一个更明确的错误提示
|
|
193
|
+
end
|
|
194
|
+
# --- 关键修复结束 ---
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
path_elements.each_with_index do |elem, index|
|
|
198
|
+
puts "find_language_path: 级别 #{index + 1}: 查找元素 '#{elem}'" if internal_verbose?
|
|
199
|
+
if current_hash.is_a?(Hash) && current_hash.key?(elem)
|
|
200
|
+
current_hash = current_hash[elem]
|
|
201
|
+
puts "find_language_path: 找到元素 '#{elem}'。当前哈希/值: #{current_hash.inspect[0..100]}..." if internal_verbose?
|
|
202
|
+
else
|
|
203
|
+
# 调试输出:找不到键时的详细信息
|
|
204
|
+
puts "find_language_path: !!! 错误: 在此级别未找到键元素 '#{elem}'。" if internal_verbose?
|
|
205
|
+
puts "find_language_path: !!! 查找失败时的当前哈希: #{current_hash.inspect}" if internal_verbose?
|
|
206
|
+
puts "find_language_path: !!! 完整的键查找路径: '#{key}'" if internal_verbose?
|
|
207
|
+
|
|
208
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: 语言 '#{actual_current_lang}' 缺少翻译键 '#{key}'。"
|
|
209
|
+
return "MISSING_TRANSLATION_#{key}"
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# 调试输出:最终找到的值
|
|
214
|
+
puts "find_language_path: 为键 '#{key}' 找到的最终值: #{current_hash.inspect}" if internal_verbose?
|
|
215
|
+
|
|
216
|
+
if current_hash.is_a?(String)
|
|
217
|
+
begin
|
|
218
|
+
result = sprintf(current_hash, options)
|
|
219
|
+
puts "find_language_path: 成功插值字符串: '#{result}'" if internal_verbose?
|
|
220
|
+
result
|
|
221
|
+
rescue ArgumentError => e
|
|
222
|
+
# 调试输出:sprintf 错误
|
|
223
|
+
puts "find_language_path: !!! 错误: 键 '#{key}' 的 sprintf 插值失败。错误: #{e.message}" if internal_verbose?
|
|
224
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: 翻译 '#{key}' 的插值失败。错误: #{e.message}"
|
|
225
|
+
current_hash # 返回原始字符串,作为备用
|
|
226
|
+
end
|
|
227
|
+
else
|
|
228
|
+
# 调试输出:翻译类型错误
|
|
229
|
+
puts "find_language_path: !!! 错误: 键 '#{key}' 的翻译不是字符串。类型: #{current_hash.class}" if internal_verbose?
|
|
230
|
+
(defined?(Pod::UI) ? Pod::UI : Kernel).warn "MPAAS: 翻译 '#{key}' 不是字符串。"
|
|
231
|
+
"INVALID_TRANSLATION_TYPE_#{key}"
|
|
232
|
+
end
|
|
233
|
+
ensure
|
|
234
|
+
puts "find_language_path: --- 退出 t 方法 ---" if internal_verbose?
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module LogTools
|
|
2
|
+
class << self
|
|
3
|
+
include Pod::Config::Mixin
|
|
4
|
+
|
|
5
|
+
# 默认都输出
|
|
6
|
+
def p(message)
|
|
7
|
+
p_(message, "", "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def p_green(message)
|
|
11
|
+
p_(message, "", "g")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def p_red(message)
|
|
15
|
+
p_(message, "", "r")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def p_yellow(message)
|
|
19
|
+
p_(message, "", "y")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# 只有verbose下才输出
|
|
23
|
+
def v(message)
|
|
24
|
+
p_(message, "v", "")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def v_green(message)
|
|
28
|
+
p_(message, "v", "g")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def v_red(message)
|
|
32
|
+
p_(message, "v", "r")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def v_yellow(message)
|
|
36
|
+
p_(message, "v", "y")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def verbose?
|
|
40
|
+
return config.verbose?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def p_(messages, mode, color)
|
|
46
|
+
if mode == "v"
|
|
47
|
+
if config.verbose?
|
|
48
|
+
p_color(messages, color)
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
p_color(messages, color)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def p_color(messages, color)
|
|
56
|
+
if color == "g"
|
|
57
|
+
Pod::UI.puts messages.green
|
|
58
|
+
elsif color == "r"
|
|
59
|
+
Pod::UI.puts messages.red
|
|
60
|
+
elsif color == "y"
|
|
61
|
+
Pod::UI.puts messages.yellow
|
|
62
|
+
else
|
|
63
|
+
Pod::UI.puts messages
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
require 'cocoapods-mPaaS/localization'
|
|
2
|
+
class MPaaSPodfile
|
|
3
|
+
attr_accessor :mPaaSPodNames
|
|
4
|
+
attr_accessor :mPaaSBaseline
|
|
5
|
+
attr_accessor :mPaaSPodVersion
|
|
6
|
+
attr_accessor :mPaaSVersionCode
|
|
7
|
+
attr_accessor :localComponentJsonPath
|
|
8
|
+
attr_accessor :localContentJsonPath
|
|
9
|
+
attr_accessor :localContentJsonFallback
|
|
10
|
+
attr_accessor :mpaasRepoUrl
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
self.mPaaSPodNames = []
|
|
14
|
+
self.mPaaSBaseline = nil
|
|
15
|
+
self.mPaaSPodVersion = nil
|
|
16
|
+
self.mPaaSVersionCode = nil
|
|
17
|
+
self.localComponentJsonPath = nil
|
|
18
|
+
self.localContentJsonPath = nil
|
|
19
|
+
self.localContentJsonFallback = false
|
|
20
|
+
self.mpaasRepoUrl = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def mPaaS_pod(name, version_str = nil)
|
|
24
|
+
self.mPaaSPodNames << name
|
|
25
|
+
self.mPaaSPodVersion ||= version_str if version_str
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def mPaaS_baseline(baseline)
|
|
29
|
+
self.mPaaSBaseline = baseline
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def mPaaS_version_code(version_code)
|
|
33
|
+
self.mPaaSVersionCode = version_code
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def mPaaS_local_component_json(path)
|
|
37
|
+
self.localComponentJsonPath = path
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def mPaaS_local_content_json(path, fallback = false)
|
|
41
|
+
self.localContentJsonPath = path
|
|
42
|
+
self.localContentJsonFallback = fallback
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def mPaaS_repo_url(url)
|
|
46
|
+
self.mpaasRepoUrl = url
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def run(path)
|
|
50
|
+
LogTools.v "MPaaSPodfile Parsing (Regex mode): #{path}"
|
|
51
|
+
|
|
52
|
+
proxy_evaluator = Object.new
|
|
53
|
+
proxy_evaluator.instance_variable_set(:@mpaas_parser_instance, self)
|
|
54
|
+
|
|
55
|
+
proxy_evaluator.define_singleton_method(:mPaaS_pod) do |name, *version|
|
|
56
|
+
@mpaas_parser_instance.mPaaS_pod(name, version.first)
|
|
57
|
+
end
|
|
58
|
+
proxy_evaluator.define_singleton_method(:mPaaS_baseline) do |baseline|
|
|
59
|
+
@mpaas_parser_instance.mPaaS_baseline(baseline)
|
|
60
|
+
end
|
|
61
|
+
proxy_evaluator.define_singleton_method(:mPaaS_version_code) do |version_code|
|
|
62
|
+
@mpaas_parser_instance.mPaaS_version_code(version_code)
|
|
63
|
+
end
|
|
64
|
+
proxy_evaluator.define_singleton_method(:mPaaS_local_component_json) do |path|
|
|
65
|
+
@mpaas_parser_instance.mPaaS_local_component_json(path)
|
|
66
|
+
end
|
|
67
|
+
proxy_evaluator.define_singleton_method(:mPaaS_local_content_json) do |path, fallback = false|
|
|
68
|
+
@mpaas_parser_instance.mPaaS_local_content_json(path, fallback)
|
|
69
|
+
end
|
|
70
|
+
proxy_evaluator.define_singleton_method(:mPaaS_repo_url) do |url|
|
|
71
|
+
@mpaas_parser_instance.mPaaS_repo_url(url)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
mpaas_pod_regex = /^\s*mPaaS_pod\s+['"]([^'"]+)['"](?:\s*,\s*['"]([^'"]+)['"])?\s*(?:#.*)?\s*$/
|
|
75
|
+
mpaas_baseline_regex = /^\s*mPaaS_baseline\s+['"]([^'"]+)['"]\s*(?:#.*)?\s*$/
|
|
76
|
+
mpaas_version_code_regex = /^\s*mPaaS_version_code\s+(\d+)\s*(?:#.*)?\s*$/
|
|
77
|
+
mpaas_local_component_regex = /^\s*mPaaS_local_component_json\s+['"]([^'"]+)['"]\s*(?:#.*)?\s*$/
|
|
78
|
+
mpaas_local_content_regex = /^\s*mPaaS_local_content_json\s+['"]([^'"]+)['"](?:\s*,\s*(true|false))?\s*(?:#.*)?\s*$/
|
|
79
|
+
mpaas_repo_url_regex = /^\s*mPaaS_repo_url\s+['"]([^'"]+)['"]\s*(?:#.*)?\s*$/
|
|
80
|
+
|
|
81
|
+
File.foreach(path) do |line|
|
|
82
|
+
if (match = line.match(mpaas_pod_regex))
|
|
83
|
+
pod_name = match[1]
|
|
84
|
+
pod_version = match[2]
|
|
85
|
+
proxy_evaluator.mPaaS_pod(pod_name, pod_version)
|
|
86
|
+
LogTools.v "Extracted mPaaS_pod: #{pod_name}, version: #{pod_version}"
|
|
87
|
+
elsif (match = line.match(mpaas_baseline_regex))
|
|
88
|
+
baseline = match[1]
|
|
89
|
+
proxy_evaluator.mPaaS_baseline(baseline)
|
|
90
|
+
LogTools.v "Extracted mPaaS_baseline: #{baseline}"
|
|
91
|
+
elsif (match = line.match(mpaas_version_code_regex))
|
|
92
|
+
version_code = match[1].to_i
|
|
93
|
+
proxy_evaluator.mPaaS_version_code(version_code)
|
|
94
|
+
LogTools.v "Extracted mPaaS_version_code: #{version_code}"
|
|
95
|
+
elsif (match = line.match(mpaas_local_component_regex))
|
|
96
|
+
proxy_evaluator.mPaaS_local_component_json(match[1])
|
|
97
|
+
LogTools.v "Extracted mPaaS_local_component_json: #{match[1]}"
|
|
98
|
+
elsif (match = line.match(mpaas_local_content_regex))
|
|
99
|
+
fallback = match[2] == 'true'
|
|
100
|
+
proxy_evaluator.mPaaS_local_content_json(match[1], fallback)
|
|
101
|
+
LogTools.v "Extracted mPaaS_local_content_json: #{match[1]}, fallback: #{fallback}"
|
|
102
|
+
elsif (match = line.match(mpaas_repo_url_regex))
|
|
103
|
+
proxy_evaluator.mPaaS_repo_url(match[1])
|
|
104
|
+
LogTools.v "Extracted mPaaS_repo_url: #{match[1]}"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
LogTools.v "Final mPaaSPodNames: #{self.mPaaSPodNames.inspect}"
|
|
109
|
+
LogTools.v "Final mPaaSBaseline: #{self.mPaaSBaseline}"
|
|
110
|
+
LogTools.v "Final mPaaSPodVersion: #{self.mPaaSPodVersion}"
|
|
111
|
+
LogTools.v "Final mPaaSVersionCode: #{self.mPaaSVersionCode}"
|
|
112
|
+
|
|
113
|
+
rescue Exception => e
|
|
114
|
+
LogTools.p_yellow Pod::MPAAS::Localization.t('mpaas.podfile.execute_error', message: e.message)
|
|
115
|
+
LogTools.p_yellow Pod::MPAAS::Localization.t('mpaas.podfile.error_stack_trace', backtrace: e.backtrace.join("\n"))
|
|
116
|
+
end
|
|
117
|
+
end
|