Class: Xcmake::Generator
Instance Method Summary
collapse
#find_group_with_path, #find_target_with_path, #group_paths, #is_target_path?, #project_root
Methods included from Logger
#log_error, #log_error!, #log_info
Constructor Details
#initialize(project_path) ⇒ Generator
Returns a new instance of Generator.
10
11
12
|
# File 'lib/xcmake/generator.rb', line 10
def initialize(project_path)
@project = Xcodeproj::Project.open(project_path)
end
|
Instance Method Details
#create_group(name) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/xcmake/generator.rb', line 43
def create_group(name)
group_dir_path = File.join(project_root, name)
if group_paths.map(&:to_s).include?(group_dir_path)
log_info("Group\t'#{name}' already exists.")
return
end
groups = name.split("/")
base_path = File.join(project_root, @project.main_group.path.to_s)
create_group_recursive(groups, @project.main_group, base_path)
FileUtils.mkdir_p(group_dir_path)
log_info("Group\t'#{name}' created!!")
@project.save
end
|
#create_source(name, template = nil) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/xcmake/generator.rb', line 66
def create_source(name, template=nil)
dir_path = File.dirname(name)
file_name = File.basename(name)
group = find_group_with_path(dir_path).tap do |r|
if r.nil?
log_error!("group path not found. please set NAME to [GROUP_PATH]/[FILE_NAME] and try it!")
end
end
File.join(group.real_path, file_name).tap do |file_path|
if File.exist?(file_path)
log_info("Source\t'#{name}' already exists.")
return
end
end
file_ref = group.new_file(file_name)
find_target_with_path(dir_path).tap { |r| r&.add_file_references([file_ref]) }
file_path = file_ref.real_path
file_ext = File.extname(file_path)
data =
case file_ext
when ".swift" then
params = parameter_for_swift(file_name, dir_path.split("/").first)
SwiftBuilder.new(template).build(params)
when ".plist" then
params = parameter_for_plist(:framework)
PlistBuilder.new(template).build(params)
else
log_error!("File type `#{file_ext}` is not supported.")
end
File.write(file_path, data)
log_info("Source\t'#{name}' created!!")
@project.save
end
|
#create_target(name, type, platform = :ios, lang = :swift) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/xcmake/generator.rb', line 14
def create_target(name, type, platform=:ios, lang=:swift)
find_target_with_path(name).tap do |target|
unless target.nil?
log_info("Target\t'#{name}' already exists.")
return
end
end
target = @project.new_target(type, name, platform, nil, nil, lang)
create_group(name)
create_source(
File.join(name, "Info.plist"),
File.expand_path("../../templates/default.plist.erb", __dir__)
)
@project.main_group.find_subpath(name).tap do |group|
target.add_file_references(group.files)
target.build_configuration_list.set_setting("INFOPLIST_FILE", "$(SRCROOT)/#{name}/Info.plist")
end
log_info("Target\t'#{name}' created!!")
@project.save
end
|
#delete_group(name) ⇒ Object
61
62
63
64
|
# File 'lib/xcmake/generator.rb', line 61
def delete_group(name)
delete_group_recursive(name)
@project.save
end
|
#delete_target(name) ⇒ Object
39
40
41
|
# File 'lib/xcmake/generator.rb', line 39
def delete_target(name)
log_info("`delete_target` now working...")
end
|