bowndler 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57295d1625452306b49d0c52d7617efbbfcdd22d
4
+ data.tar.gz: 9d1b2d88c7c683b078f494d4a1e1a1d02f41589c
5
+ SHA512:
6
+ metadata.gz: 3ed5e1c9a3bee8ffcaed9677237595402bc66b4f0614e5ea51cb39aae138a69e84cfdf1b8f8214e2ff035d79087305c6a20032d7bcef3f6a132081d340a2b3e1
7
+ data.tar.gz: 5c3f5044b881c9ba5264a8a08da2fefb3c00ec2f98e1fe742586dfbff5d4a7138252b53668981998b8bd7a264f977e9460c3f4b757746002bac4871de7189a36
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ bowndler
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p451
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bowndler.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Money Advice Service
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Bowndler
2
+
3
+ Integrate bower and bundler, by making bower aware of gem bundles.
4
+
5
+ NOTE:
6
+ - this is experimental, your results may vary
7
+ - this readme needs to be updated, we know its light on detail. It is highly recommended that you read the source before using bowndler.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'bowndler'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bowndler
22
+
23
+ ## Setup
24
+
25
+ 1. rename bower.json to bower.json.erb
26
+ 2. add `"my_gem": "<%= gem_path('my_gem') %>"` to "paths" in the bower.json.erb, for any gem that has its own bower.json
27
+ 3. instead of running `bower <command>`, run `bowndler <command>` and bowndler will make sure the bower.json is up to date. e.g. `bowndler install`
28
+
29
+ ## Usage
30
+
31
+ 1. In the root of your project run `bowndler update`
32
+ 2. If your packages are not being updated as expected run `bower cache clean` first
33
+ 3. If your packages are still not being updated. Delete the `bower_components` directory and try again
34
+
35
+ ### Autohook
36
+
37
+ Bowndler has a somewhat magical "autohook" feature - where `bowndler update` will run automatically whenever you run a `bundle` command that could potentially change your `Gemfile.lock`. This is VERY experimental, and should be used with caution.
38
+
39
+ To enable it:
40
+
41
+ 1. Run `bowndler autohook` in the root of your repo. This will modiy your Gemfile, those changes should be committed to source control.
42
+ 2. Set `ENABLE_BOWNDLER_HOOK=1` in your environment (by adding `export ENABLE_BOWNDLER_HOOK=1` to your .bashrc or .bash_profile)
43
+
44
+ NOTE: Autohook only works reliably on Mac OS X. It currently causes a segfault on both Ruby 1.9.* and 2.* on CentOS (and potentially other Linux distributions as well)
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/bowndler ADDED
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'thor'
5
+ require 'bowndler/cli'
6
+
7
+ Bowndler::CLI.start(ARGV)
data/bowndler.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bowndler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bowndler"
8
+ spec.version = Bowndler::VERSION
9
+ spec.authors = ["Money Advice Service", "Gareth Visagie"]
10
+ spec.email = ["development.team@moneyadviceservice.org.uk", "gareth@gjvis.com"]
11
+ spec.description = %q{Integrate bower and bundler, by making bower aware of gem bundles.}
12
+ spec.summary = %q{Integrate bower and bundler, by making bower aware of gem bundles.}
13
+ spec.homepage = "https://github.com/moneyadviceservice/bowndler"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "pry"
26
+ end
data/build.sh ADDED
@@ -0,0 +1 @@
1
+ gem build bowndler.gemspec
data/lib/bowndler.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "bowndler/version"
2
+ require "bowndler/hook"
3
+
4
+ module Bowndler
5
+ def self.hook
6
+ Bowndler::Hook.create
7
+ end
8
+ end
9
+
@@ -0,0 +1,31 @@
1
+ require 'bowndler/commands'
2
+ require 'bundler'
3
+
4
+ module Bowndler
5
+ class CLI < Thor
6
+ desc 'bower_configure', 'Generates bower.json from bower.json.erb'
7
+ option :template, banner: 'Template file path (will autodetect if left blank)'
8
+ def bower_configure
9
+ template_path = options.include?(:template) ?
10
+ File.expand_path(options[:template]) :
11
+ Bundler.default_gemfile.dirname.join('bower.json.erb')
12
+
13
+ Commands::RecursiveBowerConfigure.new(template_path).call
14
+ end
15
+
16
+ desc 'autohook', 'Update a gemfile to automatically configure bower when bundling'
17
+ option :gemfile, banner: 'Path to the gemfile to update (will autodetect gemfile if left blank)'
18
+ def autohook
19
+ gemfile = options.include?(:gemfile) ?
20
+ File.expand_path(options[:gemfile]) :
21
+ Bundler.default_gemfile
22
+
23
+ Commands::Autohook.new(gemfile).call
24
+ end
25
+
26
+ def method_missing(method_name, *args, &block)
27
+ invoke :bower_configure, []
28
+ exec "bower #{method_name} #{args.join(' ')}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ require 'bowndler/commands/autohook'
2
+ require 'bowndler/commands/bower_configure'
3
+ require 'bowndler/commands/recursive_bower_configure'
@@ -0,0 +1,33 @@
1
+ require 'bowndler'
2
+
3
+ module Bowndler
4
+ module Commands
5
+ class Autohook
6
+ HOOK = <<-HOOK
7
+
8
+ # BEGIN Autogenerated by bowndler, do not edit
9
+ if ENV['ENABLE_BOWNDLER_HOOK']
10
+ at_exit do
11
+ require "bowndler"
12
+ Bowndler.hook
13
+ end
14
+ end
15
+ # END Autogenerated by bowndler
16
+ HOOK
17
+
18
+ attr_reader :gemfile
19
+
20
+ def initialize(gemfile)
21
+ @gemfile = gemfile
22
+ end
23
+
24
+ def call
25
+ File.open(gemfile, 'a+') do |f|
26
+ contents = f.read
27
+ f << HOOK unless contents.include?(HOOK)
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ require 'pathname'
2
+ require 'erb'
3
+ require 'json'
4
+
5
+ module Bowndler
6
+ module Commands
7
+ class BowerConfigure
8
+
9
+ class GemAwareTemplate
10
+ def gem_path(name)
11
+ Bundler.rubygems.find_name(name).first.full_gem_path
12
+ end
13
+ end
14
+
15
+ attr_reader :template, :output_path
16
+ private :template, :output_path
17
+
18
+ def initialize(template_path)
19
+ template_path = Pathname.new(template_path)
20
+ @output_path = template_path.dirname.join('bower.json')
21
+
22
+ erb = ERB.new(IO.read(template_path))
23
+ erb.filename = template_path.to_s
24
+ @template = erb.def_class(GemAwareTemplate, 'render()').new
25
+ end
26
+
27
+ def call
28
+ bower_config = JSON.parse(template.render)
29
+ bower_config = {:__warning__ => [
30
+ " ************************************************************************** ",
31
+ " * * ",
32
+ " * WARNING! * ",
33
+ " * This file is generated. ANY CHANGES YOU MAKE MAY BE OVERWRITTEN. * ",
34
+ " * * ",
35
+ " * To add/edit bower dependencies, please edit bower.json.erb, and run * ",
36
+ " * `bowndler bower_configure` to regenerate this file. * ",
37
+ " * * ",
38
+ " ************************************************************************** ",
39
+ ]}.merge(bower_config)
40
+
41
+ bower_json = JSON.pretty_generate(bower_config)
42
+ File.open(output_path, 'w') do |file|
43
+ file.write(bower_json)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,58 @@
1
+ require 'pathname'
2
+ require 'bowndler/commands/bower_configure'
3
+
4
+ module Bowndler
5
+ module Commands
6
+ class RecursiveBowerConfigure
7
+ class Gem
8
+ attr_reader :manifest_path
9
+
10
+ def initialize(name)
11
+ gem_path = Bundler.rubygems.find_name(name).first.full_gem_path
12
+ @manifest_path = Pathname.new(gem_path).join('bower.json.erb')
13
+ end
14
+
15
+ def uses_bowndler?
16
+ manifest_path.exist?
17
+ end
18
+ end
19
+
20
+ attr_reader :template_path
21
+
22
+ def initialize(template_path)
23
+ @template_path = template_path
24
+ end
25
+
26
+ def call
27
+ all_bowndler_manifests.each do |path|
28
+ Commands::BowerConfigure.new(path).call
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def all_bowndler_manifests
35
+ found_paths = Set.new
36
+ find_bowndler_manifests_recursive(template_path, found_paths)
37
+
38
+ found_paths
39
+ end
40
+
41
+ def find_bowndler_manifests_recursive(template_path, found_paths)
42
+ found_paths << template_path
43
+ manifest = File.read(template_path)
44
+
45
+ # the \1 in the regex is a backreference that matches the opening quote
46
+ gem_names = manifest.scan(/<%=\s*gem_path\s*\(?\s*(["'])(.*)\1\s*\)?\s*%>/)
47
+ .map { |matches| matches[1] }
48
+
49
+ gems = gem_names.map { |name| Gem.new(name) }
50
+
51
+ gems.select(&:uses_bowndler?).each do |gem|
52
+ find_bowndler_manifests_recursive(gem.manifest_path, found_paths)
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,33 @@
1
+ module Bowndler
2
+ class ExecAtExit
3
+
4
+ class << self
5
+ def register(*args)
6
+ $stderr.puts "exec_at_exit: #{args}"
7
+ at_exit { new(*args).run }
8
+ end
9
+ end
10
+
11
+ attr_reader :command, :working_dir
12
+
13
+ def initialize(command, working_dir)
14
+ @command = command.to_s
15
+ @working_dir = working_dir
16
+ end
17
+
18
+ def run
19
+ run_command if is_exiting_cleanly?
20
+ end
21
+
22
+ protected
23
+
24
+ def run_command
25
+ Dir.chdir(working_dir) { exec(command) }
26
+ end
27
+
28
+ def is_exiting_cleanly?
29
+ $!.nil? || ($!.is_a?(SystemExit) && $!.success?)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require 'bowndler/exec_at_exit'
2
+ require 'bundler'
3
+
4
+ module Bowndler
5
+ module Hook
6
+ extend self
7
+
8
+ def create
9
+ create_hook if hookable_process?
10
+ end
11
+
12
+ private
13
+
14
+ def create_hook
15
+ gemfile_dir = File.dirname(Bundler.default_gemfile)
16
+ ExecAtExit.register("bowndler update", gemfile_dir)
17
+ end
18
+
19
+ def hookable_process?
20
+ bundler_running? && bundler_command_modifies_gemfile? && is_master_bundler_process?
21
+ end
22
+
23
+ def bundler_running?
24
+ $PROGRAM_NAME =~ /bundle$/
25
+ end
26
+
27
+ def bundler_command_modifies_gemfile?
28
+ ARGV.empty? || ARGV.any? { |a| ['install', 'update'].include?(a) }
29
+ end
30
+
31
+ def is_master_bundler_process?
32
+ # make sure that the parent process isn't "bundle"
33
+ /bundle$/ !~ `ps -o comm= -p #{Process.ppid} 2>/dev/null`
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Bowndler
2
+ VERSION = "1.0.2"
3
+ end
data/test.sh ADDED
@@ -0,0 +1 @@
1
+ # intentionally left blank
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bowndler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Money Advice Service
8
+ - Gareth Visagie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.3'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Integrate bower and bundler, by making bower aware of gem bundles.
71
+ email:
72
+ - development.team@moneyadviceservice.org.uk
73
+ - gareth@gjvis.com
74
+ executables:
75
+ - bowndler
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - .ruby-gemset
81
+ - .ruby-version
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/bowndler
87
+ - bowndler.gemspec
88
+ - build.sh
89
+ - lib/bowndler.rb
90
+ - lib/bowndler/cli.rb
91
+ - lib/bowndler/commands.rb
92
+ - lib/bowndler/commands/autohook.rb
93
+ - lib/bowndler/commands/bower_configure.rb
94
+ - lib/bowndler/commands/recursive_bower_configure.rb
95
+ - lib/bowndler/exec_at_exit.rb
96
+ - lib/bowndler/hook.rb
97
+ - lib/bowndler/version.rb
98
+ - test.sh
99
+ homepage: https://github.com/moneyadviceservice/bowndler
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Integrate bower and bundler, by making bower aware of gem bundles.
123
+ test_files: []