restore_bundled_with 0.3.0 → 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/.conventional-changelog.context.js +17 -0
- data/.gitignore +0 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +0 -0
- data/README.md +25 -3
- data/RELEASE.md +0 -0
- data/Rakefile +9 -0
- data/lib/restore_bundled_with.rb +2 -1
- data/lib/restore_bundled_with/cli.rb +3 -2
- data/lib/restore_bundled_with/error.rb +0 -0
- data/lib/restore_bundled_with/lock.rb +27 -1
- data/lib/restore_bundled_with/repository.rb +16 -5
- data/lib/restore_bundled_with/version.rb +1 -1
- data/restore_bundled_with.gemspec +3 -3
- metadata +5 -4
- data/bin/conventional-changelog.js +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d0052ed0f13a64e5e516d928ec22e9ba71834a7
|
4
|
+
data.tar.gz: 61275fbe18e0baaaccfc68b4dcf79a2451ffa8c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2d1f3c68463e8a691e0b127e9deb43eff6b6e4619c723b96e52236a8aad15ebb7b4d88982e73b02592cbc436e9f072ddb21bc28f2a131e35f9b9facddb79d96
|
7
|
+
data.tar.gz: af240ad0fb74bfd9caa5e926ff9a843dfe05ce06f1728afb2404f6f5c264f08cfeb4058f3035b9e5b8998d0aeb7e7add694d6c40e508e5aa1fa782a52106b9f9
|
@@ -0,0 +1,17 @@
|
|
1
|
+
'use strict';
|
2
|
+
var execSync = require('child_process').execSync;
|
3
|
+
var URI = require('urijs');
|
4
|
+
|
5
|
+
var gemspec = JSON.parse(execSync('bundle exec parse-gemspec-cli restore_bundled_with.gemspec'));
|
6
|
+
var homepageUrl = gemspec.homepage;
|
7
|
+
var url = new URI(homepageUrl);
|
8
|
+
var host = url.protocol() + '://' + url.authority();
|
9
|
+
var owner = url.pathname().split('/')[1];
|
10
|
+
var repository = url.pathname().split('/')[2];
|
11
|
+
|
12
|
+
module.exports = {
|
13
|
+
version: gemspec.version,
|
14
|
+
host: host,
|
15
|
+
owner: owner,
|
16
|
+
repository: repository
|
17
|
+
};
|
data/.gitignore
CHANGED
File without changes
|
data/CHANGELOG.md
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# RestoreBundledWith
|
2
2
|
|
3
|
-
[](https://travis-ci.org/packsaddle/ruby-restore_bundled_with)
|
3
|
+
[![Gem version][gem-image]][gem-url] [![Travis-CI Status][travis-image]][travis-url] [![yard docs][docs-image]][docs-url]
|
5
4
|
|
6
|
-
Restore `BUNDLED WITH` section in `Gemfile.lock` from git repository.
|
5
|
+
> Restore `BUNDLED WITH` section in `Gemfile.lock` from git repository.
|
7
6
|
|
8
7
|
```text
|
9
8
|
# Gemfile.lock
|
@@ -111,6 +110,19 @@ $ git diff
|
|
111
110
|
|
112
111
|
There is no diff, because this restores `BUNDLED WITH` from git repository.
|
113
112
|
|
113
|
+
### Call from Ruby script
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
system(*['bundle', 'update'])
|
117
|
+
|
118
|
+
# restore_bundled_with
|
119
|
+
lock_file_contents = File.read('Gemfile.lock')
|
120
|
+
lock = RestoreBundledWith::Lock.restore(lock_file_contents, 'Gemfile.lock')
|
121
|
+
File.write('Gemfile.lock', lock.body)
|
122
|
+
```
|
123
|
+
|
124
|
+
There is no diff, because this restores `BUNDLED WITH` from git repository.
|
125
|
+
|
114
126
|
## Requirement
|
115
127
|
|
116
128
|
* Git
|
@@ -162,6 +174,10 @@ Or install it yourself as:
|
|
162
174
|
|
163
175
|
$ gem install restore_bundled_with
|
164
176
|
|
177
|
+
## Changelog
|
178
|
+
|
179
|
+
[CHANGELOG.md](./CHANGELOG.md).
|
180
|
+
|
165
181
|
## Development
|
166
182
|
|
167
183
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -177,3 +193,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/packsa
|
|
177
193
|
|
178
194
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
179
195
|
|
196
|
+
[travis-url]: https://travis-ci.org/packsaddle/ruby-restore_bundled_with
|
197
|
+
[travis-image]: https://img.shields.io/travis/packsaddle/ruby-restore_bundled_with/master.svg?style=flat-square&label=build%20%28linux%29
|
198
|
+
[gem-url]: https://rubygems.org/gems/restore_bundled_with
|
199
|
+
[gem-image]: http://img.shields.io/gem/v/restore_bundled_with.svg?style=flat-square
|
200
|
+
[docs-url]: http://www.rubydoc.info/gems/restore_bundled_with
|
201
|
+
[docs-image]: https://img.shields.io/badge/yard-docs-blue.svg?style=flat-square
|
data/RELEASE.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
@@ -7,3 +7,12 @@ Rake::TestTask.new(:test) do |t|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
task default: :test
|
10
|
+
|
11
|
+
require 'yard'
|
12
|
+
require 'yard/rake/yardoc_task'
|
13
|
+
DOC_FILES = ['lib/**/*.rb'].freeze
|
14
|
+
DOC_OPTIONS = ['--debug', '--verbose'].freeze
|
15
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
16
|
+
t.files = DOC_FILES
|
17
|
+
t.options = DOC_OPTIONS if Rake.application.options.trace
|
18
|
+
end
|
data/lib/restore_bundled_with.rb
CHANGED
@@ -6,8 +6,9 @@ require 'restore_bundled_with/lock'
|
|
6
6
|
require 'restore_bundled_with/repository'
|
7
7
|
require 'restore_bundled_with/version'
|
8
8
|
|
9
|
+
# Restore BUNDLED WITH section in Gemfile.lock from git repository.
|
9
10
|
module RestoreBundledWith
|
10
|
-
ISSUE_URL = 'https://github.com/packsaddle/ruby-restore_bundled_with/issues/new'
|
11
|
+
ISSUE_URL = 'https://github.com/packsaddle/ruby-restore_bundled_with/issues/new'.freeze
|
11
12
|
def self.default_logger
|
12
13
|
logger = Logger.new(STDERR)
|
13
14
|
logger.progname = "RestoreBundledWith #{VERSION}"
|
@@ -78,7 +78,8 @@ module RestoreBundledWith
|
|
78
78
|
.fetch_file(
|
79
79
|
options[:lockfile],
|
80
80
|
options[:ref],
|
81
|
-
options[:new_line]
|
81
|
+
options[:new_line]
|
82
|
+
)
|
82
83
|
puts Lock
|
83
84
|
.new(lock_file)
|
84
85
|
.pick
|
@@ -101,7 +102,7 @@ module RestoreBundledWith
|
|
101
102
|
|
102
103
|
logger.info('input data')
|
103
104
|
logger.info(data)
|
104
|
-
|
105
|
+
raise NoInputError if !data || data.empty?
|
105
106
|
|
106
107
|
data
|
107
108
|
end
|
File without changes
|
@@ -1,9 +1,16 @@
|
|
1
1
|
module RestoreBundledWith
|
2
|
+
# The lock file
|
2
3
|
class Lock
|
3
4
|
attr_reader :body
|
5
|
+
# @!attribute [r] body
|
6
|
+
# @return [String] file body
|
4
7
|
|
5
8
|
REGEX_BUNDLED_WITH = /^(?<pick>(?:\r\n|\r|\n)^BUNDLED WITH.*(?:\r\n|\r|\n).+(?:\r\n|\r|\n))/
|
6
9
|
|
10
|
+
# @param text [String] base lock file
|
11
|
+
# @param section [String] appending section
|
12
|
+
#
|
13
|
+
# @return [Lock] the lock file instance
|
7
14
|
def self.insert(text, section)
|
8
15
|
if section && !section.empty?
|
9
16
|
new(text + section)
|
@@ -12,6 +19,14 @@ module RestoreBundledWith
|
|
12
19
|
end
|
13
20
|
end
|
14
21
|
|
22
|
+
# @param data [String] before restore
|
23
|
+
# @param lockfile [String] file name
|
24
|
+
# @param ref [String] git ref
|
25
|
+
# @param git_path [String] git repository path
|
26
|
+
# @param git_options [Hash] ruby-git options
|
27
|
+
# @param new_line [String] new line
|
28
|
+
#
|
29
|
+
# @return [Lock] the lock file instance
|
15
30
|
def self.restore(
|
16
31
|
data,
|
17
32
|
lockfile = Repository::LOCK_FILE,
|
@@ -29,15 +44,22 @@ module RestoreBundledWith
|
|
29
44
|
insert(trimmed.body, section)
|
30
45
|
end
|
31
46
|
|
47
|
+
# @param text [String] the lock file contents
|
48
|
+
#
|
49
|
+
# @return [Lock] the lock file instance
|
32
50
|
def initialize(text)
|
33
51
|
@body = text
|
34
52
|
end
|
35
53
|
|
36
|
-
#
|
54
|
+
# @example delete bundled with
|
55
|
+
# "\n\nBUNDLED WITH\n 1.10.4\n" => "\n"
|
56
|
+
#
|
57
|
+
# @return [Lock] new lock file instance which is deleted bundled with
|
37
58
|
def delete_bundled_with
|
38
59
|
self.class.new(body.sub(REGEX_BUNDLED_WITH) { '' })
|
39
60
|
end
|
40
61
|
|
62
|
+
# @return [String] pick target section
|
41
63
|
def pick
|
42
64
|
match = REGEX_BUNDLED_WITH.match(body)
|
43
65
|
if match
|
@@ -47,10 +69,14 @@ module RestoreBundledWith
|
|
47
69
|
end
|
48
70
|
end
|
49
71
|
|
72
|
+
# @return [String] the lock file contents
|
50
73
|
def to_s
|
51
74
|
body
|
52
75
|
end
|
53
76
|
|
77
|
+
# @param [#body] other compare body
|
78
|
+
#
|
79
|
+
# @return [Boolean] true if file body is same
|
54
80
|
def ==(other)
|
55
81
|
body == other.body
|
56
82
|
end
|
@@ -1,20 +1,31 @@
|
|
1
1
|
module RestoreBundledWith
|
2
|
+
# The git repository
|
2
3
|
class Repository
|
3
|
-
LOCK_FILE = 'Gemfile.lock'
|
4
|
-
REF = 'HEAD'
|
5
|
-
GIT_PATH = '.'
|
6
|
-
GIT_OPTIONS = {}
|
7
|
-
NEW_LINE = "\n"
|
4
|
+
LOCK_FILE = 'Gemfile.lock'.freeze
|
5
|
+
REF = 'HEAD'.freeze
|
6
|
+
GIT_PATH = '.'.freeze
|
7
|
+
GIT_OPTIONS = {}.freeze
|
8
|
+
NEW_LINE = "\n".freeze
|
8
9
|
|
10
|
+
# @param git_path [String] git repository path
|
11
|
+
# @param git_options [Hash] ruby-git options
|
12
|
+
#
|
13
|
+
# @return [Repository] Repository instance
|
9
14
|
def initialize(git_path = GIT_PATH, git_options = GIT_OPTIONS)
|
10
15
|
@git_path = git_path
|
11
16
|
@git_options = git_options
|
12
17
|
end
|
13
18
|
|
19
|
+
# @return [Git::Base] ruby-git object
|
14
20
|
def git
|
15
21
|
@git ||= Git.open(@git_path, @git_options)
|
16
22
|
end
|
17
23
|
|
24
|
+
# @param file [String] target file
|
25
|
+
# @param ref [String] git ref
|
26
|
+
# @param new_line [String] file's ending new line
|
27
|
+
#
|
28
|
+
# @return [String] target file contents
|
18
29
|
def fetch_file(file = LOCK_FILE, ref = REF, new_line = NEW_LINE)
|
19
30
|
# NOTE: git.cat_file trims last \n?
|
20
31
|
text = git.cat_file("#{ref}:#{file}")
|
@@ -21,9 +21,9 @@ RestoreBundledWith solves these conflicts.
|
|
21
21
|
|
22
22
|
spec.files = \
|
23
23
|
`git ls-files -z`
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
.split("\x0")
|
25
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
.reject do |f|
|
27
27
|
[
|
28
28
|
'.rubocop.yml',
|
29
29
|
'.rubocop_todo.yml',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restore_bundled_with
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sanemat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -109,6 +109,7 @@ executables:
|
|
109
109
|
extensions: []
|
110
110
|
extra_rdoc_files: []
|
111
111
|
files:
|
112
|
+
- ".conventional-changelog.context.js"
|
112
113
|
- ".gitignore"
|
113
114
|
- CHANGELOG.md
|
114
115
|
- CODE_OF_CONDUCT.md
|
@@ -118,7 +119,6 @@ files:
|
|
118
119
|
- RELEASE.md
|
119
120
|
- Rakefile
|
120
121
|
- bin/console
|
121
|
-
- bin/conventional-changelog.js
|
122
122
|
- bin/run-rubocop.sh
|
123
123
|
- bin/setup
|
124
124
|
- exe/restore-bundled-with
|
@@ -149,8 +149,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.5.1
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: Restore BUNDLED WITH section in Gemfile.lock from git repository.
|
156
156
|
test_files: []
|
157
|
+
has_rdoc:
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
var fs = require('fs');
|
4
|
-
var execSync = require('child_process').execSync;
|
5
|
-
var conventionalChangelog = require('conventional-changelog');
|
6
|
-
|
7
|
-
var repo = 'https://github.com/packsaddle/ruby-restore_bundled_with'
|
8
|
-
var version = "" + execSync('bundle exec exe/restore-bundled-with version --digit');
|
9
|
-
|
10
|
-
conventionalChangelog({
|
11
|
-
repository: repo,
|
12
|
-
version: version,
|
13
|
-
file: 'CHANGELOG.md'
|
14
|
-
}, function(err, log) {
|
15
|
-
fs.writeFile('CHANGELOG.md', log, function(err){
|
16
|
-
console.log(err);
|
17
|
-
});
|
18
|
-
console.log('Here is your changelog!', log);
|
19
|
-
});
|