xfabricator 0.1.2 → 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 +4 -4
- data/bin/xfabricate +1 -1
- data/lib/xfabricator/fabricator.rb +24 -12
- data/lib/xfabricator/template_definition.rb +3 -1
- data/lib/xfabricator/version.rb +1 -1
- data/lib/xfabricator/xcodeproj_additions.rb +29 -0
- data/xfabricator.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 322079b7d1a85c7ba769423c3ff5c12599a10a96
|
4
|
+
data.tar.gz: 20318c1f5fab4b69061d3350898d8aba4314aa6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 662d9432e58fc435fe18618d01604299e8336b9f66256e3b1e34fe9161bffc2b934aaaa1b2434b888024c22eba302df22b2426f9babc14bf50be0840c8500807
|
7
|
+
data.tar.gz: 21b5944af780542391faf214450cf0a20fbe8590bb68f68c66656f492f4c4f213c814cf7425c3a65b099d4fd2c6a11ab82867fe90775ff48141b1701a10a1092
|
data/bin/xfabricate
CHANGED
@@ -95,7 +95,7 @@ OptionParser.new do |opts|
|
|
95
95
|
options[:group] = group_name
|
96
96
|
end
|
97
97
|
|
98
|
-
opts.on("-p path_name", "--path=path_name", "specify path to
|
98
|
+
opts.on("-p path_name", "--path=path_name", "specify search path to find the current group") do |path|
|
99
99
|
options[:path] = path
|
100
100
|
end
|
101
101
|
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require "xfabricator/version"
|
2
2
|
require 'xcodeproj'
|
3
3
|
require 'xfabricator/x_code_file_template'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'xfabricator/xcodeproj_additions'
|
4
6
|
|
5
7
|
module Xfabricator
|
6
8
|
|
7
9
|
class Fabricator
|
8
10
|
|
9
|
-
def initialize(config,
|
11
|
+
def initialize(config, search_path)
|
10
12
|
@config = config
|
11
|
-
@
|
13
|
+
@search_path = search_path
|
12
14
|
end
|
13
15
|
|
14
16
|
def fabricate(template, variables, target_name)
|
@@ -30,7 +32,8 @@ module Xfabricator
|
|
30
32
|
raise ArgumentError, "target_name not specified"
|
31
33
|
end
|
32
34
|
|
33
|
-
|
35
|
+
project = @config.project
|
36
|
+
target = project.targets.find { |target| target.name == target_name }
|
34
37
|
|
35
38
|
unless target
|
36
39
|
raise ArgumentError, "Couldn't find target with name: #{target_name}"
|
@@ -46,25 +49,36 @@ module Xfabricator
|
|
46
49
|
if Pathname.new(template_file_path).exist?
|
47
50
|
name_template = Mustache.new
|
48
51
|
output_name = name_template.render template_file.output_name_template, variables
|
49
|
-
|
50
|
-
|
52
|
+
|
53
|
+
current_group = group
|
54
|
+
|
55
|
+
if template_file.sub_path.length > 0
|
56
|
+
groups = group.xfab_create_subpath(template_file.sub_path)
|
57
|
+
current_group = groups.last
|
58
|
+
end
|
59
|
+
|
60
|
+
output_file = fabricate_file(output_name, template_file_path, variables, current_group.real_path)
|
61
|
+
|
62
|
+
ref = current_group.new_reference output_file
|
51
63
|
target.add_file_references [ref]
|
52
64
|
else
|
53
65
|
raise RuntimeError, "template file was not found: #{template_file_path}"
|
54
66
|
end
|
55
67
|
|
56
|
-
@config.project.save
|
57
68
|
end
|
58
69
|
|
70
|
+
project.save
|
71
|
+
|
59
72
|
end
|
60
73
|
|
61
|
-
def fabricate_file(output_name, template_file_path, variables)
|
62
|
-
|
74
|
+
def fabricate_file(output_name, template_file_path, variables, output_dir)
|
75
|
+
FileUtils.mkdir_p output_dir
|
63
76
|
|
64
77
|
template = XCodeFileTemplate.new @config.project, variables
|
65
78
|
template.template_file = template_file_path
|
66
79
|
rendered_content = template.render
|
67
80
|
|
81
|
+
output_file = "#{output_dir}/#{output_name}"
|
68
82
|
File.open(output_file, 'w') { |file| file.write(rendered_content) }
|
69
83
|
output_file
|
70
84
|
end
|
@@ -73,13 +87,11 @@ module Xfabricator
|
|
73
87
|
project = @config.project
|
74
88
|
main_group = project.main_group
|
75
89
|
|
76
|
-
|
77
|
-
puts "#{main_group_path} == #{@fabrication_path.to_s}"
|
78
|
-
if main_group_path == @fabrication_path.to_s
|
90
|
+
if main_group.real_path == @search_path.to_s
|
79
91
|
return main_group
|
80
92
|
end
|
81
93
|
|
82
|
-
find_group_for_directory(main_group, @
|
94
|
+
find_group_for_directory(main_group, @search_path, project)
|
83
95
|
end
|
84
96
|
|
85
97
|
def find_group_for_directory(current_group, directory, project)
|
@@ -44,10 +44,12 @@ module Xfabricator
|
|
44
44
|
|
45
45
|
attr_reader :output_name_template
|
46
46
|
attr_reader :template_file
|
47
|
+
attr_reader :sub_path
|
47
48
|
|
48
|
-
def initialize(template_file, output_name_template)
|
49
|
+
def initialize(template_file, output_name_template, sub_path = '')
|
49
50
|
@output_name_template = output_name_template
|
50
51
|
@template_file = template_file
|
52
|
+
@sub_path = sub_path
|
51
53
|
end
|
52
54
|
|
53
55
|
end
|
data/lib/xfabricator/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'xcodeproj'
|
2
|
+
|
3
|
+
module Xfabricator
|
4
|
+
|
5
|
+
module PBXGroupAdditions
|
6
|
+
|
7
|
+
def xfab_create_subpath(path)
|
8
|
+
return self unless path
|
9
|
+
|
10
|
+
path = path.split('/') unless path.is_a?(Array)
|
11
|
+
child_name = path.shift
|
12
|
+
child = children.find { |c| c.display_name == child_name }
|
13
|
+
|
14
|
+
if child.nil?
|
15
|
+
child = new_group(nil, child_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
if path.empty?
|
19
|
+
[ child ]
|
20
|
+
else
|
21
|
+
[ child ].concat child.xfab_create_subpath(path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
Xcodeproj::Project::Object::PBXGroup.include PBXGroupAdditions
|
28
|
+
|
29
|
+
end
|
data/xfabricator.gemspec
CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "xcodeproj", "~> 1.4"
|
27
27
|
spec.add_development_dependency "mustache", "~> 1.0"
|
28
|
-
spec.add_development_dependency "inquirer"
|
28
|
+
spec.add_development_dependency "inquirer", "~> 0"
|
29
29
|
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xfabricator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Cross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,14 +70,14 @@ dependencies:
|
|
70
70
|
name: inquirer
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Generate file templates and add them to XCode project...
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/xfabricator/template_definition.rb
|
101
101
|
- lib/xfabricator/version.rb
|
102
102
|
- lib/xfabricator/x_code_file_template.rb
|
103
|
+
- lib/xfabricator/xcodeproj_additions.rb
|
103
104
|
- xfabricator.gemspec
|
104
105
|
homepage: https://github.com/nicholascross/xfabricator
|
105
106
|
licenses:
|