packs 0.0.36 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0a49abad749c63c73c0bbb9cfa0ac4d75962af3c0f5b22cfb8173906f18310e
4
- data.tar.gz: e9757c94ee7866e9ee7daaeec189166aa7a07b47baa18f93eff239552a5e94ab
3
+ metadata.gz: 61faca4f667524b1ad3ac80486441315601f3ceda6ff04c413a1412b943e7df4
4
+ data.tar.gz: 347f3a70a95fb188497f7056f88925a5c9ecc409fc0b9561d35ce8fbe13ca191
5
5
  SHA512:
6
- metadata.gz: a74621a2a3346a352256086cb534c1ef6038beac481af3559409682ce2198c4d90e16b4d276ebe271fc93d6a9d7a2260642bf0aa2b76de22cd8bd4d9f11054a1
7
- data.tar.gz: 93dc9e6df47b7150fd1c2ef1ddd312931b154934d83ae8060307ef17a6a146858b98b33f6961863a3c23348b0aa398f0c188098e6bdf5dc5c6c70547b97fc843
6
+ metadata.gz: 11de5f83297dce2506a151ceb9f6e18d2a7bdfdfb0086f3ac05b2136f2530b638817d5eea079342265102e2e652c6264f6b31df9fd58e9a1bc61a15f0d47eae9
7
+ data.tar.gz: ab4bd4f5e89f880ada5f0d9bf7d4a25119a8e3b9ca1158be241cb3b9530b6470ddf6cf817d3c2930afd53b2c0ddd17821d0ee9b42a61547d0578402f581ce87e
data/README.md CHANGED
@@ -111,7 +111,10 @@ Make sure there are no spaces between the comma-separated list of paths of direc
111
111
  `bin/packs rename`
112
112
 
113
113
  ## Set packs/child_pack as a child of packs/parent_pack
114
- `bin/packs move_to_parent packs/child_pack packs/parent_pack `
114
+ `bin/packs move_to_parent packs/child_pack packs/parent_pack`
115
+
116
+ ## Move packs/foo to the some/directory folder, where some/directory does not contain a package.yml file
117
+ `bin/packs move_to_folder packs/foo some/directory`
115
118
 
116
119
 
117
120
  ## Releasing
data/lib/packs/cli.rb CHANGED
@@ -150,7 +150,7 @@ module Packs
150
150
  exit_successfully
151
151
  end
152
152
 
153
- desc 'move_to_parent packs/child_pack packs/parent_pack ', 'Set packs/child_pack as a child of packs/parent_pack'
153
+ desc 'move_to_parent packs/child_pack packs/parent_pack', 'Set packs/child_pack as a child of packs/parent_pack'
154
154
  sig { params(child_pack_name: String, parent_pack_name: String).void }
155
155
  def move_to_parent(child_pack_name, parent_pack_name)
156
156
  Packs.move_to_parent!(
@@ -160,6 +160,16 @@ module Packs
160
160
  exit_successfully
161
161
  end
162
162
 
163
+ desc 'move_to_folder packs/foo some/directory', 'Move packs/foo to the some/directory folder, where some/directory does not contain a package.yml file'
164
+ sig { params(pack_name: String, destination: String).void }
165
+ def move_to_folder(pack_name, destination)
166
+ Packs.move_to_folder!(
167
+ pack_name: pack_name,
168
+ destination: destination
169
+ )
170
+ exit_successfully
171
+ end
172
+
163
173
  private
164
174
 
165
175
  # This is used by thor to know that these private methods are not intended to be CLI commands
data/lib/packs/private.rb CHANGED
@@ -140,6 +140,83 @@ module Packs
140
140
  end
141
141
  end
142
142
 
143
+ sig do
144
+ params(
145
+ pack_name: String,
146
+ destination: String,
147
+ per_file_processors: T::Array[PerFileProcessorInterface]
148
+ ).void
149
+ end
150
+ def self.move_to_folder!(pack_name:, destination:, per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new])
151
+ pack_name = Private.clean_pack_name(pack_name)
152
+ package = ParsePackwerk.all.find { |p| p.name == pack_name }
153
+ if package.nil?
154
+ raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
155
+ end
156
+
157
+ # First we create a new pack that has the exact same properties of the old one!
158
+ package_last_name = package.directory.basename
159
+ new_package_name = File.join(destination, package_last_name)
160
+
161
+ new_package = ParsePackwerk::Package.new(
162
+ name: new_package_name,
163
+ enforce_privacy: package.enforce_privacy,
164
+ enforce_dependencies: package.enforce_dependencies,
165
+ dependencies: package.dependencies,
166
+ violations: package.violations,
167
+ metadata: package.metadata,
168
+ config: package.config
169
+ )
170
+ ParsePackwerk.write_package_yml!(new_package)
171
+ ParsePackwerk.bust_cache!
172
+
173
+ # Move everything from the old pack to the new one
174
+ move_to_pack!(
175
+ pack_name: new_package_name,
176
+ paths_relative_to_root: [package.directory.to_s],
177
+ per_file_processors: per_file_processors
178
+ )
179
+
180
+ # Then delete the old package.yml and package_todo.yml files
181
+ package.yml.delete
182
+ package_todo_file = ParsePackwerk::PackageTodo.for(package).pathname
183
+ package_todo_file.delete if package_todo_file.exist?
184
+
185
+ ParsePackwerk.bust_cache!
186
+
187
+ ParsePackwerk.all.each do |other_package|
188
+ new_dependencies = other_package.dependencies.map { |d| d == pack_name ? new_package_name : d }
189
+
190
+ new_config = other_package.config.dup
191
+ if new_config['ignored_dependencies']
192
+ new_config['ignored_dependencies'] = new_config['ignored_dependencies'].map do |d|
193
+ d == pack_name ? new_package_name : d
194
+ end
195
+ end
196
+
197
+ new_other_package = ParsePackwerk::Package.new(
198
+ name: other_package.name,
199
+ enforce_privacy: other_package.enforce_privacy,
200
+ enforce_dependencies: other_package.enforce_dependencies,
201
+ dependencies: new_dependencies.uniq.sort,
202
+ violations: other_package.violations,
203
+ metadata: other_package.metadata,
204
+ config: new_config
205
+ )
206
+
207
+ ParsePackwerk.write_package_yml!(new_other_package)
208
+ end
209
+
210
+ sorbet_config = Pathname.new('sorbet/config')
211
+ if sorbet_config.exist?
212
+ Packs.replace_in_file(
213
+ file: sorbet_config.to_s,
214
+ find: package.directory.join('spec'),
215
+ replace_with: new_package.directory.join('spec')
216
+ )
217
+ end
218
+ end
219
+
143
220
  sig do
144
221
  params(
145
222
  pack_name: String,
@@ -105,6 +105,24 @@ module Packs
105
105
  MSG
106
106
  end
107
107
 
108
+ sig { params(pack_name: String).returns(String) }
109
+ def before_move_to_folder(pack_name)
110
+ <<~MSG
111
+ You are moving one pack to a new directory. Check out #{documentation_link} for more info!
112
+ MSG
113
+ end
114
+
115
+ sig { params(pack_name: String).returns(String) }
116
+ def after_move_to_folder(pack_name)
117
+ <<~MSG
118
+ Your next steps might be:
119
+
120
+ 1) Delete the old pack when things look good: `git rm -r #{pack_name}`
121
+
122
+ 2) Run `bin/packwerk update-todo` to update the violations. Make sure to run `spring stop` first.
123
+ MSG
124
+ end
125
+
108
126
  sig { params(pack_name: String).returns(String) }
109
127
  def on_create_public_directory_todo(pack_name)
110
128
  <<~MSG
data/lib/packs.rb CHANGED
@@ -178,6 +178,36 @@ module Packs
178
178
  end
179
179
  end
180
180
 
181
+ sig do
182
+ params(
183
+ pack_name: String,
184
+ destination: String,
185
+ per_file_processors: T::Array[PerFileProcessorInterface]
186
+ ).void
187
+ end
188
+ def self.move_to_folder!(
189
+ pack_name:,
190
+ destination:,
191
+ per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
192
+ )
193
+ Logging.section('👋 Hi!') do
194
+ intro = Packs.config.user_event_logger.before_move_to_folder(pack_name)
195
+ Logging.print_bold_green(intro)
196
+ end
197
+
198
+ Private.move_to_folder!(
199
+ pack_name: pack_name,
200
+ destination: destination,
201
+ per_file_processors: per_file_processors
202
+ )
203
+
204
+ Logging.section('Next steps') do
205
+ next_steps = Packs.config.user_event_logger.after_move_to_folder(pack_name)
206
+
207
+ Logging.print_bold_green(next_steps)
208
+ end
209
+ end
210
+
181
211
  sig do
182
212
  params(
183
213
  type: String,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.36
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-28 00:00:00.000000000 Z
11
+ date: 2023-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership