shopify-bundler 1.10.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +96 -0
  5. data/.rubocop_todo.yml +177 -0
  6. data/.travis.yml +104 -0
  7. data/CHANGELOG.md +2131 -0
  8. data/CODE_OF_CONDUCT.md +42 -0
  9. data/CONTRIBUTING.md +32 -0
  10. data/DEVELOPMENT.md +118 -0
  11. data/ISSUES.md +96 -0
  12. data/LICENSE.md +23 -0
  13. data/README.md +40 -0
  14. data/Rakefile +309 -0
  15. data/bin/rake +14 -0
  16. data/bin/rspec +10 -0
  17. data/bin/rubocop +11 -0
  18. data/bundler.gemspec +34 -0
  19. data/exe/bundle +21 -0
  20. data/exe/bundle_ruby +60 -0
  21. data/exe/bundler +21 -0
  22. data/lib/bundler.rb +499 -0
  23. data/lib/bundler/capistrano.rb +16 -0
  24. data/lib/bundler/cli.rb +435 -0
  25. data/lib/bundler/cli/binstubs.rb +37 -0
  26. data/lib/bundler/cli/cache.rb +34 -0
  27. data/lib/bundler/cli/check.rb +37 -0
  28. data/lib/bundler/cli/clean.rb +25 -0
  29. data/lib/bundler/cli/common.rb +56 -0
  30. data/lib/bundler/cli/config.rb +88 -0
  31. data/lib/bundler/cli/console.rb +37 -0
  32. data/lib/bundler/cli/exec.rb +51 -0
  33. data/lib/bundler/cli/gem.rb +208 -0
  34. data/lib/bundler/cli/init.rb +32 -0
  35. data/lib/bundler/cli/inject.rb +32 -0
  36. data/lib/bundler/cli/install.rb +188 -0
  37. data/lib/bundler/cli/lock.rb +35 -0
  38. data/lib/bundler/cli/open.rb +22 -0
  39. data/lib/bundler/cli/outdated.rb +86 -0
  40. data/lib/bundler/cli/package.rb +45 -0
  41. data/lib/bundler/cli/platform.rb +42 -0
  42. data/lib/bundler/cli/show.rb +74 -0
  43. data/lib/bundler/cli/update.rb +72 -0
  44. data/lib/bundler/cli/viz.rb +26 -0
  45. data/lib/bundler/constants.rb +5 -0
  46. data/lib/bundler/current_ruby.rb +218 -0
  47. data/lib/bundler/definition.rb +675 -0
  48. data/lib/bundler/dep_proxy.rb +45 -0
  49. data/lib/bundler/dependency.rb +119 -0
  50. data/lib/bundler/deployment.rb +62 -0
  51. data/lib/bundler/deprecate.rb +17 -0
  52. data/lib/bundler/dsl.rb +478 -0
  53. data/lib/bundler/endpoint_specification.rb +100 -0
  54. data/lib/bundler/env.rb +82 -0
  55. data/lib/bundler/environment.rb +41 -0
  56. data/lib/bundler/fetcher.rb +288 -0
  57. data/lib/bundler/fetcher/base.rb +26 -0
  58. data/lib/bundler/fetcher/dependency.rb +88 -0
  59. data/lib/bundler/fetcher/downloader.rb +60 -0
  60. data/lib/bundler/fetcher/index.rb +32 -0
  61. data/lib/bundler/friendly_errors.rb +92 -0
  62. data/lib/bundler/gem_helper.rb +191 -0
  63. data/lib/bundler/gem_helpers.rb +26 -0
  64. data/lib/bundler/gem_installer.rb +9 -0
  65. data/lib/bundler/gem_path_manipulation.rb +8 -0
  66. data/lib/bundler/gem_tasks.rb +5 -0
  67. data/lib/bundler/graph.rb +173 -0
  68. data/lib/bundler/index.rb +199 -0
  69. data/lib/bundler/injector.rb +62 -0
  70. data/lib/bundler/inline.rb +58 -0
  71. data/lib/bundler/installer.rb +242 -0
  72. data/lib/bundler/installer/parallel_installer.rb +122 -0
  73. data/lib/bundler/installer/standalone.rb +48 -0
  74. data/lib/bundler/lazy_specification.rb +82 -0
  75. data/lib/bundler/lockfile_parser.rb +199 -0
  76. data/lib/bundler/match_platform.rb +13 -0
  77. data/lib/bundler/psyched_yaml.rb +26 -0
  78. data/lib/bundler/remote_specification.rb +82 -0
  79. data/lib/bundler/resolver.rb +350 -0
  80. data/lib/bundler/retry.rb +60 -0
  81. data/lib/bundler/ruby_dsl.rb +11 -0
  82. data/lib/bundler/ruby_version.rb +116 -0
  83. data/lib/bundler/rubygems_ext.rb +175 -0
  84. data/lib/bundler/rubygems_integration.rb +674 -0
  85. data/lib/bundler/runtime.rb +285 -0
  86. data/lib/bundler/settings.rb +263 -0
  87. data/lib/bundler/setup.rb +26 -0
  88. data/lib/bundler/shared_helpers.rb +176 -0
  89. data/lib/bundler/similarity_detector.rb +61 -0
  90. data/lib/bundler/source.rb +35 -0
  91. data/lib/bundler/source/git.rb +286 -0
  92. data/lib/bundler/source/git/git_proxy.rb +190 -0
  93. data/lib/bundler/source/path.rb +224 -0
  94. data/lib/bundler/source/path/installer.rb +43 -0
  95. data/lib/bundler/source/rubygems.rb +436 -0
  96. data/lib/bundler/source/rubygems/remote.rb +38 -0
  97. data/lib/bundler/source_list.rb +101 -0
  98. data/lib/bundler/spec_set.rb +156 -0
  99. data/lib/bundler/ssl_certs/.document +1 -0
  100. data/lib/bundler/ssl_certs/AddTrustExternalCARoot-2048.pem +25 -0
  101. data/lib/bundler/ssl_certs/AddTrustExternalCARoot.pem +32 -0
  102. data/lib/bundler/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +14 -0
  103. data/lib/bundler/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +23 -0
  104. data/lib/bundler/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +28 -0
  105. data/lib/bundler/ssl_certs/GeoTrustGlobalCA.pem +20 -0
  106. data/lib/bundler/ssl_certs/certificate_manager.rb +64 -0
  107. data/lib/bundler/stub_specification.rb +23 -0
  108. data/lib/bundler/templates/Executable +16 -0
  109. data/lib/bundler/templates/Executable.standalone +12 -0
  110. data/lib/bundler/templates/Gemfile +4 -0
  111. data/lib/bundler/templates/newgem/.travis.yml.tt +4 -0
  112. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +22 -0
  113. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  114. data/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
  115. data/lib/bundler/templates/newgem/README.md.tt +41 -0
  116. data/lib/bundler/templates/newgem/Rakefile.tt +29 -0
  117. data/lib/bundler/templates/newgem/bin/console.tt +14 -0
  118. data/lib/bundler/templates/newgem/bin/setup.tt +8 -0
  119. data/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
  120. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  121. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  122. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  123. data/lib/bundler/templates/newgem/gitignore.tt +16 -0
  124. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  125. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  126. data/lib/bundler/templates/newgem/newgem.gemspec.tt +43 -0
  127. data/lib/bundler/templates/newgem/rspec.tt +2 -0
  128. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  129. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  130. data/lib/bundler/templates/newgem/test/newgem_test.rb.tt +11 -0
  131. data/lib/bundler/templates/newgem/test/test_helper.rb.tt +4 -0
  132. data/lib/bundler/ui.rb +7 -0
  133. data/lib/bundler/ui/rg_proxy.rb +17 -0
  134. data/lib/bundler/ui/shell.rb +108 -0
  135. data/lib/bundler/ui/silent.rb +44 -0
  136. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +5 -0
  137. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +277 -0
  138. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +69 -0
  139. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +3 -0
  140. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +99 -0
  141. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +63 -0
  142. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +434 -0
  143. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +43 -0
  144. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +51 -0
  145. data/lib/bundler/vendor/net/http/faster.rb +26 -0
  146. data/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  147. data/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  148. data/lib/bundler/vendor/thor/lib/thor.rb +484 -0
  149. data/lib/bundler/vendor/thor/lib/thor/actions.rb +319 -0
  150. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  151. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  152. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +118 -0
  153. data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  154. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +316 -0
  155. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +107 -0
  156. data/lib/bundler/vendor/thor/lib/thor/base.rb +656 -0
  157. data/lib/bundler/vendor/thor/lib/thor/command.rb +133 -0
  158. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  159. data/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +10 -0
  160. data/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +98 -0
  161. data/lib/bundler/vendor/thor/lib/thor/error.rb +32 -0
  162. data/lib/bundler/vendor/thor/lib/thor/group.rb +281 -0
  163. data/lib/bundler/vendor/thor/lib/thor/invocation.rb +178 -0
  164. data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
  165. data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  166. data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  167. data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
  168. data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +73 -0
  169. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  170. data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +125 -0
  171. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +218 -0
  172. data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +71 -0
  173. data/lib/bundler/vendor/thor/lib/thor/runner.rb +322 -0
  174. data/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
  175. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +421 -0
  176. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +149 -0
  177. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +126 -0
  178. data/lib/bundler/vendor/thor/lib/thor/util.rb +267 -0
  179. data/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
  180. data/lib/bundler/vendored_molinillo.rb +2 -0
  181. data/lib/bundler/vendored_persistent.rb +11 -0
  182. data/lib/bundler/vendored_thor.rb +3 -0
  183. data/lib/bundler/version.rb +6 -0
  184. data/lib/bundler/vlad.rb +11 -0
  185. data/lib/bundler/worker.rb +72 -0
  186. data/man/bundle-config.ronn +187 -0
  187. data/man/bundle-exec.ronn +136 -0
  188. data/man/bundle-gem.ronn +77 -0
  189. data/man/bundle-install.ronn +398 -0
  190. data/man/bundle-package.ronn +66 -0
  191. data/man/bundle-platform.ronn +42 -0
  192. data/man/bundle-update.ronn +188 -0
  193. data/man/bundle.ronn +98 -0
  194. data/man/gemfile.5.ronn +495 -0
  195. data/man/index.txt +8 -0
  196. metadata +346 -0
@@ -0,0 +1,37 @@
1
+ require "bundler/cli/common"
2
+
3
+ module Bundler
4
+ class CLI::Binstubs
5
+ attr_reader :options, :gems
6
+ def initialize(options, gems)
7
+ @options = options
8
+ @gems = gems
9
+ end
10
+
11
+ def run
12
+ Bundler.definition.validate_ruby!
13
+ Bundler.settings[:bin] = options["path"] if options["path"]
14
+ Bundler.settings[:bin] = nil if options["path"] && options["path"].empty?
15
+ installer = Installer.new(Bundler.root, Bundler.definition)
16
+
17
+ if gems.empty?
18
+ Bundler.ui.error "`bundle binstubs` needs at least one gem to run."
19
+ exit 1
20
+ end
21
+
22
+ gems.each do |gem_name|
23
+ spec = installer.specs.find {|s| s.name == gem_name }
24
+ unless spec
25
+ raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(
26
+ gem_name, Bundler.definition.specs)
27
+ end
28
+
29
+ if spec.name == "bundler"
30
+ Bundler.ui.warn "Sorry, Bundler can only be run via Rubygems."
31
+ else
32
+ installer.generate_bundler_executable_stubs(spec, :force => options[:force], :binstubs_cmd => true)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ module Bundler
2
+ class CLI::Cache
3
+ attr_reader :options
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def run
9
+ Bundler.definition.validate_ruby!
10
+ Bundler.definition.resolve_with_cache!
11
+ setup_cache_all
12
+ Bundler.settings[:cache_all_platforms] = options["all-platforms"] if options.key?("all-platforms")
13
+ Bundler.load.cache
14
+ Bundler.settings[:no_prune] = true if options["no-prune"]
15
+ Bundler.load.lock
16
+ rescue GemNotFound => e
17
+ Bundler.ui.error(e.message)
18
+ Bundler.ui.warn "Run `bundle install` to install missing gems."
19
+ exit 1
20
+ end
21
+
22
+ private
23
+
24
+ def setup_cache_all
25
+ Bundler.settings[:cache_all] = options[:all] if options.key?("all")
26
+
27
+ if Bundler.definition.has_local_dependencies? && !Bundler.settings[:cache_all]
28
+ Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \
29
+ "to package them as well, please pass the --all flag. This will be the default " \
30
+ "on Bundler 2.0."
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module Bundler
2
+ class CLI::Check
3
+ attr_reader :options
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def run
9
+ if options[:path]
10
+ Bundler.settings[:path] = File.expand_path(options[:path])
11
+ Bundler.settings[:disable_shared_gems] = "1"
12
+ end
13
+ begin
14
+ definition = Bundler.definition
15
+ definition.validate_ruby!
16
+ not_installed = definition.missing_specs
17
+ rescue GemNotFound, VersionConflict
18
+ Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies."
19
+ Bundler.ui.warn "Install missing gems with `bundle install`."
20
+ exit 1
21
+ end
22
+
23
+ if not_installed.any?
24
+ Bundler.ui.error "The following gems are missing"
25
+ not_installed.each {|s| Bundler.ui.error " * #{s.name} (#{s.version})" }
26
+ Bundler.ui.warn "Install missing gems with `bundle install`"
27
+ exit 1
28
+ elsif !Bundler.default_lockfile.exist? && Bundler.settings[:frozen]
29
+ Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} present"
30
+ exit 1
31
+ else
32
+ Bundler.load.lock(:preserve_bundled_with => true) unless options[:"dry-run"]
33
+ Bundler.ui.info "The Gemfile's dependencies are satisfied"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ module Bundler
2
+ class CLI::Clean
3
+ attr_reader :options
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def run
10
+ require_path_or_force
11
+ Bundler.load.clean(options[:"dry-run"])
12
+ end
13
+
14
+ protected
15
+
16
+ def require_path_or_force
17
+ if !Bundler.settings[:path] && !options[:force]
18
+ Bundler.ui.error "Cleaning all the gems on your system is dangerous! " \
19
+ "If you're sure you want to remove every system gem not in this " \
20
+ "bundle, run `bundle clean --force`."
21
+ exit 1
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,56 @@
1
+ module Bundler
2
+ module CLI::Common
3
+ def self.without_groups_message
4
+ groups = Bundler.settings.without
5
+ group_list = [groups[0...-1].join(", "), groups[-1..-1]].
6
+ reject {|s| s.to_s.empty? }.join(" and ")
7
+ group_str = (groups.size == 1) ? "group" : "groups"
8
+ "Gems in the #{group_str} #{group_list} were not installed."
9
+ end
10
+
11
+ def self.select_spec(name, regex_match = nil)
12
+ specs = []
13
+ regexp = Regexp.new(name) if regex_match
14
+
15
+ Bundler.definition.specs.each do |spec|
16
+ return spec if spec.name == name
17
+ specs << spec if regexp && spec.name =~ regexp
18
+ end
19
+
20
+ case specs.count
21
+ when 0
22
+ raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
23
+ when 1
24
+ specs.first
25
+ else
26
+ ask_for_spec_from(specs)
27
+ end
28
+ rescue RegexpError
29
+ raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
30
+ end
31
+
32
+ def self.ask_for_spec_from(specs)
33
+ if !$stdout.tty? && ENV["BUNDLE_SPEC_RUN"].nil?
34
+ raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
35
+ end
36
+
37
+ specs.each_with_index do |spec, index|
38
+ Bundler.ui.info "#{index.succ} : #{spec.name}", true
39
+ end
40
+ Bundler.ui.info "0 : - exit -", true
41
+
42
+ num = Bundler.ui.ask("> ").to_i
43
+ num > 0 ? specs[num - 1] : nil
44
+ end
45
+
46
+ def self.gem_not_found_message(missing_gem_name, alternatives)
47
+ require "bundler/similarity_detector"
48
+ message = "Could not find gem '#{missing_gem_name}'."
49
+ alternate_names = alternatives.map {|a| a.respond_to?(:name) ? a.name : a }
50
+ suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name)
51
+ message += "\nDid you mean #{suggestions}?" if suggestions
52
+ message
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,88 @@
1
+ module Bundler
2
+ class CLI::Config
3
+ attr_reader :options, :thor
4
+ attr_accessor :args
5
+
6
+ def initialize(options, args, thor)
7
+ @options = options
8
+ @args = args
9
+ @thor = thor
10
+ end
11
+
12
+ def run
13
+ peek = args.shift
14
+
15
+ if peek && peek =~ /^\-\-/
16
+ name = args.shift
17
+ scope = $'
18
+ else
19
+ name = peek
20
+ scope = "global"
21
+ end
22
+
23
+ unless name
24
+ Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n"
25
+
26
+ Bundler.settings.all.each do |setting|
27
+ Bundler.ui.confirm "#{setting}"
28
+ thor.with_padding do
29
+ Bundler.settings.pretty_values_for(setting).each do |line|
30
+ Bundler.ui.info line
31
+ end
32
+ end
33
+ Bundler.ui.confirm ""
34
+ end
35
+ return
36
+ end
37
+
38
+ case scope
39
+ when "delete"
40
+ Bundler.settings.set_local(name, nil)
41
+ Bundler.settings.set_global(name, nil)
42
+ when "local", "global"
43
+ if args.empty?
44
+ Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used"
45
+ thor.with_padding do
46
+ Bundler.settings.pretty_values_for(name).each {|line| Bundler.ui.info line }
47
+ end
48
+ return
49
+ end
50
+
51
+ new_value = args.join(" ")
52
+ locations = Bundler.settings.locations(name)
53
+
54
+ if scope == "global"
55
+ if locations[:local]
56
+ Bundler.ui.info "Your application has set #{name} to #{locations[:local].inspect}. " \
57
+ "This will override the global value you are currently setting"
58
+ end
59
+
60
+ if locations[:env]
61
+ Bundler.ui.info "You have a bundler environment variable for #{name} set to " \
62
+ "#{locations[:env].inspect}. This will take precedence over the global value you are setting"
63
+ end
64
+
65
+ if locations[:global] && locations[:global] != new_value
66
+ Bundler.ui.info "You are replacing the current global value of #{name}, which is currently " \
67
+ "#{locations[:global].inspect}"
68
+ end
69
+ end
70
+
71
+ if scope == "local" && locations[:local] != new_value
72
+ Bundler.ui.info "You are replacing the current local value of #{name}, which is currently " \
73
+ "#{locations[:local].inspect}"
74
+ end
75
+
76
+ if name.match(/\Alocal\./)
77
+ pathname = Pathname.new(args.join(" "))
78
+ new_value = pathname.expand_path.to_s if pathname.directory?
79
+ end
80
+
81
+ Bundler.settings.send("set_#{scope}", name, new_value)
82
+ else
83
+ Bundler.ui.error "Invalid scope --#{scope} given. Please use --local or --global."
84
+ exit 1
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,37 @@
1
+ module Bundler
2
+ class CLI::Console
3
+ attr_reader :options, :group
4
+ def initialize(options, group)
5
+ @options = options
6
+ @group = group
7
+ end
8
+
9
+ def run
10
+ group ? Bundler.require(:default, *(group.split.map!(&:to_sym))) : Bundler.require
11
+ ARGV.clear
12
+
13
+ console = get_console(Bundler.settings[:console] || "irb")
14
+ console.start
15
+ end
16
+
17
+ def get_console(name)
18
+ require name
19
+ get_constant(name)
20
+ rescue LoadError
21
+ Bundler.ui.error "Couldn't load console #{name}"
22
+ get_constant("irb")
23
+ end
24
+
25
+ def get_constant(name)
26
+ const_name = {
27
+ "pry" => :Pry,
28
+ "ripl" => :Ripl,
29
+ "irb" => :IRB,
30
+ }[name]
31
+ Object.const_get(const_name)
32
+ rescue NameError
33
+ Bundler.ui.error "Could not find constant #{const_name}"
34
+ exit 1
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ require "bundler/current_ruby"
2
+
3
+ module Bundler
4
+ class CLI::Exec
5
+ attr_reader :options, :args, :cmd
6
+
7
+ def initialize(options, args)
8
+ @options = options
9
+ @cmd = args.shift
10
+ @args = args
11
+
12
+ if Bundler.current_ruby.ruby_2? && !Bundler.current_ruby.jruby?
13
+ @args << { :close_others => !options.keep_file_descriptors? }
14
+ elsif options.keep_file_descriptors?
15
+ Bundler.ui.warn "Ruby version #{RUBY_VERSION} defaults to keeping non-standard file descriptors on Kernel#exec."
16
+ end
17
+ end
18
+
19
+ def run
20
+ ui = Bundler.ui
21
+ raise ArgumentError if cmd.nil?
22
+
23
+ # First, try to exec directly to something in PATH
24
+ SharedHelpers.set_bundle_environment
25
+ bin_path = Bundler.which(@cmd)
26
+ if bin_path
27
+ Bundler.ui = nil
28
+ Kernel.exec(bin_path, *args)
29
+ end
30
+
31
+ # If that didn't work, set up the whole bundle
32
+ Bundler.definition.validate_ruby!
33
+ Bundler.load.setup_environment
34
+ Bundler.ui = nil
35
+ Kernel.exec(@cmd, *args)
36
+ rescue Errno::EACCES
37
+ Bundler.ui = ui
38
+ Bundler.ui.error "bundler: not executable: #{cmd}"
39
+ exit 126
40
+ rescue Errno::ENOENT
41
+ Bundler.ui = ui
42
+ Bundler.ui.error "bundler: command not found: #{cmd}"
43
+ Bundler.ui.warn "Install missing gem executables with `bundle install`"
44
+ exit 127
45
+ rescue ArgumentError
46
+ Bundler.ui = ui
47
+ Bundler.ui.error "bundler: exec needs a command to run"
48
+ exit 128
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,208 @@
1
+ require "pathname"
2
+
3
+ module Bundler
4
+ class CLI::Gem
5
+ TEST_FRAMEWORK_VERSIONS = {
6
+ "rspec" => "3.0",
7
+ "minitest" => "5.0"
8
+ }
9
+
10
+ attr_reader :options, :gem_name, :thor, :name, :target
11
+
12
+ def initialize(options, gem_name, thor)
13
+ @options = options
14
+ @gem_name = resolve_name(gem_name)
15
+ @thor = thor
16
+
17
+ @name = @gem_name
18
+ @target = SharedHelpers.pwd.join(gem_name)
19
+
20
+ validate_ext_name if options[:ext]
21
+ end
22
+
23
+ def run
24
+ Bundler.ui.confirm "Creating gem '#{name}'..."
25
+
26
+ underscored_name = name.tr("-", "_")
27
+ namespaced_path = name.tr("-", "/")
28
+ constant_name = name.gsub(/-[_-]*(?![_-]|$)/) { "::" }.gsub(/([_-]+|(::)|^)(.|$)/) { $2.to_s + $3.upcase }
29
+ constant_array = constant_name.split("::")
30
+ test_task = options[:test] == "minitest" ? "test" : "spec"
31
+
32
+ git_user_name = `git config user.name`.chomp
33
+ git_user_email = `git config user.email`.chomp
34
+
35
+ config = {
36
+ :name => name,
37
+ :underscored_name => underscored_name,
38
+ :namespaced_path => namespaced_path,
39
+ :makefile_path => "#{underscored_name}/#{underscored_name}",
40
+ :constant_name => constant_name,
41
+ :constant_array => constant_array,
42
+ :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
43
+ :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
44
+ :test => options[:test],
45
+ :test_task => test_task,
46
+ :ext => options[:ext],
47
+ :bin => options[:bin],
48
+ :bundler_version => bundler_dependency_version
49
+ }
50
+ ensure_safe_gem_name(name, constant_array)
51
+
52
+ templates = {
53
+ "Gemfile.tt" => "Gemfile",
54
+ "gitignore.tt" => ".gitignore",
55
+ "lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb",
56
+ "lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb",
57
+ "newgem.gemspec.tt" => "#{name}.gemspec",
58
+ "Rakefile.tt" => "Rakefile",
59
+ "README.md.tt" => "README.md",
60
+ "bin/console.tt" => "bin/console",
61
+ "bin/setup.tt" => "bin/setup"
62
+ }
63
+
64
+ executables = %w[
65
+ bin/console
66
+ bin/setup
67
+ ]
68
+
69
+ if test_framework = ask_and_set_test_framework
70
+ config[:test] = test_framework
71
+ config[:test_framework_version] = TEST_FRAMEWORK_VERSIONS[test_framework]
72
+
73
+ templates.merge!(".travis.yml.tt" => ".travis.yml")
74
+
75
+ case test_framework
76
+ when "rspec"
77
+ templates.merge!(
78
+ "rspec.tt" => ".rspec",
79
+ "spec/spec_helper.rb.tt" => "spec/spec_helper.rb",
80
+ "spec/newgem_spec.rb.tt" => "spec/#{namespaced_path}_spec.rb"
81
+ )
82
+ when "minitest"
83
+ templates.merge!(
84
+ "test/test_helper.rb.tt" => "test/test_helper.rb",
85
+ "test/newgem_test.rb.tt" => "test/#{namespaced_path}_test.rb"
86
+ )
87
+ end
88
+ end
89
+
90
+ if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?",
91
+ "This means that any other developer or company will be legally allowed to use your code " \
92
+ "for free as long as they admit you created it. You can read more about the MIT license " \
93
+ "at http://choosealicense.com/licenses/mit.")
94
+ config[:mit] = true
95
+ Bundler.ui.info "MIT License enabled in config"
96
+ templates.merge!("LICENSE.txt.tt" => "LICENSE.txt")
97
+ end
98
+
99
+ if ask_and_set(:coc, "Do you want to include a code of conduct in gems you generate?",
100
+ "Codes of conduct can increase contributions to your project by contributors who " \
101
+ "prefer collaborative, safe spaces. You can read more about the code of conduct at " \
102
+ "contributor-covenant.org. Having a code of conduct means agreeing to the responsibility " \
103
+ "of enforcing it, so be sure that you are prepared to do that. For suggestions about " \
104
+ "how to enforce codes of conduct, see http://bit.ly/coc-enforcement.")
105
+ config[:coc] = true
106
+ Bundler.ui.info "Code of conduct enabled in config"
107
+ templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md")
108
+ end
109
+
110
+ templates.merge!("exe/newgem.tt" => "exe/#{name}") if options[:bin]
111
+
112
+ if options[:ext]
113
+ templates.merge!(
114
+ "ext/newgem/extconf.rb.tt" => "ext/#{name}/extconf.rb",
115
+ "ext/newgem/newgem.h.tt" => "ext/#{name}/#{underscored_name}.h",
116
+ "ext/newgem/newgem.c.tt" => "ext/#{name}/#{underscored_name}.c"
117
+ )
118
+ end
119
+
120
+ templates.each do |src, dst|
121
+ thor.template("newgem/#{src}", target.join(dst), config)
122
+ end
123
+
124
+ executables.each do |file|
125
+ path = target.join(file)
126
+ executable = (path.stat.mode | 0111)
127
+ path.chmod(executable)
128
+ end
129
+
130
+ Bundler.ui.info "Initializing git repo in #{target}"
131
+ Dir.chdir(target) do
132
+ `git init`
133
+ `git add .`
134
+ end
135
+
136
+ if options[:edit]
137
+ # Open gemspec in editor
138
+ thor.run("#{options["edit"]} \"#{target.join("#{name}.gemspec")}\"")
139
+ end
140
+ end
141
+
142
+ private
143
+
144
+ def resolve_name(name)
145
+ SharedHelpers.pwd.join(name).basename.to_s
146
+ end
147
+
148
+ def ask_and_set(key, header, message)
149
+ choice = options[key] || Bundler.settings["gem.#{key}"]
150
+
151
+ if choice.nil?
152
+ Bundler.ui.confirm header
153
+ choice = Bundler.ui.yes? "#{message} y/(n):"
154
+ Bundler.settings.set_global("gem.#{key}", choice)
155
+ end
156
+
157
+ choice
158
+ end
159
+
160
+ def validate_ext_name
161
+ return unless gem_name.index("-")
162
+
163
+ Bundler.ui.error "You have specified a gem name which does not conform to the \n" \
164
+ "naming guidelines for C extensions. For more information, \n" \
165
+ "see the 'Extension Naming' section at the following URL:\n" \
166
+ "http://guides.rubygems.org/gems-with-extensions/\n"
167
+ exit 1
168
+ end
169
+
170
+ def ask_and_set_test_framework
171
+ test_framework = options[:test] || Bundler.settings["gem.test"]
172
+
173
+ if test_framework.nil?
174
+ Bundler.ui.confirm "Do you want to generate tests with your gem?"
175
+ result = Bundler.ui.ask "Type 'rspec' or 'minitest' to generate those test files now and " \
176
+ "in the future. rspec/minitest/(none):"
177
+ if result =~ /rspec|minitest/
178
+ test_framework = result
179
+ else
180
+ test_framework = false
181
+ end
182
+ end
183
+
184
+ if Bundler.settings["gem.test"].nil?
185
+ Bundler.settings.set_global("gem.test", test_framework)
186
+ end
187
+
188
+ test_framework
189
+ end
190
+
191
+ def bundler_dependency_version
192
+ v = Gem::Version.new(Bundler::VERSION)
193
+ req = v.segments[0..1]
194
+ req << "a" if v.prerelease?
195
+ req.join(".")
196
+ end
197
+
198
+ def ensure_safe_gem_name(name, constant_array)
199
+ if name =~ /^\d/
200
+ Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
201
+ exit 1
202
+ elsif constant_array.inject(Object) {|c, s| (c.const_defined?(s) && c.const_get(s)) || break }
203
+ Bundler.ui.error "Invalid gem name #{name} constant #{constant_array.join("::")} is already in use. Please choose another gem name."
204
+ exit 1
205
+ end
206
+ end
207
+ end
208
+ end