lhj-tools 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhj/command/head_import.rb +128 -0
- data/lib/lhj/command/init.rb +52 -0
- data/lib/lhj/command/local/fetch.rb +152 -0
- data/lib/lhj/command/local/filter.rb +82 -0
- data/lib/lhj/command/local/local.rb +264 -0
- data/lib/lhj/command/local/local_upload.rb +44 -0
- data/lib/lhj/command/local/micro_service.rb +87 -0
- data/lib/lhj/command/oss/del.rb +36 -0
- data/lib/lhj/command/oss/list.rb +19 -0
- data/lib/lhj/command/oss/upload.rb +58 -0
- data/lib/lhj/command/oss.rb +10 -0
- data/lib/lhj/command/refactor_rename.rb +77 -0
- data/lib/lhj/command/rename_image.rb +49 -7
- data/lib/lhj/command/reverse_import.rb +74 -0
- data/lib/lhj/command/template.rb +21 -0
- data/lib/lhj/command/trans.rb +48 -6
- data/lib/lhj/command/view.rb +27 -23
- data/lib/lhj/command/yapi.rb +32 -29
- data/lib/lhj/command.rb +14 -1
- data/lib/lhj/config.rb +2 -342
- data/lib/lhj/helper/local_config.rb +40 -0
- data/lib/lhj/helper/oss_config.rb +32 -0
- data/lib/lhj/helper/oss_helper.rb +43 -0
- data/lib/lhj/helper/trans_helper.rb +49 -0
- data/lib/lhj/tools/version.rb +1 -1
- data/lib/lhj/tools.rb +0 -1
- metadata +51 -15
- data/.github/workflows/main.yml +0 -16
- data/.gitignore +0 -12
- data/.idea/dictionaries +0 -6
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -10
- data/Gemfile.lock +0 -78
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -12
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lhj-tools.gemspec +0 -41
data/lib/lhj/command/yapi.rb
CHANGED
@@ -7,6 +7,7 @@ module Lhj
|
|
7
7
|
class Command
|
8
8
|
class Yapi < Command
|
9
9
|
self.summary = '通过yapi接口生成请求'
|
10
|
+
self.description = '更新 ~/.lhj/yapi.yml 文件配置后执行`lhj api`生成接口模型'
|
10
11
|
|
11
12
|
def self.options
|
12
13
|
[
|
@@ -43,8 +44,8 @@ module Lhj
|
|
43
44
|
def test_ding
|
44
45
|
require 'net/http'
|
45
46
|
require 'uri'
|
46
|
-
body = {
|
47
|
-
Net::HTTP.post(URI('https://oapi.dingtalk.com/robot/send?access_token=6a3519057170cdb1b7274edfe43934c84a0062ffe2c9bcced434699296a7e26e'), body,
|
47
|
+
body = { 'msgtype' => 'text', 'text' => { 'content' => 'error:上传蒲公英超时失败!' } }.to_json
|
48
|
+
Net::HTTP.post(URI('https://oapi.dingtalk.com/robot/send?access_token=6a3519057170cdb1b7274edfe43934c84a0062ffe2c9bcced434699296a7e26e'), body, 'Content-Type' => 'application/json')
|
48
49
|
end
|
49
50
|
|
50
51
|
def puts_h(str)
|
@@ -178,7 +179,8 @@ module Lhj
|
|
178
179
|
p_model = { name: p_name }
|
179
180
|
|
180
181
|
properties = []
|
181
|
-
|
182
|
+
case p_type
|
183
|
+
when 'object'
|
182
184
|
p_properties.each do |k, v|
|
183
185
|
c_type = @type_trans[v['type']] || v['type']
|
184
186
|
c_model = { key: k, type: c_type, description: v['description'], default: '' }
|
@@ -186,7 +188,7 @@ module Lhj
|
|
186
188
|
o = v['items'] || v
|
187
189
|
o['name'] = gen_model_name(k)
|
188
190
|
if v['type'].eql?('array') && v['items']['type'].eql?('string')
|
189
|
-
c_model[:type_name] =
|
191
|
+
c_model[:type_name] = 'NSString'
|
190
192
|
else
|
191
193
|
c_model[:type_name] = o['name']
|
192
194
|
handle_model(o)
|
@@ -196,7 +198,7 @@ module Lhj
|
|
196
198
|
end
|
197
199
|
p_model[:properties] = properties
|
198
200
|
@models << p_model
|
199
|
-
|
201
|
+
when 'array'
|
200
202
|
t = model['items']
|
201
203
|
t['name'] = p_name
|
202
204
|
handle_model(t)
|
@@ -220,9 +222,9 @@ module Lhj
|
|
220
222
|
puts_m "@implementation #{model[:name]}"
|
221
223
|
str = model[:properties].filter { |p| p[:type].eql?('array') && !p[:type_name].eql?('NSString') }.map { |p| "@\"#{p[:key]}\": #{p[:type_name]}.class" }.join(', ')
|
222
224
|
if str && str.length > 0
|
223
|
-
puts_m
|
225
|
+
puts_m '+(NSDictionary *)modelContainerPropertyGenericClass {'
|
224
226
|
puts_m " return @{#{str}};"
|
225
|
-
puts_m
|
227
|
+
puts_m '}'
|
226
228
|
end
|
227
229
|
puts_m "@end\n"
|
228
230
|
puts "\n\n"
|
@@ -237,27 +239,28 @@ module Lhj
|
|
237
239
|
des.gsub!(/\n/, ' ')
|
238
240
|
default = m[:default]
|
239
241
|
puts_h "///#{des} #{default}"
|
240
|
-
|
242
|
+
case type
|
243
|
+
when 'integer'
|
241
244
|
puts_h "@property (nonatomic, assign) NSInteger #{key};"
|
242
245
|
if des.include?('分')
|
243
|
-
puts_h
|
246
|
+
puts_h '/////////==========删掉其中一个属性'
|
244
247
|
puts_h "@property (nonatomic, strong) MLCentNumber *#{key};"
|
245
248
|
end
|
246
|
-
|
249
|
+
when 'cent'
|
247
250
|
puts_h "@property (nonatomic, strong) MLCentNumber *#{key};"
|
248
|
-
|
251
|
+
when 'string'
|
249
252
|
puts_h "@property (nonatomic, copy) NSString *#{key};"
|
250
|
-
|
253
|
+
when 'number'
|
251
254
|
puts_h "@property (nonatomic, strong) NSNumber *#{key};"
|
252
|
-
|
255
|
+
when 'float'
|
253
256
|
puts_h "@property (nonatomic, assign) CGFloat #{key};"
|
254
|
-
|
257
|
+
when 'double'
|
255
258
|
puts_h "@property (nonatomic, assign) double #{key};"
|
256
|
-
|
259
|
+
when 'boolean'
|
257
260
|
puts_h "@property (nonatomic, assign) BOOL #{key};"
|
258
|
-
|
261
|
+
when 'object'
|
259
262
|
puts_h "@property (nonatomic, strong) #{type_name} *#{key};"
|
260
|
-
|
263
|
+
when 'array'
|
261
264
|
puts_h "@property (nonatomic, strong) NSArray<#{type_name} *> *#{key};"
|
262
265
|
else
|
263
266
|
puts_h "@property (nonatomic, copy) NSString *#{key};"
|
@@ -266,36 +269,36 @@ module Lhj
|
|
266
269
|
|
267
270
|
def print_methods
|
268
271
|
puts "\n<===============方法调用=====================>\n"
|
269
|
-
puts_m
|
272
|
+
puts_m '/**'
|
270
273
|
puts_m " * #{@data_json['title']} -- #{@data_json['username']}"
|
271
|
-
puts_m
|
274
|
+
puts_m ' */'
|
272
275
|
key_str = @data_json['path'].split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { $&.upcase } }.join('')
|
273
276
|
key = "k#{key_str}URL"
|
274
277
|
puts_m "static NSString * const #{key} = @\"#{@data_json['path']}\";"
|
275
278
|
puts_m "\n\n"
|
276
|
-
puts_h
|
279
|
+
puts_h '@interface MLParamModel : NSObject'
|
277
280
|
@data_json['req_query'].each do |h|
|
278
281
|
des = h['desc']
|
279
282
|
puts_h "///#{des} #{h['example']}"
|
280
283
|
puts_h "@property (nonatomic, copy) NSString *#{h['name']};"
|
281
284
|
end
|
282
|
-
puts_h
|
285
|
+
puts_h '@end'
|
283
286
|
puts "\n\n"
|
284
287
|
model = @models.last
|
285
288
|
if @data_json['method'].eql?('GET')
|
286
289
|
puts_m " [MLNetworkingManager getWithUrl:#{key} params:nil response:^(MLResponseMessage *responseMessage) {"
|
287
|
-
puts_m
|
288
|
-
puts_m
|
290
|
+
puts_m ' if (response.resultCode == 0 && !response.error){'
|
291
|
+
puts_m ' NSDictionary *detailMsg = response.detailMsg'
|
289
292
|
puts_m " #{model[:name]} *model = [#{model[:name]} yy_modelWithDictionary:detailMsg];" if model
|
290
|
-
puts_m
|
291
|
-
puts_m
|
293
|
+
puts_m ' }'
|
294
|
+
puts_m ' }];'
|
292
295
|
else
|
293
296
|
puts_m " [MLNetworkingManager postWithUrl:#{key} params:nil response:^(MLResponseMessage *responseMessage) {"
|
294
|
-
puts_m
|
295
|
-
puts_m
|
297
|
+
puts_m ' if (response.resultCode == 0 && !response.error){'
|
298
|
+
puts_m ' NSDictionary *detailMsg = response.detailMsg'
|
296
299
|
puts_m " #{model[:name]} *model = [#{model[:name]} yy_modelWithDictionary:detailMsg];" if model
|
297
|
-
puts_m
|
298
|
-
puts_m
|
300
|
+
puts_m ' }'
|
301
|
+
puts_m ' }];'
|
299
302
|
end
|
300
303
|
end
|
301
304
|
end
|
data/lib/lhj/command.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
require 'claide'
|
2
2
|
|
3
3
|
module Lhj
|
4
|
+
# command plugin
|
4
5
|
class Command < CLAide::Command
|
6
|
+
require 'lhj/command/init'
|
7
|
+
require 'lhj/command/head_import'
|
8
|
+
require 'lhj/command/refactor_rename'
|
9
|
+
require 'lhj/command/local/fetch'
|
10
|
+
require 'lhj/command/local/filter'
|
11
|
+
require 'lhj/command/local/local'
|
12
|
+
require 'lhj/command/local/micro_service'
|
13
|
+
require 'lhj/command/local/local_upload'
|
14
|
+
require 'lhj/command/oss'
|
15
|
+
require 'lhj/command/oss/del'
|
16
|
+
require 'lhj/command/oss/upload'
|
17
|
+
require 'lhj/command/oss/list'
|
5
18
|
require 'lhj/command/view'
|
6
19
|
require 'lhj/command/rename_image'
|
7
20
|
require 'lhj/command/trans'
|
@@ -10,4 +23,4 @@ module Lhj
|
|
10
23
|
self.abstract_command = true
|
11
24
|
self.command = 'lhj'
|
12
25
|
end
|
13
|
-
end
|
26
|
+
end
|
data/lib/lhj/config.rb
CHANGED
@@ -1,354 +1,14 @@
|
|
1
|
-
|
2
1
|
module Lhj
|
3
|
-
#
|
4
|
-
#
|
2
|
+
# config
|
5
3
|
class Config
|
6
|
-
# The default settings for the configuration.
|
7
|
-
#
|
8
|
-
# Users can specify custom settings in `~/.cocoapods/config.yaml`.
|
9
|
-
# An example of the contents of this file might look like:
|
10
|
-
#
|
11
|
-
# ---
|
12
|
-
# skip_repo_update: true
|
13
|
-
# new_version_message: false
|
14
|
-
#
|
15
|
-
DEFAULTS = {
|
16
|
-
:verbose => false,
|
17
|
-
:silent => false,
|
18
|
-
:skip_download_cache => !ENV['COCOAPODS_SKIP_CACHE'].nil?,
|
19
|
-
|
20
|
-
:new_version_message => ENV['COCOAPODS_SKIP_UPDATE_MESSAGE'].nil?,
|
21
|
-
|
22
|
-
:cache_root => Pathname.new(Dir.home) + 'Library/Caches/CocoaPods',
|
23
|
-
}
|
24
|
-
|
25
|
-
# Applies the given changes to the config for the duration of the given
|
26
|
-
# block.
|
27
|
-
#
|
28
|
-
# @param [Hash<#to_sym,Object>] changes
|
29
|
-
# the changes to merge temporarily with the current config
|
30
|
-
#
|
31
|
-
# @yield [] is called while the changes are applied
|
32
|
-
#
|
33
|
-
def with_changes(changes)
|
34
|
-
old = {}
|
35
|
-
changes.keys.each do |key|
|
36
|
-
key = key.to_sym
|
37
|
-
old[key] = send(key) if respond_to?(key)
|
38
|
-
end
|
39
|
-
configure_with(changes)
|
40
|
-
yield if block_given?
|
41
|
-
ensure
|
42
|
-
configure_with(old)
|
43
|
-
end
|
44
|
-
|
45
|
-
public
|
46
|
-
|
47
|
-
#-------------------------------------------------------------------------#
|
48
|
-
|
49
|
-
# @!group UI
|
50
|
-
|
51
|
-
# @return [Boolean] Whether CocoaPods should provide detailed output about the
|
52
|
-
# performed actions.
|
53
|
-
#
|
54
|
-
attr_accessor :verbose
|
55
|
-
alias_method :verbose?, :verbose
|
56
|
-
|
57
|
-
# @return [Boolean] Whether CocoaPods should produce not output.
|
58
|
-
#
|
59
|
-
attr_accessor :silent
|
60
|
-
alias_method :silent?, :silent
|
61
|
-
|
62
|
-
# @return [Boolean] Whether CocoaPods is allowed to run as root.
|
63
|
-
#
|
64
|
-
attr_accessor :allow_root
|
65
|
-
alias_method :allow_root?, :allow_root
|
66
|
-
|
67
|
-
# @return [Boolean] Whether a message should be printed when a new version of
|
68
|
-
# CocoaPods is available.
|
69
|
-
#
|
70
|
-
attr_accessor :new_version_message
|
71
|
-
alias_method :new_version_message?, :new_version_message
|
72
|
-
|
73
|
-
#-------------------------------------------------------------------------#
|
74
|
-
|
75
|
-
# @!group Installation
|
76
|
-
|
77
|
-
# @return [Boolean] Whether the installer should skip the download cache.
|
78
|
-
#
|
79
|
-
attr_accessor :skip_download_cache
|
80
|
-
alias_method :skip_download_cache?, :skip_download_cache
|
81
|
-
|
82
|
-
public
|
83
|
-
|
84
|
-
#-------------------------------------------------------------------------#
|
85
|
-
|
86
|
-
# @!group Cache
|
87
|
-
|
88
|
-
# @return [Pathname] The directory where CocoaPods should cache remote data
|
89
|
-
# and other expensive to compute information.
|
90
|
-
#
|
91
|
-
attr_accessor :cache_root
|
92
|
-
|
93
|
-
def cache_root
|
94
|
-
@cache_root.mkpath unless @cache_root.exist?
|
95
|
-
@cache_root
|
96
|
-
end
|
97
|
-
|
98
|
-
public
|
99
|
-
|
100
|
-
#-------------------------------------------------------------------------#
|
101
|
-
|
102
|
-
# @!group Initialization
|
103
|
-
|
104
|
-
def initialize(use_user_settings = true)
|
105
|
-
configure_with(DEFAULTS)
|
106
|
-
|
107
|
-
unless ENV['CP_HOME_DIR'].nil?
|
108
|
-
@cache_root = home_dir + 'cache'
|
109
|
-
end
|
110
|
-
|
111
|
-
if use_user_settings && user_settings_file.exist?
|
112
|
-
require 'yaml'
|
113
|
-
user_settings = YAML.load_file(user_settings_file)
|
114
|
-
configure_with(user_settings)
|
115
|
-
end
|
116
|
-
|
117
|
-
unless ENV['CP_CACHE_DIR'].nil?
|
118
|
-
@cache_root = Pathname.new(ENV['CP_CACHE_DIR']).expand_path
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def verbose
|
123
|
-
@verbose && !silent
|
124
|
-
end
|
125
|
-
|
126
|
-
public
|
127
|
-
|
128
|
-
#-------------------------------------------------------------------------#
|
129
|
-
|
130
|
-
# @!group Paths
|
131
|
-
|
132
|
-
# @return [Pathname] the directory where repos, templates and configuration
|
133
|
-
# files are stored.
|
134
|
-
#
|
135
4
|
def home_dir
|
136
|
-
@home_dir ||= Pathname.new(
|
5
|
+
@home_dir ||= Pathname.new('~/.lhj').expand_path
|
137
6
|
end
|
138
7
|
|
139
|
-
# @return [Pathname] the directory where the CocoaPods sources are stored.
|
140
|
-
#
|
141
|
-
def repos_dir
|
142
|
-
@repos_dir ||= Pathname.new(ENV['CP_REPOS_DIR'] || (home_dir + 'repos')).expand_path
|
143
|
-
end
|
144
|
-
|
145
|
-
attr_writer :repos_dir
|
146
|
-
|
147
|
-
# @return [Source::Manager] the source manager for the spec repos in `repos_dir`
|
148
|
-
#
|
149
|
-
def sources_manager
|
150
|
-
return @sources_manager if @sources_manager && @sources_manager.repos_dir == repos_dir
|
151
|
-
@sources_manager = Source::Manager.new(repos_dir)
|
152
|
-
end
|
153
|
-
|
154
|
-
# @return [Pathname] the directory where the CocoaPods templates are stored.
|
155
|
-
#
|
156
|
-
def templates_dir
|
157
|
-
@templates_dir ||= Pathname.new(ENV['CP_TEMPLATES_DIR'] || (home_dir + 'templates')).expand_path
|
158
|
-
end
|
159
|
-
|
160
|
-
# @return [Pathname] the root of the CocoaPods installation where the
|
161
|
-
# Podfile is located.
|
162
|
-
#
|
163
|
-
def installation_root
|
164
|
-
@installation_root ||= begin
|
165
|
-
current_dir = Pathname.new(Dir.pwd.unicode_normalize(:nfkc))
|
166
|
-
current_path = current_dir
|
167
|
-
until current_path.root?
|
168
|
-
if podfile_path_in_dir(current_path)
|
169
|
-
installation_root = current_path
|
170
|
-
unless current_path == current_dir
|
171
|
-
UI.puts("[in #{current_path}]")
|
172
|
-
end
|
173
|
-
break
|
174
|
-
else
|
175
|
-
current_path = current_path.parent
|
176
|
-
end
|
177
|
-
end
|
178
|
-
installation_root || current_dir
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
attr_writer :installation_root
|
183
|
-
alias_method :project_root, :installation_root
|
184
|
-
|
185
|
-
# @return [Pathname] The root of the sandbox.
|
186
|
-
#
|
187
|
-
def sandbox_root
|
188
|
-
@sandbox_root ||= installation_root + 'Pods'
|
189
|
-
end
|
190
|
-
|
191
|
-
attr_writer :sandbox_root
|
192
|
-
alias_method :project_pods_root, :sandbox_root
|
193
|
-
|
194
|
-
# @return [Sandbox] The sandbox of the current project.
|
195
|
-
#
|
196
|
-
def sandbox
|
197
|
-
@sandbox ||= Sandbox.new(sandbox_root)
|
198
|
-
end
|
199
|
-
|
200
|
-
# @return [Podfile] The Podfile to use for the current execution.
|
201
|
-
# @return [Nil] If no Podfile is available.
|
202
|
-
#
|
203
|
-
def podfile
|
204
|
-
@podfile ||= Podfile.from_file(podfile_path) if podfile_path
|
205
|
-
end
|
206
|
-
attr_writer :podfile
|
207
|
-
|
208
|
-
# @return [Lockfile] The Lockfile to use for the current execution.
|
209
|
-
# @return [Nil] If no Lockfile is available.
|
210
|
-
#
|
211
|
-
def lockfile
|
212
|
-
@lockfile ||= Lockfile.from_file(lockfile_path) if lockfile_path
|
213
|
-
end
|
214
|
-
|
215
|
-
# Returns the path of the Podfile.
|
216
|
-
#
|
217
|
-
# @note The Podfile can be named either `CocoaPods.podfile.yaml`,
|
218
|
-
# `CocoaPods.podfile` or `Podfile`. The first two are preferred as
|
219
|
-
# they allow to specify an OS X UTI.
|
220
|
-
#
|
221
|
-
# @return [Pathname]
|
222
|
-
# @return [Nil]
|
223
|
-
#
|
224
|
-
def podfile_path
|
225
|
-
@podfile_path ||= podfile_path_in_dir(installation_root)
|
226
|
-
end
|
227
|
-
|
228
|
-
# Returns the path of the Lockfile.
|
229
|
-
#
|
230
|
-
# @note The Lockfile is named `Podfile.lock`.
|
231
|
-
#
|
232
|
-
def lockfile_path
|
233
|
-
@lockfile_path ||= installation_root + 'Podfile.lock'
|
234
|
-
end
|
235
|
-
|
236
|
-
# Returns the path of the default Podfile pods.
|
237
|
-
#
|
238
|
-
# @note The file is expected to be named Podfile.default
|
239
|
-
#
|
240
|
-
# @return [Pathname]
|
241
|
-
#
|
242
|
-
def default_podfile_path
|
243
|
-
@default_podfile_path ||= templates_dir + 'Podfile.default'
|
244
|
-
end
|
245
|
-
|
246
|
-
# Returns the path of the default Podfile test pods.
|
247
|
-
#
|
248
|
-
# @note The file is expected to be named Podfile.test
|
249
|
-
#
|
250
|
-
# @return [Pathname]
|
251
|
-
#
|
252
|
-
def default_test_podfile_path
|
253
|
-
@default_test_podfile_path ||= templates_dir + 'Podfile.test'
|
254
|
-
end
|
255
|
-
|
256
|
-
# @return [Pathname] The file to use to cache the search data.
|
257
|
-
#
|
258
|
-
def search_index_file
|
259
|
-
cache_root + 'search_index.json'
|
260
|
-
end
|
261
|
-
|
262
|
-
private
|
263
|
-
|
264
|
-
#-------------------------------------------------------------------------#
|
265
|
-
|
266
|
-
# @!group Private helpers
|
267
|
-
|
268
|
-
# @return [Pathname] The path of the file which contains the user settings.
|
269
|
-
#
|
270
|
-
def user_settings_file
|
271
|
-
home_dir + 'config.yaml'
|
272
|
-
end
|
273
|
-
|
274
|
-
# Sets the values of the attributes with the given hash.
|
275
|
-
#
|
276
|
-
# @param [Hash{String,Symbol => Object}] values_by_key
|
277
|
-
# The values of the attributes grouped by key.
|
278
|
-
#
|
279
|
-
# @return [void]
|
280
|
-
#
|
281
|
-
def configure_with(values_by_key)
|
282
|
-
return unless values_by_key
|
283
|
-
values_by_key.each do |key, value|
|
284
|
-
if key.to_sym == :cache_root
|
285
|
-
value = Pathname.new(value).expand_path
|
286
|
-
end
|
287
|
-
instance_variable_set("@#{key}", value)
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
# @return [Array<String>] The filenames that the Podfile can have ordered
|
292
|
-
# by priority.
|
293
|
-
#
|
294
|
-
PODFILE_NAMES = [
|
295
|
-
'CocoaPods.podfile.yaml',
|
296
|
-
'CocoaPods.podfile',
|
297
|
-
'Podfile',
|
298
|
-
'Podfile.rb',
|
299
|
-
].freeze
|
300
|
-
|
301
|
-
public
|
302
|
-
|
303
|
-
# Returns the path of the Podfile in the given dir if any exists.
|
304
|
-
#
|
305
|
-
# @param [Pathname] dir
|
306
|
-
# The directory where to look for the Podfile.
|
307
|
-
#
|
308
|
-
# @return [Pathname] The path of the Podfile.
|
309
|
-
# @return [Nil] If not Podfile was found in the given dir
|
310
|
-
#
|
311
|
-
def podfile_path_in_dir(dir)
|
312
|
-
PODFILE_NAMES.each do |filename|
|
313
|
-
candidate = dir + filename
|
314
|
-
if candidate.file?
|
315
|
-
return candidate
|
316
|
-
end
|
317
|
-
end
|
318
|
-
nil
|
319
|
-
end
|
320
|
-
|
321
|
-
# Excludes the given dir from Time Machine backups.
|
322
|
-
#
|
323
|
-
# @param [Pathname] dir
|
324
|
-
# The directory to exclude from Time Machine backups.
|
325
|
-
#
|
326
|
-
# @return [void]
|
327
|
-
#
|
328
|
-
def exclude_from_backup(dir)
|
329
|
-
return if Gem.win_platform?
|
330
|
-
system('tmutil', 'addexclusion', dir.to_s, %i(out err) => File::NULL)
|
331
|
-
end
|
332
|
-
|
333
|
-
public
|
334
|
-
|
335
|
-
#-------------------------------------------------------------------------#
|
336
|
-
|
337
|
-
# @!group Singleton
|
338
|
-
|
339
|
-
# @return [Config] the current config instance creating one if needed.
|
340
|
-
#
|
341
8
|
def self.instance
|
342
9
|
@instance ||= new
|
343
10
|
end
|
344
11
|
|
345
|
-
# Sets the current config instance. If set to nil the config will be
|
346
|
-
# recreated when needed.
|
347
|
-
#
|
348
|
-
# @param [Config, Nil] the instance.
|
349
|
-
#
|
350
|
-
# @return [void]
|
351
|
-
#
|
352
12
|
class << self
|
353
13
|
attr_writer :instance
|
354
14
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'lhj/helper/oss_config'
|
3
|
+
|
4
|
+
module Lhj
|
5
|
+
class LocalConfig
|
6
|
+
def config_file
|
7
|
+
File.join(Lhj::Config.instance.home_dir, config_file_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def config_file_name
|
11
|
+
'localizable_config.yml'
|
12
|
+
end
|
13
|
+
|
14
|
+
def syn_config_file
|
15
|
+
Lhj::OSS::Helper.instance.down_load(config_file_name, config_file)
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_config
|
19
|
+
syn_config_file unless File.exist?(config_file)
|
20
|
+
YAML.load_file(config_file)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_col_by_name(file_name, col_name = 'csv_key_col')
|
24
|
+
m = config
|
25
|
+
col = m[col_name]
|
26
|
+
fo = m['read_targets'].find{ |o| /#{o['csv_file']}/ =~ file_name }
|
27
|
+
col = fo[col_name] if fo
|
28
|
+
col
|
29
|
+
end
|
30
|
+
|
31
|
+
def config
|
32
|
+
@config ||= load_config
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.instance
|
36
|
+
@instance ||= new
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'lhj/config'
|
4
|
+
|
5
|
+
module Lhj
|
6
|
+
class OSSConfig
|
7
|
+
def self.config_file
|
8
|
+
file = 'oss_config.yml'
|
9
|
+
File.expand_path("#{Lhj::Config.instance.home_dir}/#{file}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
@yaml ||= YAML.load_file(config_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.oss_endpoint
|
17
|
+
config['oss_endpoint']
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.oss_access_key_id
|
21
|
+
config['oss_access_key_id']
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.oss_access_key_secret
|
25
|
+
config['oss_access_key_secret']
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.oss_bucket
|
29
|
+
config['oss_bucket']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'aliyun/oss'
|
2
|
+
require 'lhj/helper/oss_config'
|
3
|
+
|
4
|
+
module Lhj
|
5
|
+
class OSS
|
6
|
+
class Helper
|
7
|
+
def initialize
|
8
|
+
@client = Aliyun::OSS::Client.new(endpoint: Lhj::OSSConfig.oss_endpoint,
|
9
|
+
access_key_id: Lhj::OSSConfig.oss_access_key_id,
|
10
|
+
access_key_secret: Lhj::OSSConfig.oss_access_key_secret)
|
11
|
+
@bucket = @client.get_bucket(Lhj::OSSConfig.oss_bucket)
|
12
|
+
end
|
13
|
+
|
14
|
+
def url_path
|
15
|
+
"http://#{Lhj::OSSConfig.oss_bucket}.#{Lhj::OSSConfig.oss_endpoint}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def upload(key, file)
|
19
|
+
@bucket.put_object(key, :file => file)
|
20
|
+
end
|
21
|
+
|
22
|
+
def down_load(key, file, &block)
|
23
|
+
@bucket.get_object(key, :file => file, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def object_url(key)
|
27
|
+
@bucket.object_url(key, false)
|
28
|
+
end
|
29
|
+
|
30
|
+
def list
|
31
|
+
@bucket.list_objects
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(key)
|
35
|
+
@bucket.delete_object(key)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.instance
|
39
|
+
@instance ||= new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'lhj/config'
|
2
|
+
|
3
|
+
module Lhj
|
4
|
+
class Trans
|
5
|
+
class Helper
|
6
|
+
def self.instance
|
7
|
+
@instance ||= new
|
8
|
+
end
|
9
|
+
|
10
|
+
def yaml_file
|
11
|
+
File.join(Lhj::Config.instance.home_dir, 'zh2hant.yml')
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_trans_map
|
15
|
+
require 'yaml'
|
16
|
+
down_load_yaml unless File.exist?(yaml_file)
|
17
|
+
contents = YAML.safe_load(File.open(yaml_file))
|
18
|
+
contents.to_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def down_load_yaml
|
22
|
+
require 'open-uri'
|
23
|
+
URI.open('http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml') do |i|
|
24
|
+
File.open(yaml_file, 'w+') do |f|
|
25
|
+
f.write(i.read)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def trans_zh_cn_str(input)
|
31
|
+
@trans_map_invert ||= load_trans_map.invert
|
32
|
+
out = []
|
33
|
+
input.each_char do |c|
|
34
|
+
out << (@trans_map_invert[c] || c)
|
35
|
+
end
|
36
|
+
out.join('')
|
37
|
+
end
|
38
|
+
|
39
|
+
def trans_zh_hk_str(input)
|
40
|
+
@trans_map ||= load_trans_map
|
41
|
+
out = []
|
42
|
+
input.each_char do |c|
|
43
|
+
out << (@trans_map[c] || c)
|
44
|
+
end
|
45
|
+
out.join('')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|