lapidario 0.2alpha.0 → 0.3alpha.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/README.md +3 -2
- data/lib/cli.rb +23 -1
- data/lib/gemfile_info.rb +3 -1
- data/lib/helper.rb +7 -0
- data/lib/lapidario/version.rb +1 -1
- data/lib/lapidario.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20d6caf8e33b92cf05ac97c0aabbc067056c319c1f346f0b7dc18df4e15a53bc
|
|
4
|
+
data.tar.gz: f5523dcf45fea5d35c4a7fbb67bcf181d23b800cb56fb682a3f29a9929f14c71
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ac1f42c2addf85814d1344a6cb0421cdd1484d2fb698ef13613897cda236a18ddc4966b6f2ad2649176b6bd79ec6cb19860792476c13feafa04a7e7684233be
|
|
7
|
+
data.tar.gz: 40f1b5d1889669bdb91949ef52aaab82b6f40e5c84cb8d35f2f683a4ed5a13ff36546ae5fa726433644362e55e2e7a4fe0c3d7a1f0230aca5228404d514996af
|
data/README.md
CHANGED
|
@@ -6,8 +6,9 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
|
|
|
6
6
|
|
|
7
7
|
## TO DO:
|
|
8
8
|
- [ ] Backup system: keep `Gemfile.original` stashed persistently
|
|
9
|
-
- [
|
|
10
|
-
- [
|
|
9
|
+
- [x] Add option to ignore Gemfile lines with `# LOCK` commented to the right end of the line
|
|
10
|
+
- [x] Normalize git gems with rubygems from Gemfile.lock
|
|
11
|
+
- [x] Add logic to ignore any comments in Gemfile gem lines
|
|
11
12
|
- [ ] Normalize gems from other sources with rubygems from Gemfile.lock
|
|
12
13
|
|
|
13
14
|
## Installation
|
data/lib/cli.rb
CHANGED
|
@@ -5,13 +5,35 @@ require_relative "lapidario"
|
|
|
5
5
|
module Lapidario
|
|
6
6
|
module CLI
|
|
7
7
|
def self.start(_cmd_args)
|
|
8
|
+
if _cmd_args.include?('--help') || _cmd_args.include?('-h')
|
|
9
|
+
puts "Usage: lapidario [options]\n\n"
|
|
10
|
+
puts "NOTE: if you want to exclude any gem in your Gemfile to the functionality described below, comment 'LOCK' at the end of its line.\nSee examples:\n\n"
|
|
11
|
+
puts "Valid example of locking gem line:\n"
|
|
12
|
+
puts "gem 'rails', '~> 7.0' # LOCK"
|
|
13
|
+
puts "\n\nInvalid example of locking gem line:"
|
|
14
|
+
puts "gem 'rails', '~> 7.0' # Not locked, will be taken into account to rebuild Gemfile"
|
|
15
|
+
puts "\n\nOptions:"
|
|
16
|
+
puts " --help, -h Show help message"
|
|
17
|
+
puts " --lock, -l Rebuild Gemfile using versions specified in Gemfile.lock; default sign is '~>' and default depth is 2 (up to minor version, ignores patch)"
|
|
18
|
+
puts " --reset, -r Rebuild Gemfile without gem versions"
|
|
19
|
+
puts " --full-reset, -fr Rebuild Gemfile, removing all info but gem names"
|
|
20
|
+
exit
|
|
21
|
+
end
|
|
8
22
|
puts "cmd args: #{_cmd_args}"
|
|
9
23
|
project_path_hash = { project_path: './' }
|
|
10
24
|
info_instances = Lapidario.get_gemfile_and_lockfile_info(project_path_hash)
|
|
11
25
|
gemfile_info = info_instances[0]
|
|
12
26
|
lockfile_info = info_instances[1]
|
|
13
27
|
original_gemfile_lines = gemfile_info.original_gemfile
|
|
14
|
-
new_gemfile_info =
|
|
28
|
+
new_gemfile_info = case
|
|
29
|
+
when _cmd_args.include?('--reset'), _cmd_args.include?('-r')
|
|
30
|
+
Lapidario.hardcode_gemfile_with_empty_versions(gemfile_info, true) # keep_extra_info = true
|
|
31
|
+
when _cmd_args.include?('--full-reset'), _cmd_args.include?('-fr')
|
|
32
|
+
Lapidario.hardcode_gemfile_with_empty_versions(gemfile_info, false) # keep_extra_info = false
|
|
33
|
+
else # default = --lock
|
|
34
|
+
Lapidario.hardcode_lockfile_versions_into_gemfile_info(gemfile_info, lockfile_info)
|
|
35
|
+
end
|
|
36
|
+
|
|
15
37
|
new_gemfile = Lapidario.build_new_gemfile(new_gemfile_info, original_gemfile_lines)
|
|
16
38
|
puts "New gemfile created:"
|
|
17
39
|
puts new_gemfile
|
data/lib/gemfile_info.rb
CHANGED
|
@@ -44,6 +44,8 @@ module Lapidario
|
|
|
44
44
|
|
|
45
45
|
def self.gem_info(gemfile_line, line_index = -9999)
|
|
46
46
|
gem_info = { line_index: line_index, name: "", prepended_spaces: 0, current_version: "", version_sign: "", extra_info: "" }
|
|
47
|
+
# ignore everything to the right of first '#' character
|
|
48
|
+
gemfile_line = gemfile_line.split("#", 2)[0]
|
|
47
49
|
# count prepended spaces to reuse on gemfile rebuild
|
|
48
50
|
gem_info[:prepended_spaces] = gemfile_line.match(/\A\s*/)[0].size
|
|
49
51
|
# splits on coma, removes prepended whitespaces if any
|
|
@@ -76,7 +78,7 @@ module Lapidario
|
|
|
76
78
|
# gi = gem_info
|
|
77
79
|
def self.build_gemfile_line(gi)
|
|
78
80
|
line = "#{' ' * gi[:prepended_spaces].to_i}gem '#{gi[:name]}'"
|
|
79
|
-
if gi[:current_version]
|
|
81
|
+
if gi[:current_version] && !gi[:current_version].empty?
|
|
80
82
|
version_fragment = "#{gi[:current_version]}"
|
|
81
83
|
version_fragment = "#{gi[:version_sign]} " + version_fragment if gi[:version_sign]
|
|
82
84
|
line = line + ", '#{version_fragment}'"
|
data/lib/helper.rb
CHANGED
|
@@ -8,12 +8,19 @@ module Lapidario
|
|
|
8
8
|
@@GEM_VERSION_FRAGMENT = /^\s*([<>]=?|~>)?\s*[0-9a-zA-Z\s.]+\s*$/
|
|
9
9
|
@@DETECT_GEMFILE_IN_PATH = /\/Gemfile/
|
|
10
10
|
@@DETECT_LOCKFILE_IN_PATH = /\/Gemfile\.lock/
|
|
11
|
+
# checks 0 or more spaces to the left or 1 or more to the right, also asserting that LOCK is at the end of string
|
|
12
|
+
@@DETECT_LOCKED_LINE = /\s*LOCK\s*\z/
|
|
11
13
|
|
|
12
14
|
def self.version_fragment?(line_section)
|
|
13
15
|
line_section.match? @@GEM_VERSION_FRAGMENT
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def self.gem_line?(gemfile_line)
|
|
19
|
+
commented_portion = gemfile_line.split("#", 2)[1] # gets everything to the right of a '#' if present in line
|
|
20
|
+
if commented_portion && commented_portion.match?(@@DETECT_LOCKED_LINE)
|
|
21
|
+
puts "Ignoring line as it ends in # LOCK: \n#{gemfile_line}"
|
|
22
|
+
return false
|
|
23
|
+
end
|
|
17
24
|
gemfile_line.match?(/^\s*gem\s+["']([^"']+)["']/)
|
|
18
25
|
end
|
|
19
26
|
|
data/lib/lapidario/version.rb
CHANGED
data/lib/lapidario.rb
CHANGED
|
@@ -69,4 +69,17 @@ module Lapidario
|
|
|
69
69
|
end
|
|
70
70
|
new_gemfile_info
|
|
71
71
|
end
|
|
72
|
+
|
|
73
|
+
# soft reset of gemfile, removing all version information. Removing extra info is optional
|
|
74
|
+
# Note: if a version is ranged and extra info is keps, this will also hard-code the version upper range in the gem line.
|
|
75
|
+
def self.hardcode_gemfile_with_empty_versions(gemfile_info, keep_extra_info = true)
|
|
76
|
+
new_gemfile_info = gemfile_info.gemfile_lines_info.clone
|
|
77
|
+
# replace versions in gemfile with ones on lockfile
|
|
78
|
+
new_gemfile_info.each do |gem_info|
|
|
79
|
+
gem_info[:current_version] = ""
|
|
80
|
+
gem_info[:version_sign] = ""
|
|
81
|
+
gem_info[:extra_info] = "" unless keep_extra_info
|
|
82
|
+
end
|
|
83
|
+
new_gemfile_info
|
|
84
|
+
end
|
|
72
85
|
end
|