cocoapods-x 0.0.1 → 0.0.2

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-x/command.rb +3 -1
  3. data/lib/cocoapods-x/command/edit.rb +41 -30
  4. data/lib/cocoapods-x/command/environment/init.rb +3 -4
  5. data/lib/cocoapods-x/command/environment/install.rb +3 -3
  6. data/lib/cocoapods-x/command/environment/update.rb +3 -3
  7. data/lib/cocoapods-x/command/install.rb +35 -0
  8. data/lib/cocoapods-x/command/libary/create.rb +1 -1
  9. data/lib/cocoapods-x/command/repo.rb +91 -0
  10. data/lib/cocoapods-x/command/update.rb +28 -0
  11. data/lib/cocoapods-x/command/xcode/clean.rb +2 -2
  12. data/lib/cocoapods-x/command/xcode/open.rb +5 -30
  13. data/lib/cocoapods-x/extension.rb +2 -1
  14. data/lib/cocoapods-x/extension/configure.rb +10 -5
  15. data/lib/cocoapods-x/extension/environment.rb +0 -81
  16. data/lib/cocoapods-x/extension/installer.rb +144 -0
  17. data/lib/cocoapods-x/extension/installer/builder.rb +36 -0
  18. data/lib/cocoapods-x/extension/installer/dsl.rb +94 -0
  19. data/lib/cocoapods-x/extension/installer/podfile.rb +66 -0
  20. data/lib/cocoapods-x/extension/sandbox/project.rb +1 -1
  21. data/lib/cocoapods-x/extension/sandbox/repos.rb +48 -24
  22. data/lib/cocoapods-x/extension/sandbox/template.rb +2 -2
  23. data/lib/cocoapods-x/extension/sandbox/workspace.rb +41 -2
  24. data/lib/cocoapods-x/extension/xcode.rb +1 -0
  25. data/lib/cocoapods-x/extension/xcode/open.rb +44 -0
  26. data/lib/cocoapods-x/gem_version.rb +1 -1
  27. metadata +11 -8
  28. data/lib/cocoapods-x/command/repos.rb +0 -74
  29. data/lib/cocoapods-x/extension/environment/definition.rb +0 -90
  30. data/lib/cocoapods-x/extension/environment/dsl.rb +0 -76
  31. data/lib/cocoapods-x/extension/environment/pod.rb +0 -23
  32. data/lib/cocoapods-x/extension/environment/podfile.rb +0 -40
  33. data/lib/cocoapods-x/extension/environment/source.rb +0 -24
@@ -0,0 +1,144 @@
1
+ require 'cocoapods-x/extension/sandbox'
2
+ require 'cocoapods-x/extension/configure'
3
+ require 'cocoapods-x/extension/installer/dsl'
4
+ require 'cocoapods-x/extension/installer/podfile'
5
+ require 'cocoapods-x/extension/installer/builder'
6
+
7
+ module Pod
8
+ module X
9
+ class Installer
10
+
11
+ attr_accessor :init_self, :target_self, :pod_self, :print_post_install_message_self
12
+ attr_accessor :init_method, :target_method, :pod_method, :print_post_install_message_method
13
+
14
+ attr_accessor :pods_builder, :sources_builder
15
+ attr_accessor :project, :workspace
16
+
17
+ attr_accessor :repos
18
+ attr_accessor :use_repos
19
+
20
+ extend Executable
21
+ executable :rm
22
+ executable :git
23
+
24
+ def initialize
25
+ @project = nil
26
+ @workspace = nil
27
+ @pods_builder = Pod::X::PodsBuilder::new
28
+ @sources_builder = Pod::X::SourcesBuilder::new
29
+ end
30
+
31
+ def self.installer
32
+ @@shared ||= Pod::X::Installer::new
33
+ @@shared
34
+ end
35
+
36
+ # monitor
37
+
38
+ def monitor_initialize_begin(defined_in_file = nil, internal_hash = {}, &block)
39
+ workspace = Pod::X::Sandbox::workspace
40
+ return unless workspace.source_file.exist?
41
+
42
+ conf = Pod::X::Configurator::find_conf?(Dir.pwd)
43
+ return if conf.nil?
44
+ project = Pod::X::Sandbox::Project::new(conf)
45
+ return unless project.pods_file.exist?
46
+
47
+ @project = project
48
+ @workspace = workspace
49
+ @pods_builder::build(project.pods_file)
50
+ @sources_builder::build(workspace.source_file)
51
+ @repos = build_repos()
52
+ @use_repos = Array::new
53
+ UI.puts 'Pod::X '.blue + 'Working...'.green
54
+ end
55
+
56
+ def monitor_initialize_end(defined_in_file = nil, internal_hash = {}, &block)
57
+ return nil if @repos.nil?
58
+ return nil if @use_repos.nil?
59
+
60
+ @use_repos.each do |name|
61
+ repo = @repos[name]
62
+ repo_url = repo.repo_url
63
+ location_url = repo.location_url
64
+ if repo_url.nil? || location_url.nil?
65
+ UI.puts 'Pod::X '.blue + "You must specify a repository to clone for '#{name}'.".yellow
66
+ elsif !Dir::exist?(location_url) || Dir::empty?(location_url)
67
+ UI.section('Pod::X '.blue + "Cloning into '#{name}'...".green) do
68
+ UI.puts 'Pod::X '.blue + "'#{name}' from: #{repo_url}".blue
69
+ UI.puts 'Pod::X '.blue + "'#{name}' to: #{location_url}".blue
70
+ rm! ['-rf', location_url]
71
+ git! ['clone', repo_url, location_url]
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def monitor_target_begin(name, options = nil, &block)
78
+
79
+ end
80
+
81
+ def monitor_target_end(name, options = nil, &block)
82
+
83
+ end
84
+
85
+ def monitor_pod_begin(name, *requirements)
86
+ return nil if @repos.nil?
87
+ return nil if @repos[name].nil?
88
+ return nil if @use_repos.nil?
89
+
90
+ @use_repos << name
91
+ @repos[name].location_url
92
+ end
93
+
94
+ def monitor_pod_end(name, *requirements)
95
+ nil
96
+ end
97
+
98
+ def monitor_print_post_install_message_begin
99
+ return nil if @repos.nil?
100
+ return nil if @use_repos.nil?
101
+ return nil if @use_repos.size <= 0
102
+
103
+ @use_repos.each do |name|
104
+ repo = @repos[name]
105
+ location_url = repo.location_url
106
+ unless location_url.nil?
107
+ Dir.chdir(location_url) do
108
+ begin
109
+ branch = git! ['rev-parse', '--abbrev-ref', 'HEAD']
110
+ branch = branch.chomp
111
+ UI.puts 'Pod::X '.blue + "Installing #{name} (#{branch.red})".green
112
+ rescue => exception
113
+ UI.puts 'Pod::X '.blue + "Installing #{name}".green
114
+ end
115
+ end
116
+ end
117
+ end
118
+ UI.puts 'Pod::X '.blue + "installation complete!".green
119
+ end
120
+
121
+ def monitor_print_post_install_message_end
122
+
123
+ end
124
+
125
+ private
126
+
127
+ def build_repos
128
+ return nil if @pods_builder.nil?
129
+ return nil if @sources_builder.nil?
130
+
131
+ repos = Hash::new(nil)
132
+ @pods_builder.pods.each do | name, pod_argv |
133
+ source_argv = @sources_builder.sources[name]
134
+ repo = Pod::X::Sandbox::Repos::Repo(name, pod_argv, source_argv, @workspace, @project)
135
+ unless repo.nil?
136
+ repos[name] = repo
137
+ end
138
+ end
139
+ repos
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,36 @@
1
+ require 'cocoapods-x/extension/installer/dsl'
2
+
3
+ module Pod
4
+ module X
5
+ class PodsBuilder
6
+
7
+ include Pod::X::PodsDSL
8
+ include Pod::X::BuilderDSL
9
+
10
+ attr_accessor :pods
11
+
12
+ def initialize
13
+ @pods = Hash::new(nil)
14
+ end
15
+
16
+ end
17
+
18
+ class SourcesBuilder
19
+
20
+ include Pod::X::SourcesDSL
21
+ include Pod::X::BuilderDSL
22
+
23
+ attr_accessor :current_domain, :current_group
24
+ attr_accessor :sources
25
+
26
+ def initialize
27
+ @current_domain = nil
28
+ @current_group = nil
29
+ @sources = Hash::new(nil)
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
36
+
@@ -0,0 +1,94 @@
1
+ module Pod
2
+ module X
3
+
4
+ module PodsDSL
5
+
6
+ def pod(name = nil, *requirements)
7
+ unless name
8
+ raise StandardError, 'A development requires a name.'
9
+ end
10
+
11
+ pod = Hash::new(nil)
12
+ pod[:name] = name
13
+ pod[:share] = true
14
+ options = requirements.last
15
+ if options && options.is_a?(Hash)
16
+ pod = pod.merge(options.dup)
17
+ end
18
+
19
+ @pods[name] = pod
20
+ end
21
+
22
+ end
23
+
24
+ module SourcesDSL
25
+
26
+ def source(domain, *requirements)
27
+ @current_domain = domain
28
+ options = requirements.last
29
+ if options && options.is_a?(Hash) && options[:group]
30
+ @current_group = options[:group]
31
+ end
32
+
33
+ yield if block_given?
34
+ ensure
35
+ @current_domain = nil
36
+ @current_group = nil
37
+ end
38
+
39
+ def pod(name = nil, *requirements)
40
+ unless name
41
+ raise StandardError, 'A development requires a name.'
42
+ end
43
+
44
+ return if @current_domain.nil?
45
+
46
+ source = Hash::new(nil)
47
+ source[:domain] = @current_domain
48
+ source[:git] = name + '.git'
49
+ source[:name] = name
50
+ if @current_group
51
+ source[:group] = @current_group
52
+ else
53
+ source[:group] = name
54
+ end
55
+
56
+ options = requirements.last
57
+ if options && options.is_a?(Hash)
58
+ source = source.merge(options.dup)
59
+ end
60
+
61
+ @sources[name] = source
62
+ end
63
+
64
+ end
65
+
66
+ module BuilderDSL
67
+
68
+ def build url
69
+ contents = File.exist?(url) ? File.open(url, 'r:utf-8', &:read) : nil
70
+ # Work around for Rubinius incomplete encoding in 1.9 mode
71
+ if !contents.nil? && contents.respond_to?(:encoding) && contents.encoding.name != 'UTF-8'
72
+ contents.encode!('UTF-8')
73
+ end
74
+ if !contents.nil? && contents.tr!('“”‘’‛', %(""'''))
75
+ # Changes have been made
76
+ CoreUI.warn "Smart quotes were detected and ignored in your #{File.basename(url)}. " \
77
+ 'To avoid issues in the future, you should not use ' \
78
+ 'TextEdit for editing it. If you are not using TextEdit, ' \
79
+ 'you should turn off smart quotes in your editor of choice.'
80
+ end
81
+ unless contents.nil?
82
+ begin
83
+ eval(contents, nil, url.to_s)
84
+ rescue Exception => e
85
+ message = "Invalid `#{File.basename(url)}` file: #{e.message}"
86
+ raise DSLError.new(message, url, e, contents)
87
+ end
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,66 @@
1
+ module Pod
2
+ class Podfile
3
+
4
+ xold_podfile_init_method = instance_method(:initialize)
5
+ define_method(:initialize) do |defined_in_file = nil, internal_hash = {}, &block|
6
+ installer = Pod::X::Installer::installer
7
+ installer.init_self = self
8
+ installer.init_method = xold_podfile_init_method
9
+
10
+ installer::monitor_initialize_begin(defined_in_file, internal_hash, &block)
11
+ result = xold_podfile_init_method.bind(self).(defined_in_file, internal_hash, &block)
12
+ installer::monitor_initialize_end(defined_in_file, internal_hash, &block)
13
+ result
14
+ end
15
+
16
+ module DSL
17
+
18
+ xold_target_method = instance_method(:target)
19
+ define_method(:target) do |name, options = nil, &block|
20
+ installer = Pod::X::Installer::installer
21
+ installer.target_self = self
22
+ installer.target_method = xold_target_method
23
+
24
+ installer::monitor_target_begin(name, options, &block)
25
+ result = xold_target_method.bind(self).(name, options, &block)
26
+ installer::monitor_target_end(name, options, &block)
27
+ result
28
+ end
29
+
30
+ xold_pod_method = instance_method(:pod)
31
+ define_method(:pod) do |name, *requirements|
32
+ installer = Pod::X::Installer::installer
33
+ installer.pod_self = self
34
+ installer.pod_method = xold_pod_method
35
+
36
+ path = installer::monitor_pod_begin(name, *requirements)
37
+ if path
38
+ result = xold_pod_method.bind(self).(name, :path => path)
39
+ else
40
+ result = xold_pod_method.bind(self).(name, *requirements)
41
+ end
42
+ installer::monitor_pod_end(name, *requirements)
43
+ result
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
50
+ module Pod
51
+ class Installer
52
+
53
+ xold_print_post_install_message_method = instance_method(:print_post_install_message)
54
+ define_method(:print_post_install_message) do
55
+ installer = Pod::X::Installer::installer
56
+ installer.print_post_install_message_self = self
57
+ installer.print_post_install_message_method = xold_print_post_install_message_method
58
+
59
+ installer::monitor_print_post_install_message_begin()
60
+ result = xold_print_post_install_message_method.bind(self).()
61
+ installer::monitor_print_post_install_message_end()
62
+ result
63
+ end
64
+
65
+ end
66
+ end
@@ -38,7 +38,7 @@ module Pod
38
38
  end
39
39
 
40
40
  def source_file
41
- root + 'source'
41
+ root + 'sources'
42
42
  end
43
43
 
44
44
  def project_name
@@ -7,6 +7,8 @@ module Pod
7
7
 
8
8
  include Pod::X::Sandbox::Protocol
9
9
 
10
+ Repo = Struct::new(:name, :repo_url, :location_url)
11
+
10
12
  def initialize url
11
13
  super File.join(url, 'repos')
12
14
  end
@@ -19,39 +21,61 @@ module Pod
19
21
 
20
22
  end
21
23
 
22
- def pod_path! name, version, share, repo_url
23
- host = hostname(repo_url)
24
- to = root + "#{host}/#{name}"
25
- to
26
- end
24
+ def self.Repo name, pod_argv, source_argv, workspace, project
25
+ return nil if pod_argv.nil?
27
26
 
28
- def pod_path_clone! name, version, share, repo_url
29
- to = pod_path!(name, version, share, repo_url)
30
- rm! ['-rf', to]
31
- pod_clone!(name, repo_url, to)
32
- to
33
- end
27
+ location_url = pod_argv[:path]
28
+ return Repo::new(name, nil, location_url) unless location_url.nil?
34
29
 
35
- private
30
+ repo_url = pod_argv[:source]
31
+ return Repo::new(name, repo_url, LocationUrl(name, repo_url, pod_argv, workspace, project)) unless repo_url.nil?
36
32
 
37
- def pod_clone! name, repo_url, to
38
- UI.section("Pod::X Cloning #{name}.".green) do
39
- git! ['clone', repo_url, to]
40
- end
41
- unless (to + '.git').exist?
42
- raise Informative, "Clone failed."
33
+ return Repo::new(name, nil, nil) if source_argv.nil?
34
+
35
+ git_name = source_argv[:git]
36
+ return Repo::new(name, nil, nil) if git_name.nil?
37
+
38
+ group_name = source_argv[:group]
39
+ return Repo::new(name, nil, nil) if group_name.nil?
40
+
41
+ domain_name = source_argv[:domain]
42
+ return Repo::new(name, nil, nil) if domain_name.nil?
43
+
44
+ if domain_name.start_with? "git@"
45
+ repo_url = RepoGitUrl(domain_name, group_name, git_name)
46
+ else
47
+ repo_url = RepoHttpUrl(domain_name, group_name, git_name)
43
48
  end
49
+
50
+ Repo::new(name, repo_url, LocationUrl(name, repo_url, pod_argv, workspace, project))
51
+ end
52
+
53
+ private
54
+
55
+ def self.LocationUrl name, repo_url, pod_argv, workspace, project
56
+ hostname = Hostname(repo_url)
57
+ root = pod_argv[:share] ? workspace::repos::root : project::repos::root
58
+ (root + "#{hostname}/#{name}").to_s
44
59
  end
45
60
 
46
- def hostname source
47
- if source.start_with? 'git@'
48
- source = source.gsub ':', '/'
49
- source = source.gsub 'git@', 'https://'
61
+ def self.Hostname repo_url
62
+ url = repo_url
63
+ if url.start_with? 'git@'
64
+ url = url.gsub ':', '/'
65
+ url = url.gsub 'git@', 'https://'
50
66
  end
51
- URI(source).hostname
67
+ URI(url).hostname
68
+ end
69
+
70
+ def self.RepoGitUrl domain_name, group_name, git_name
71
+ "#{domain_name}:#{group_name}/#{git_name}"
72
+ end
73
+
74
+ def self.RepoHttpUrl domain_name, group_name, git_name
75
+ "#{domain_name}/#{group_name}/#{git_name}"
52
76
  end
53
77
 
54
78
  end
55
79
  end
56
80
  end
57
- end
81
+ end
@@ -23,7 +23,7 @@ module Pod
23
23
  end
24
24
 
25
25
  def source_file
26
- root + 'Projects/podfile/source'
26
+ root + 'Projects/podfile/sources'
27
27
  end
28
28
 
29
29
  def pods_file
@@ -62,7 +62,7 @@ module Pod
62
62
 
63
63
  def clone_template! to
64
64
  repo_url = 'https://github.com/CocoaPodsX/project-template.git'
65
- UI.section("Cloning `#{repo_url}`.") do
65
+ UI.section('Pod::X '.blue + "Cloning `#{repo_url}`.") do
66
66
  git! ['clone', '--depth=1', repo_url, to]
67
67
  end
68
68