rails-diff 0.2.1 → 0.3.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/CHANGELOG.md +9 -0
- data/README.md +10 -0
- data/lib/rails/diff/version.rb +1 -1
- data/lib/rails/diff.rb +21 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93b1be272240b33b7c9357f98d876b1816fab44a032f7f655cc3b3c65a6bc925
|
4
|
+
data.tar.gz: 8201af2847c96ac8bda63200fffcc9a45179f571f72fd695260422e383fee89e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38ced646ec7b54baaed0a072be43cc2a78e7e15e6658363747611de84e403df14f1cfbebbec7d67732ee0c15e0d0fc5d1ac2bf8dcecafd1060ab15f4fab2fd51
|
7
|
+
data.tar.gz: 7e17923b6b90f24e2a8542e291862121d7f5cccd0587bf96fd28601b32d2c83234152bb98cd769a512af86076da057eaf97cdbd8fb399b7665f9123eabfc614e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2025-02-23
|
4
|
+
|
5
|
+
- Allow passing options to generate the new application
|
6
|
+
|
7
|
+
```sh
|
8
|
+
rails-diff file Gemfile --new-app-options="--database=postgresql"
|
9
|
+
```
|
10
|
+
|
3
11
|
## [0.2.1] - 2025-02-22
|
4
12
|
|
5
13
|
- Add missing version command
|
@@ -30,6 +38,7 @@ M## [0.1.1] - 2025-02-21
|
|
30
38
|
|
31
39
|
- Initial release
|
32
40
|
|
41
|
+
[0.3.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.3.0
|
33
42
|
[0.2.1]: https://github.com/matheusrich/rails-diff/releases/tag/v0.2.1
|
34
43
|
[0.2.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.2.0
|
35
44
|
[0.1.1]: https://github.com/matheusrich/rails-diff/releases/tag/v0.1.1
|
data/README.md
CHANGED
@@ -78,6 +78,16 @@ If this option is specified, the command will exit with a non-zero status code i
|
|
78
78
|
Specify the commit hash you want to compare against. If not provided, the latest
|
79
79
|
commit on main will be used by default.
|
80
80
|
|
81
|
+
#### --new-app-options <options>
|
82
|
+
|
83
|
+
Specify additional options to be used with the `rails new` command. This allows you to customize the generated Rails application, for example, by specifying a different database.
|
84
|
+
|
85
|
+
Example:
|
86
|
+
|
87
|
+
```bash
|
88
|
+
rails-diff file Dockerfile --new-app-options="--database=postgresql"
|
89
|
+
```
|
90
|
+
|
81
91
|
## How it works
|
82
92
|
|
83
93
|
When you run the diff, it will:
|
data/lib/rails/diff/version.rb
CHANGED
data/lib/rails/diff.rb
CHANGED
@@ -14,16 +14,16 @@ module Rails
|
|
14
14
|
CACHE_DIR = File.expand_path("~/.rails-diff/cache")
|
15
15
|
|
16
16
|
class << self
|
17
|
-
def file(*files, no_cache: false, commit: nil)
|
17
|
+
def file(*files, no_cache: false, commit: nil, new_app_options: nil)
|
18
18
|
clear_cache if no_cache
|
19
|
-
ensure_template_app_exists(commit)
|
19
|
+
ensure_template_app_exists(commit, new_app_options)
|
20
20
|
|
21
21
|
files.filter_map { |it| diff_with_header(it) }.join("\n")
|
22
22
|
end
|
23
23
|
|
24
|
-
def generated(generator_name, *args, no_cache: false, skip: [], commit: nil)
|
24
|
+
def generated(generator_name, *args, no_cache: false, skip: [], commit: nil, new_app_options: nil)
|
25
25
|
clear_cache if no_cache
|
26
|
-
ensure_template_app_exists(commit)
|
26
|
+
ensure_template_app_exists(commit, new_app_options)
|
27
27
|
install_app_dependencies
|
28
28
|
|
29
29
|
generated_files(generator_name, *args, skip)
|
@@ -38,17 +38,17 @@ module Rails
|
|
38
38
|
FileUtils.rm_rf(CACHE_DIR)
|
39
39
|
end
|
40
40
|
|
41
|
-
def ensure_template_app_exists(commit)
|
41
|
+
def ensure_template_app_exists(commit, new_app_options)
|
42
42
|
FileUtils.mkdir_p(CACHE_DIR)
|
43
|
+
@new_app_options = new_app_options
|
43
44
|
@commit = commit || latest_commit
|
44
45
|
return if cached_app?
|
45
46
|
|
46
|
-
FileUtils.rm_rf(template_app_path)
|
47
47
|
create_new_rails_app
|
48
48
|
end
|
49
49
|
|
50
50
|
def template_app_path
|
51
|
-
@template_app_path ||= File.join(CACHE_DIR, commit, app_name)
|
51
|
+
@template_app_path ||= File.join(CACHE_DIR, commit, new_app_options_hash, app_name)
|
52
52
|
end
|
53
53
|
|
54
54
|
def rails_path
|
@@ -124,11 +124,11 @@ module Rails
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def cached_app?
|
127
|
-
File.exist?(template_app_path) && !
|
127
|
+
File.exist?(template_app_path) && !out_of_date_rails?
|
128
128
|
end
|
129
129
|
|
130
|
-
def
|
131
|
-
return true
|
130
|
+
def out_of_date_rails?
|
131
|
+
return true unless File.exist?(rails_path)
|
132
132
|
|
133
133
|
Dir.chdir(rails_path) do
|
134
134
|
system("git fetch origin main >/dev/null 2>&1")
|
@@ -152,6 +152,7 @@ module Rails
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def generate_app
|
155
|
+
FileUtils.rm_rf(template_app_path)
|
155
156
|
Dir.chdir("railties") do
|
156
157
|
unless system("bundle check >/dev/null 2>&1")
|
157
158
|
puts "Installing Rails dependencies"
|
@@ -159,7 +160,7 @@ module Rails
|
|
159
160
|
end
|
160
161
|
|
161
162
|
puts "Generating new Rails application"
|
162
|
-
system("bundle exec rails new #{template_app_path} --main --skip-bundle --force --skip-test --skip-system-test --quiet")
|
163
|
+
system("bundle exec rails new #{template_app_path} --main --skip-bundle --force --skip-test --skip-system-test --quiet #{new_app_options}")
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
@@ -170,17 +171,24 @@ module Rails
|
|
170
171
|
|
171
172
|
def commit = @commit
|
172
173
|
|
174
|
+
def new_app_options = @new_app_options
|
175
|
+
|
173
176
|
def latest_commit
|
174
177
|
Dir.chdir(rails_path) do
|
175
178
|
`git rev-parse origin/main`.strip
|
176
179
|
end
|
177
180
|
end
|
181
|
+
|
182
|
+
def new_app_options_hash
|
183
|
+
Digest::SHA256.hexdigest(new_app_options.to_s)
|
184
|
+
end
|
178
185
|
end
|
179
186
|
|
180
187
|
class CLI < Thor
|
181
188
|
class_option :no_cache, type: :boolean, desc: "Clear cache before running", aliases: ["--clear-cache"]
|
182
189
|
class_option :fail_on_diff, type: :boolean, desc: "Fail if there are differences"
|
183
190
|
class_option :commit, type: :string, desc: "Compare against a specific commit"
|
191
|
+
class_option :new_app_options, type: :string, desc: "Options to pass to the rails new command"
|
184
192
|
|
185
193
|
def self.exit_on_failure? = true
|
186
194
|
|
@@ -188,7 +196,7 @@ module Rails
|
|
188
196
|
def file(*files)
|
189
197
|
abort "Please provide at least one file to compare" if files.empty?
|
190
198
|
|
191
|
-
diff = Rails::Diff.file(*files, no_cache: options[:no_cache], commit: options[:commit])
|
199
|
+
diff = Rails::Diff.file(*files, no_cache: options[:no_cache], commit: options[:commit], new_app_options: options[:new_app_options])
|
192
200
|
return if diff.empty?
|
193
201
|
|
194
202
|
options[:fail] ? abort(diff) : puts(diff)
|
@@ -197,7 +205,7 @@ module Rails
|
|
197
205
|
desc "generated GENERATOR [args]", "Compare files that would be created by a Rails generator"
|
198
206
|
option :skip, type: :array, desc: "Skip specific files or directories", aliases: ["-s"], default: []
|
199
207
|
def generated(generator_name, *args)
|
200
|
-
diff = Rails::Diff.generated(generator_name, *args, no_cache: options[:no_cache], skip: options[:skip], commit: options[:commit])
|
208
|
+
diff = Rails::Diff.generated(generator_name, *args, no_cache: options[:no_cache], skip: options[:skip], commit: options[:commit], new_app_options: options[:new_app_options])
|
201
209
|
return if diff.empty?
|
202
210
|
|
203
211
|
options[:fail] ? abort(diff) : puts(diff)
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matheus Richard
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02-
|
10
|
+
date: 2025-02-23 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|