mirrorfile 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 513175ce2e6de6e4e0a0a810d844ce5a280fd3e899cf490b289249054a8c37f9
4
- data.tar.gz: 9a8ca82bdd368ef020c97fbf156aba1e5d3cad6860e5eef4e02226165c167277
3
+ metadata.gz: d8ab3635e4795e7250a284a158d0122062460a19db75d4eb00cd8754e0cedbb5
4
+ data.tar.gz: aec727ba372fea9a0cf78fcb38e321db66845f6e8d6e63618a62b6d2ba6c780b
5
5
  SHA512:
6
- metadata.gz: 0046b1bde5286137d682244bf597e8f72a0d43a206c6013b4dc470b08b9dead8ebbe0d7aa390c63437330b9ccf15c93dbefc99ca8e5a0bd346606166232f38b9
7
- data.tar.gz: fa70c541f5cdaa6e17c2a654bf07a094cb2037a405409a9fda00fe8f7d725331cb6b66737915fe1df8b39a2f7c8bdbe4bcd887a1a536fd7c1420fa8bcbbdd971
6
+ metadata.gz: 8deb4362ac6f4d89ba6dc3d8c7f5d2dc3887bf1e433ca2dba9151ffcd0905edfaddf62757f3600fae74f6eb53982c7f1ba7b35a4e8e55e1e62bb03d84f54e43c
7
+ data.tar.gz: 3c190b0887928dfedd7cd5cfae45fa1858f248417461e7e05411a63c93cd827844a18ef3c0462e1b3fe7120ad3487b9e0c77ab7fc61fa9bfb2fb37ea0f39654b
@@ -21,7 +21,7 @@ module Mirrorfile
21
21
  class CLI
22
22
  # Available CLI commands
23
23
  # @return [Array<String>] list of valid commands
24
- COMMANDS = %w[init install update list git help].freeze
24
+ COMMANDS = %w[init install update list git migrate-to-v1 help].freeze
25
25
 
26
26
  # Creates a new CLI instance.
27
27
  #
@@ -70,8 +70,9 @@ module Mirrorfile
70
70
  when 'install' then install
71
71
  when 'update' then update
72
72
  when 'list' then list
73
- when 'git' then git(args.drop(1))
74
- when 'help' then help
73
+ when 'git' then git(args.drop(1))
74
+ when 'migrate-to-v1' then migrate_to_v1
75
+ when 'help' then help
75
76
  when '-h', '--help' then help
76
77
  when '-v', '--version' then version
77
78
  else usage
@@ -152,6 +153,14 @@ module Mirrorfile
152
153
  system('git', '--git-dir=.git.mirror', *args)
153
154
  end
154
155
 
156
+ # Executes the migrate-to-v1 command.
157
+ #
158
+ # @return [void]
159
+ # @api private
160
+ def migrate_to_v1
161
+ Mirror.new.migrate_to_v1
162
+ end
163
+
155
164
  # Displays help information.
156
165
  #
157
166
  # @return [void]
@@ -163,13 +172,14 @@ module Mirrorfile
163
172
  Usage: mirror <command>
164
173
 
165
174
  Commands:
166
- init Initialize project with Mirrorfile, .gitignore entry,
167
- and Zeitwerk initializer for Rails projects
168
- install Clone repositories that don't exist locally
169
- update Pull latest changes for existing repositories
170
- list Show all defined mirrors
171
- git Run git commands against a .git.mirror directory
172
- help Show this help message
175
+ init Initialize project with Mirrorfile, .gitignore entry,
176
+ and Zeitwerk initializer for Rails projects
177
+ install Clone repositories that don't exist locally
178
+ update Pull latest changes for existing repositories
179
+ list Show all defined mirrors
180
+ git Run git commands against a .git.mirror directory
181
+ migrate-to-v1 Upgrade legacy mirrors to v1.0 format
182
+ help Show this help message
173
183
 
174
184
  Options:
175
185
  -h, --help Show this help message
@@ -212,12 +222,13 @@ module Mirrorfile
212
222
  Usage: mirror <command>
213
223
 
214
224
  Commands:
215
- init Create Mirrorfile, .gitignore entry, and Zeitwerk initializer (Rails only)
216
- install Clone repositories that don't exist locally
217
- update Pull latest changes for existing repositories
218
- list Show all defined mirrors
219
- git Run git commands against a .git.mirror directory
220
- help Show detailed help
225
+ init Create Mirrorfile, .gitignore entry, and Zeitwerk initializer (Rails only)
226
+ install Clone repositories that don't exist locally
227
+ update Pull latest changes for existing repositories
228
+ list Show all defined mirrors
229
+ git Run git commands against a .git.mirror directory
230
+ migrate-to-v1 Upgrade legacy mirrors to v1.0 format
231
+ help Show detailed help
221
232
 
222
233
  Run 'mirror help' for more information.
223
234
  USAGE
@@ -136,6 +136,23 @@ module Mirrorfile
136
136
  @mirrorfile.entries.to_a
137
137
  end
138
138
 
139
+ # Migrates the project to mirrorfile v1.0.
140
+ #
141
+ # Performs the following steps:
142
+ # - Updates Gemfile version constraint to ~> 1.0 (if Gemfile exists)
143
+ # - Updates the system gem if installed
144
+ # - Installs template files (.envrc, README.md) into mirrors/
145
+ # - Renames .git directories to .git.mirror in existing mirrors
146
+ #
147
+ # @return [void]
148
+ def migrate_to_v1
149
+ update_gemfile
150
+ update_system_gem
151
+ setup_templates
152
+ rename_git_dirs
153
+ puts 'Migration to v1.0 complete.'
154
+ end
155
+
139
156
  # Returns whether any mirrors use legacy .git directories.
140
157
  #
141
158
  # A project is considered legacy if any subdirectory of mirrors/
@@ -273,6 +290,63 @@ module Mirrorfile
273
290
  readme_dest.exist? || FileUtils.cp(templates_dir.join('README.md.template'), readme_dest)
274
291
  end
275
292
 
293
+ # Updates the Gemfile to use mirrorfile ~> 1.0.
294
+ #
295
+ # Replaces any existing mirrorfile gem declaration with one
296
+ # constrained to ~> 1.0. Does nothing if Gemfile doesn't exist
297
+ # or doesn't reference mirrorfile.
298
+ #
299
+ # @return [void]
300
+ # @api private
301
+ def update_gemfile
302
+ gemfile = root.join('Gemfile')
303
+ return unless gemfile.exist?
304
+
305
+ content = gemfile.read
306
+ updated = content.gsub(/^(\s*gem\s+["']mirrorfile["']).*$/, '\1, "~> 1.0"')
307
+
308
+ return unless content != updated
309
+
310
+ gemfile.write(updated)
311
+ puts 'Updated Gemfile to mirrorfile ~> 1.0'
312
+ end
313
+
314
+ # Updates the system-installed mirrorfile gem.
315
+ #
316
+ # Checks if the gem is installed globally and runs gem update
317
+ # if so.
318
+ #
319
+ # @return [void]
320
+ # @api private
321
+ def update_system_gem
322
+ return if ENV['MIRRORFILE_SKIP_GEM_UPDATE']
323
+ return unless system('gem', 'list', '-i', 'mirrorfile', out: File::NULL, err: File::NULL)
324
+
325
+ puts 'Updating system gem...'
326
+ system('gem', 'update', 'mirrorfile')
327
+ end
328
+
329
+ # Renames .git directories to .git.mirror in existing mirrors.
330
+ #
331
+ # Scans all subdirectories of mirrors/ for .git directories
332
+ # and renames them. Skips entries that already have .git.mirror.
333
+ #
334
+ # @return [void]
335
+ # @api private
336
+ def rename_git_dirs
337
+ return unless mirrors_dir.exist?
338
+
339
+ mirrors_dir.children.select(&:directory?).each do |mirror_path|
340
+ git_dir = mirror_path.join('.git')
341
+ git_mirror_dir = mirror_path.join('.git.mirror')
342
+
343
+ if git_dir.exist? && !git_mirror_dir.exist?
344
+ File.rename(git_dir.to_s, git_mirror_dir.to_s)
345
+ puts "Renamed #{mirror_path.basename}/.git to .git.mirror"
346
+ end
347
+ end
348
+ end
349
+
276
350
  # Determines if the current project is a Rails application by checking
277
351
  # for the standard Rails application entrypoint.
278
352
  #
@@ -3,5 +3,5 @@
3
3
  module Mirrorfile
4
4
  # Current version of the Mirrorfile gem
5
5
  # @return [String] the semantic version string
6
- VERSION = '1.0.0'
6
+ VERSION = '1.0.1'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mirrorfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Kidd