prebundler 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3c5ee33f4d7882d485b63b1e901011124c6368f5
4
- data.tar.gz: 9f1aa9f618e12120df3d4f44b9ef14feea919adc
2
+ SHA256:
3
+ metadata.gz: c9a5176ed10e63f0c2ef47923ecf4c932eb27c7e368db4ddc2f1c62fff497026
4
+ data.tar.gz: e9f08a38bae954b4dfb760d1294a2f75d78ee09a0a4ec411e49fe66f00891d7f
5
5
  SHA512:
6
- metadata.gz: 1213007d2b97d513b63e467dabc12fe087b0284ddefb2a522dc4ec224e95f5536a302a642ca42f2cc1296203d69fe26cbe38f1952722e9aba8ad34229b6046de
7
- data.tar.gz: e907371cf4ec061626c3b6524b6f6bef246a44121876dc873f51cbdbdf043d47d1a940d42e1b75ce2e716056f8ad63f187ed8f898d37e8364017eea759ab7fbf
6
+ metadata.gz: 8458d9dc7a78856efea8144e0e0d45ba44142723aae99164c85ee60e01158571e22253e24e5100daadcc81e7c678b8a86c641f1ad3e463c0414fe9f7713aa0d0
7
+ data.tar.gz: 61739fa529e3c01a7c36b09e25276dea81952a328aba145e3df76bbc13a5cff9d4bf038f71d17dc62db38e52bdfafe31c3203033cffbd44ddcd01014c5b4d712
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.8.0
2
+ ===
3
+ - Add the subset command for generating subsets of gemfiles.
4
+
1
5
  0.7.2
2
6
  ===
3
7
  - Fix use of continuation token when listing remote files in S3 backend.
data/bin/prebundle CHANGED
@@ -71,6 +71,35 @@ command :list do |c|
71
71
  end
72
72
  end
73
73
 
74
+ desc 'Generate a subset of a Gemfile.'
75
+ command :subset do |c|
76
+ c.desc 'Path to the gemfile.'
77
+ c.default_value ENV.fetch('BUNDLE_GEMFILE', './Gemfile')
78
+ c.flag [:g, :gemfile]
79
+
80
+ c.desc 'Path to the bundle installation directory.'
81
+ c.default_value ENV.fetch('BUNDLE_PATH', Bundler.bundle_path.to_s)
82
+ c.flag [:b, :'bundle-path']
83
+
84
+ c.desc 'Gem (and dependencies) to include in the subset.'
85
+ c.flag [:i, :include], multiple: true
86
+
87
+ c.desc "Add an additional gem to the subset. The gem doesn't have to be part of the original Gemfile."
88
+ c.flag [:a, :add], multiple: true
89
+
90
+ c.desc 'Include development dependencies of subsetted gems.'
91
+ c.default_value false
92
+ c.switch [:d, :development]
93
+
94
+ c.desc 'File path to output the resulting Gemfile into. Use - for standard output.'
95
+ c.default_value '-'
96
+ c.flag [:o, :output]
97
+
98
+ c.action do |global_options, options, args|
99
+ Prebundler::Cli::Subset.run($out, global_options, options, args)
100
+ end
101
+ end
102
+
74
103
  pre do |global, command, options, args|
75
104
  # Pre logic here
76
105
  # Return true to proceed; false to abort and not call the
@@ -78,7 +107,7 @@ pre do |global, command, options, args|
78
107
  # Use skips_pre before a command to skip this block
79
108
  # on that command only
80
109
  $out.silence! if global[:silent]
81
- load global[:config]
110
+ load global[:config] unless global[:config]
82
111
  true
83
112
  end
84
113
 
@@ -0,0 +1,26 @@
1
+ module Prebundler
2
+ module Cli
3
+ class Subset < Base
4
+ def run
5
+ subset = Prebundler::GemfileSubset.from(options[:gemfile], bundle_path)
6
+
7
+ options[:include].each { |g| subset.include(g) }
8
+ options[:add].each { |a| subset.add_raw(a, group: 'https://rubygems.org') }
9
+
10
+ result = subset.to_gemfile(include_dev_deps: options[:development])
11
+
12
+ if options[:output].strip == '-'
13
+ out.write(result)
14
+ else
15
+ File.write(options[:output], result)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def bundle_path
22
+ options.fetch(:'bundle-path')
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,5 +3,6 @@ module Prebundler
3
3
  autoload :Base, 'prebundler/cli/base'
4
4
  autoload :Install, 'prebundler/cli/install'
5
5
  autoload :List, 'prebundler/cli/list'
6
+ autoload :Subset, 'prebundler/cli/subset'
6
7
  end
7
8
  end
@@ -25,6 +25,10 @@ module Prebundler
25
25
  @prefix = options[:prefix]
26
26
  end
27
27
 
28
+ def to_gem
29
+ "gem '#{name}', '= #{version}'"
30
+ end
31
+
28
32
  def dependencies
29
33
  @dependencies ||= []
30
34
  end
@@ -33,6 +37,8 @@ module Prebundler
33
37
  @source ||= DEFAULT_SOURCE
34
38
  end
35
39
 
40
+ alias_method :remote, :source
41
+
36
42
  def id
37
43
  "#{name}-#{version}"
38
44
  end
@@ -0,0 +1,90 @@
1
+ module Prebundler
2
+ class GemfileSubset
3
+ attr_reader :gemfile, :included_gems, :additional_gems, :raw
4
+
5
+ def self.from(*args)
6
+ new(GemfileInterpreter.interpret(*args))
7
+ end
8
+
9
+ def initialize(gemfile)
10
+ @gemfile = gemfile
11
+ @included_gems = []
12
+ @additional_gems = []
13
+ @raw = []
14
+ end
15
+
16
+ def include(gem_name)
17
+ @included_gems << gem_name
18
+ end
19
+
20
+ def add(gem_name, **params)
21
+ additional_gems << [gem_name, params]
22
+ end
23
+
24
+ def add_raw(str, group: nil)
25
+ raw << [str, group]
26
+ end
27
+
28
+ def to_gemfile(include_dev_deps: true)
29
+ deps = aggregate_deps(include_dev_deps)
30
+ groups = group_deps(deps)
31
+
32
+ additional_gems.each do |gem_name, params|
33
+ options = params.dup
34
+ version = options.delete(:version)
35
+ group = options.delete(:group)
36
+
37
+ requirements = ["gem '#{gem_name}'"]
38
+ requirements << "'#{version}'" if version
39
+ requirements += options.map { |k, v| "#{k}: '#{v}'" }
40
+
41
+ groups[group] << requirements.join(', ')
42
+ end
43
+
44
+ raw.each do |str, group|
45
+ groups[group] << str
46
+ end
47
+
48
+ ''.tap do |result|
49
+ (groups.keys - [nil]).each_with_index do |remote, idx|
50
+ result << "\n" if idx > 0
51
+ result << "source '#{remote}' do\n"
52
+ result << groups[remote].map { |g| " #{g}" }.join("\n")
53
+ result << "\nend\n"
54
+ end
55
+
56
+ unless groups[nil].empty?
57
+ result << "\n"
58
+ result << groups[nil].join("\n")
59
+ result << "\n"
60
+ end
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def group_deps(deps)
67
+ Hash.new { |h, k| h[k] = [] }.tap do |ret|
68
+ deps.each do |dep|
69
+ if spec = gemfile.gems[dep.name]
70
+ ret[spec.remote] << spec.to_gem
71
+ else
72
+ req_str = dep.requirements_list.map { |r| "'#{r}'" }.join(', ')
73
+ ret[nil] << "gem '#{dep.name}', #{req_str}"
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ def aggregate_deps(include_dev_deps)
80
+ Set.new.tap do |result|
81
+ included_gems.each do |included_gem_name|
82
+ gemfile.gems[included_gem_name].gemspecs.each do |gemspec|
83
+ result.merge(gemspec.runtime_dependencies)
84
+ result.merge(gemspec.development_dependencies) if include_dev_deps
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -33,6 +33,10 @@ module Prebundler
33
33
  $?
34
34
  end
35
35
 
36
+ def to_gem
37
+ "gem '#{name}', git: '#{uri}', ref: '#{revision}'"
38
+ end
39
+
36
40
  def version
37
41
  revision[0...12]
38
42
  end
@@ -63,6 +67,10 @@ module Prebundler
63
67
 
64
68
  alias_method :source, :uri
65
69
 
70
+ def remote
71
+ nil
72
+ end
73
+
66
74
  def revision
67
75
  spec.source.revision
68
76
  end
@@ -1,3 +1,3 @@
1
1
  module Prebundler
2
- VERSION = '0.7.2'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/prebundler.rb CHANGED
@@ -5,6 +5,7 @@ module Prebundler
5
5
  autoload :PathGemRef, 'prebundler/path_gem_ref'
6
6
  autoload :Gemfile, 'prebundler/gemfile'
7
7
  autoload :GemfileInterpreter, 'prebundler/gemfile_interpreter'
8
+ autoload :GemfileSubset, 'prebundler/gemfile_subset'
8
9
  autoload :GemRef, 'prebundler/gem_ref'
9
10
  autoload :GitGemRef, 'prebundler/git_gem_ref'
10
11
  autoload :S3Backend, 'prebundler/s3_backend'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prebundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,11 +84,13 @@ files:
84
84
  - lib/prebundler/cli/base.rb
85
85
  - lib/prebundler/cli/install.rb
86
86
  - lib/prebundler/cli/list.rb
87
+ - lib/prebundler/cli/subset.rb
87
88
  - lib/prebundler/configurator.rb
88
89
  - lib/prebundler/file_backend.rb
89
90
  - lib/prebundler/gem_ref.rb
90
91
  - lib/prebundler/gemfile.rb
91
92
  - lib/prebundler/gemfile_interpreter.rb
93
+ - lib/prebundler/gemfile_subset.rb
92
94
  - lib/prebundler/git_gem_ref.rb
93
95
  - lib/prebundler/path_gem_ref.rb
94
96
  - lib/prebundler/s3_backend.rb
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  version: '0'
115
117
  requirements: []
116
118
  rubyforge_project:
117
- rubygems_version: 2.4.5.5
119
+ rubygems_version: 2.7.6
118
120
  signing_key:
119
121
  specification_version: 4
120
122
  summary: Gem dependency prebuilder