lhj-tools 0.1.1 → 0.1.5
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 +54 -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 +23 -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 +93 -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 +28 -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
- data/lib/lhj/tree/directory_renderer.rb +45 -0
- data/lib/lhj/tree/hash_walker.rb +70 -0
- data/lib/lhj/tree/node.rb +90 -0
- data/lib/lhj/tree/number_renderer.rb +30 -0
- data/lib/lhj/tree/path_walker.rb +108 -0
- data/lib/lhj/tree/tree.rb +112 -0
- metadata +74 -2
data/lib/lhj/command/view.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Lhj
|
2
2
|
class Command
|
3
3
|
class View < Command
|
4
|
-
self.summary = '
|
4
|
+
self.summary = '生成iOS组件源码'
|
5
|
+
self.description = '使用`lhj view --type=UILabel --name=titleLabel`'
|
5
6
|
|
6
7
|
def initialize(argv)
|
7
8
|
@name = argv.option('name', 'titleLabel')
|
@@ -10,24 +11,25 @@ module Lhj
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def names
|
13
|
-
@name.split(
|
14
|
+
@name.split(',').map(&:strip)
|
14
15
|
end
|
15
16
|
|
16
17
|
def type
|
17
18
|
@ele_type ||= begin
|
18
|
-
|
19
|
+
case @type
|
20
|
+
when /image/i
|
19
21
|
'UIImageView'
|
20
|
-
|
22
|
+
when /stack/i
|
21
23
|
'UIStackView'
|
22
|
-
|
24
|
+
when /label/i
|
23
25
|
'UILabel'
|
24
|
-
|
26
|
+
when /table/i
|
25
27
|
'UITableView'
|
26
|
-
|
28
|
+
when /text/i
|
27
29
|
'UITextField'
|
28
|
-
|
30
|
+
when /button/i
|
29
31
|
'UIButton'
|
30
|
-
|
32
|
+
when /view/i
|
31
33
|
'UIView'
|
32
34
|
else
|
33
35
|
@type
|
@@ -47,7 +49,7 @@ module Lhj
|
|
47
49
|
|
48
50
|
def print_declare
|
49
51
|
names.each do |name|
|
50
|
-
puts
|
52
|
+
puts '///'
|
51
53
|
puts "@property (nonatomic, strong) #{type} *#{name};"
|
52
54
|
end
|
53
55
|
end
|
@@ -55,24 +57,25 @@ module Lhj
|
|
55
57
|
def print_instance
|
56
58
|
names.each do |name|
|
57
59
|
puts "-(#{type} *)#{name}"
|
58
|
-
puts
|
60
|
+
puts '{'
|
59
61
|
puts " if(!_#{name}){"
|
60
62
|
print_alloc(name)
|
61
63
|
puts " _#{name}.translatesAutoresizingMaskIntoConstraints = NO;"
|
62
64
|
print_property(name)
|
63
|
-
puts
|
65
|
+
puts ' }'
|
64
66
|
puts " return _#{name};"
|
65
|
-
puts
|
67
|
+
puts '}'
|
66
68
|
puts "\n"
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
70
72
|
def print_alloc(name)
|
71
|
-
|
73
|
+
case type
|
74
|
+
when 'UIImageView'
|
72
75
|
puts " _#{name} = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"xxxx\"]];"
|
73
|
-
|
76
|
+
when 'UIButton'
|
74
77
|
puts " _#{name} = [UIButton buttonWithType:UIButtonTypeCustom];"
|
75
|
-
|
78
|
+
when 'UITableView'
|
76
79
|
puts " _#{name} = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];"
|
77
80
|
else
|
78
81
|
puts " _#{name} = [[#{type} alloc] init];"
|
@@ -80,34 +83,35 @@ module Lhj
|
|
80
83
|
end
|
81
84
|
|
82
85
|
def print_property(name)
|
83
|
-
|
86
|
+
case type
|
87
|
+
when 'UILabel'
|
84
88
|
puts " _#{name}.textColor = kSetCOLOR(0x333333);"
|
85
89
|
puts " _#{name}.text = @\"xxxxxxxx\";"
|
86
90
|
puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
|
87
91
|
puts " _#{name}.textAlignment = NSTextAlignmentCenter;"
|
88
|
-
|
92
|
+
when 'UIImageView'
|
89
93
|
puts " _#{name}.backgroundColor = kBackgroundColor;"
|
90
94
|
puts " _#{name}.contentMode = UIViewContentModeScaleAspectFit;"
|
91
95
|
puts " _#{name}.clipsToBounds = YES;"
|
92
96
|
puts " _#{name}.layer.cornerRadius = 6.0f;"
|
93
97
|
puts " _#{name}.layer.borderColor = kLineColor.CGColor;"
|
94
98
|
puts " _#{name}.layer.borderWidth = 0.5;"
|
95
|
-
|
99
|
+
when 'UITextField'
|
96
100
|
puts " _#{name}.textColor = kSetCOLOR(0x333333);"
|
97
101
|
puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
|
98
|
-
|
102
|
+
when 'UIView'
|
99
103
|
puts " _#{name}.backgroundColor = kBackgroundColor;"
|
100
|
-
|
104
|
+
when 'UIStackView'
|
101
105
|
puts " _#{name}.axis = UILayoutConstraintAxisHorizontal;"
|
102
106
|
puts " _#{name}.distribution = UIStackViewDistributionFillEqually;"
|
103
|
-
|
107
|
+
when 'UITableView'
|
104
108
|
puts " _#{name}.backgroundColor = kBackgroundColor;"
|
105
109
|
puts " _#{name}.delegate = self;"
|
106
110
|
puts " _#{name}.delegate = self;"
|
107
111
|
puts " _#{name}.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
|
108
112
|
puts " _#{name}.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
|
109
113
|
puts " _#{name}.separatorStyle = UITableViewCellSeparatorStyleNone;"
|
110
|
-
|
114
|
+
when 'UIButton'
|
111
115
|
puts " _#{name}.backgroundColor = kBackgroundColor;"
|
112
116
|
puts " [_#{name} setTitle:@\"xxx\" forState:UIControlStateNormal];"
|
113
117
|
puts " [_#{name} setTitleColor:kSetCOLOR(0x999999) forState:UIControlStateNormal];"
|
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,21 @@
|
|
1
1
|
require 'claide'
|
2
|
+
require "tty-spinner"
|
2
3
|
|
3
4
|
module Lhj
|
5
|
+
# command plugin
|
4
6
|
class Command < CLAide::Command
|
7
|
+
require 'lhj/command/init'
|
8
|
+
require 'lhj/command/head_import'
|
9
|
+
require 'lhj/command/refactor_rename'
|
10
|
+
require 'lhj/command/local/fetch'
|
11
|
+
require 'lhj/command/local/filter'
|
12
|
+
require 'lhj/command/local/local'
|
13
|
+
require 'lhj/command/local/micro_service'
|
14
|
+
require 'lhj/command/local/local_upload'
|
15
|
+
require 'lhj/command/oss'
|
16
|
+
require 'lhj/command/oss/del'
|
17
|
+
require 'lhj/command/oss/upload'
|
18
|
+
require 'lhj/command/oss/list'
|
5
19
|
require 'lhj/command/view'
|
6
20
|
require 'lhj/command/rename_image'
|
7
21
|
require 'lhj/command/trans'
|
@@ -9,5 +23,18 @@ module Lhj
|
|
9
23
|
|
10
24
|
self.abstract_command = true
|
11
25
|
self.command = 'lhj'
|
26
|
+
|
27
|
+
def spinner
|
28
|
+
@spinner ||= TTY::Spinner.new('[:spinner]正在处理...', format: :dots)
|
29
|
+
end
|
30
|
+
|
31
|
+
def auto_spin
|
32
|
+
spinner.auto_spin
|
33
|
+
end
|
34
|
+
|
35
|
+
def stop
|
36
|
+
spinner.stop('Done!')
|
37
|
+
end
|
38
|
+
|
12
39
|
end
|
13
|
-
end
|
40
|
+
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
|