rails-diff 0.3.0 → 0.4.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/.ruby-version +1 -0
- data/CHANGELOG.md +8 -0
- data/lib/rails/diff/version.rb +1 -1
- data/lib/rails/diff.rb +64 -25
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65e5efcc214d48f2c3d2aac80dfb88c7506b3bd559a74e2c77f31fd1388736f0
|
4
|
+
data.tar.gz: cd3123a08c990c068401869e18e6a8c3ad0fb54867640b42a655357d73b23a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1177590a5fa948253de27d6169f567cd75a50dc9f840e4145b45ddc55e7e3f884c8595b0ed2a8a01911290be9eaeab34eaee670212cddd56f412b7ab1a4564ea
|
7
|
+
data.tar.gz: 67c3ff2090a3f81c1ff1d22e1dad2ca549b45e80588021eec5c128d0f8bede276cb8da2ffcd5719fc3a312e0be52fde112ccd37cf6a97398c6725e22dc3c2375
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.4.2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.0] - 2025-03-05
|
4
|
+
|
5
|
+
- Respect `~/.railsrc` file when generating new rails apps (PR #4). Thanks [@marcoroth](https://github.com/marcoroth) 🎉
|
6
|
+
- Use array version of `system` to avoid command injection.
|
7
|
+
- Update cache keys to be shorter.
|
8
|
+
- Improve log messages.
|
9
|
+
|
3
10
|
## [0.3.0] - 2025-02-23
|
4
11
|
|
5
12
|
- Allow passing options to generate the new application
|
@@ -38,6 +45,7 @@ M## [0.1.1] - 2025-02-21
|
|
38
45
|
|
39
46
|
- Initial release
|
40
47
|
|
48
|
+
[0.4.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.4.0
|
41
49
|
[0.3.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.3.0
|
42
50
|
[0.2.1]: https://github.com/matheusrich/rails-diff/releases/tag/v0.2.1
|
43
51
|
[0.2.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.2.0
|
data/lib/rails/diff/version.rb
CHANGED
data/lib/rails/diff.rb
CHANGED
@@ -5,13 +5,15 @@ require "rails"
|
|
5
5
|
require "thor"
|
6
6
|
require "diffy"
|
7
7
|
require "fileutils"
|
8
|
+
require "open3"
|
8
9
|
|
9
10
|
module Rails
|
10
11
|
module Diff
|
11
12
|
class Error < StandardError; end
|
12
13
|
|
13
14
|
RAILS_REPO = "https://github.com/rails/rails.git"
|
14
|
-
CACHE_DIR = File.expand_path("
|
15
|
+
CACHE_DIR = File.expand_path("#{ENV["HOME"]}/.rails-diff/cache")
|
16
|
+
RAILSRC_PATH = "#{ENV["HOME"]}/.railsrc"
|
15
17
|
|
16
18
|
class << self
|
17
19
|
def file(*files, no_cache: false, commit: nil, new_app_options: nil)
|
@@ -33,8 +35,23 @@ module Rails
|
|
33
35
|
|
34
36
|
private
|
35
37
|
|
38
|
+
def system!(*cmd)
|
39
|
+
_, stderr, status = Open3.capture3(*cmd)
|
40
|
+
|
41
|
+
unless status.success?
|
42
|
+
puts "\e[1;31mCommand failed:\e[0m #{cmd.join(' ')}"
|
43
|
+
abort stderr
|
44
|
+
end
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def info(message)
|
50
|
+
puts "\e[1;34minfo:\e[0m #{message}"
|
51
|
+
end
|
52
|
+
|
36
53
|
def clear_cache
|
37
|
-
|
54
|
+
info "Clearing cache"
|
38
55
|
FileUtils.rm_rf(CACHE_DIR)
|
39
56
|
end
|
40
57
|
|
@@ -48,19 +65,26 @@ module Rails
|
|
48
65
|
end
|
49
66
|
|
50
67
|
def template_app_path
|
51
|
-
@template_app_path ||= File.join(CACHE_DIR, commit,
|
68
|
+
@template_app_path ||= File.join(CACHE_DIR, "rails-#{commit.first(10)}", rails_new_options_hash, app_name)
|
52
69
|
end
|
53
70
|
|
54
71
|
def rails_path
|
55
72
|
@rails_path ||= begin
|
56
73
|
File.join(CACHE_DIR, "rails").tap do |path|
|
57
74
|
unless File.exist?(path)
|
58
|
-
|
75
|
+
info "Cloning Rails repository"
|
76
|
+
system!("git", "clone", "--depth", "1", RAILS_REPO, path)
|
59
77
|
end
|
60
78
|
end
|
61
79
|
end
|
62
80
|
end
|
63
81
|
|
82
|
+
def railsrc_options
|
83
|
+
return @railsrc_options if defined?(@railsrc_options)
|
84
|
+
|
85
|
+
@railsrc_options = File.read(RAILSRC_PATH).lines if File.exist?(RAILSRC_PATH)
|
86
|
+
end
|
87
|
+
|
64
88
|
def app_name = @app_name ||= File.basename(Dir.pwd)
|
65
89
|
|
66
90
|
def list_files(dir, skip = [])
|
@@ -82,11 +106,10 @@ module Rails
|
|
82
106
|
end
|
83
107
|
|
84
108
|
def generated_files(generator_name, *args, skip)
|
85
|
-
command = "#{generator_name} #{args.join(' ')}"
|
86
109
|
Dir.chdir(template_app_path) do
|
87
|
-
system("bin/rails destroy
|
88
|
-
|
89
|
-
track_new_files(skip) { system("bin/rails generate
|
110
|
+
system!("bin/rails", "destroy", generator_name, *args)
|
111
|
+
info "Running generator: rails generate #{generator_name} #{args.join(' ')}"
|
112
|
+
track_new_files(skip) { system!("bin/rails", "generate", generator_name, *args) }
|
90
113
|
.map { |it| it.delete_prefix("#{template_app_path}/") }
|
91
114
|
end
|
92
115
|
end
|
@@ -101,9 +124,9 @@ module Rails
|
|
101
124
|
|
102
125
|
def install_app_dependencies
|
103
126
|
Dir.chdir(template_app_path) do
|
104
|
-
unless system("bundle check
|
105
|
-
|
106
|
-
system("bundle install
|
127
|
+
unless system!("bundle check")
|
128
|
+
info "Installing application dependencies"
|
129
|
+
system!("bundle install")
|
107
130
|
end
|
108
131
|
end
|
109
132
|
end
|
@@ -112,8 +135,8 @@ module Rails
|
|
112
135
|
rails_file = File.join(template_app_path, file)
|
113
136
|
repo_file = File.join(Dir.pwd, file)
|
114
137
|
|
115
|
-
return "
|
116
|
-
return "
|
138
|
+
return "File not found in the Rails template" unless File.exist?(rails_file)
|
139
|
+
return "File not found in your repository" unless File.exist?(repo_file)
|
117
140
|
|
118
141
|
Diffy::Diff.new(
|
119
142
|
rails_file,
|
@@ -131,7 +154,7 @@ module Rails
|
|
131
154
|
return true unless File.exist?(rails_path)
|
132
155
|
|
133
156
|
Dir.chdir(rails_path) do
|
134
|
-
system("git fetch origin main
|
157
|
+
system!("git fetch origin main")
|
135
158
|
current = `git rev-parse HEAD`.strip
|
136
159
|
latest = `git rev-parse origin/main`.strip
|
137
160
|
|
@@ -152,21 +175,24 @@ module Rails
|
|
152
175
|
end
|
153
176
|
|
154
177
|
def generate_app
|
155
|
-
FileUtils.rm_rf(template_app_path)
|
156
178
|
Dir.chdir("railties") do
|
157
|
-
unless system("bundle check
|
158
|
-
|
159
|
-
system("bundle install
|
179
|
+
unless system!("bundle check")
|
180
|
+
info "Installing Rails dependencies"
|
181
|
+
system!("bundle install")
|
160
182
|
end
|
161
183
|
|
162
|
-
|
163
|
-
|
184
|
+
if railsrc_options
|
185
|
+
info "Using default options from #{RAILSRC_PATH}:\n > #{railsrc_options.join(' ')}"
|
186
|
+
end
|
187
|
+
|
188
|
+
info "Generating new Rails application\n > #{rails_new_command.join(' ')}"
|
189
|
+
system!(*rails_new_command)
|
164
190
|
end
|
165
191
|
end
|
166
192
|
|
167
193
|
def checkout_rails
|
168
|
-
|
169
|
-
system("git checkout
|
194
|
+
info "Checking out Rails (at commit #{commit[0..6]})"
|
195
|
+
system!("git", "checkout", commit)
|
170
196
|
end
|
171
197
|
|
172
198
|
def commit = @commit
|
@@ -179,9 +205,22 @@ module Rails
|
|
179
205
|
end
|
180
206
|
end
|
181
207
|
|
182
|
-
def
|
183
|
-
|
184
|
-
|
208
|
+
def rails_new_command = @rails_new_command ||= [
|
209
|
+
"bundle",
|
210
|
+
"exec",
|
211
|
+
"rails",
|
212
|
+
"new",
|
213
|
+
template_app_path,
|
214
|
+
"--main",
|
215
|
+
"--skip-bundle",
|
216
|
+
"--force",
|
217
|
+
"--quiet",
|
218
|
+
*rails_new_options
|
219
|
+
]
|
220
|
+
|
221
|
+
def rails_new_options = @rails_new_options ||= [*new_app_options, *railsrc_options].compact
|
222
|
+
|
223
|
+
def rails_new_options_hash = Digest::MD5.hexdigest(rails_new_options.join(" "))
|
185
224
|
end
|
186
225
|
|
187
226
|
class CLI < Thor
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matheus Richard
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-06 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -62,6 +62,7 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- ".rspec"
|
65
|
+
- ".ruby-version"
|
65
66
|
- CHANGELOG.md
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
|
-
rubygems_version: 3.6.
|
95
|
+
rubygems_version: 3.6.2
|
95
96
|
specification_version: 4
|
96
97
|
summary: Compare Rails-generated files with the ones in your repository
|
97
98
|
test_files: []
|