updater_gf 0.1.1 → 0.1.3
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/bin/updater_gf +8 -1
- data/lib/updater_gf/.rubocop.yml +414 -0
- data/lib/updater_gf/constants.rb +24 -0
- data/lib/updater_gf/handle_rubocop.rb +30 -0
- data/lib/updater_gf/handle_update.rb +153 -0
- data/lib/updater_gf/version.rb +1 -1
- data/lib/updater_gf.rb +5 -114
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04dd7ddb74f712be09341db4c98984c3e6697b4218439c72a5c1eddf417174f1
|
4
|
+
data.tar.gz: 688e22dc6c52147e978db6644b921896f3eaaee72237581640ce327633449154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d727b8ac34667c36d4ce08e7ea7e49ea007c56bc6ad8efc9462a16d9198626e9255cb9e714dfcf7071b4d62d16524517bf5a9c356589e5851342f9d2e5323be4
|
7
|
+
data.tar.gz: e2bc0b8a935d19e70b784e774496899548deeffc63ac0ff310536a9018f1cb52823af097384e12c4d66820662b3568e854c20bc362b64c9944af3431a7e06121
|
data/bin/updater_gf
CHANGED
@@ -6,5 +6,12 @@ require 'updater_gf'
|
|
6
6
|
|
7
7
|
# Run the updater
|
8
8
|
puts 'Running the updater gemfile'
|
9
|
-
|
9
|
+
if ARGV.length > 2
|
10
|
+
puts 'accepts only 2 parameters at most:'
|
11
|
+
puts '-a and -r'
|
12
|
+
puts "'-a' will add commonly used gems"
|
13
|
+
puts "'-r' will update robocop file"
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
UpdaterGf::Updater.run(ARGV[0], ARGV[1])
|
10
17
|
puts 'Finished running the updater gemfile'
|
@@ -0,0 +1,414 @@
|
|
1
|
+
# Omakase Ruby styling for Rails
|
2
|
+
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
|
3
|
+
|
4
|
+
# Overwrite or add rules to create your own house style
|
5
|
+
#
|
6
|
+
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
|
7
|
+
# Layout/SpaceInsideArrayLiteralBrackets:
|
8
|
+
# Enabled: false
|
9
|
+
|
10
|
+
require:
|
11
|
+
- rubocop-minitest
|
12
|
+
- rubocop-packaging
|
13
|
+
- rubocop-performance
|
14
|
+
- rubocop-rails
|
15
|
+
- rubocop-md
|
16
|
+
|
17
|
+
AllCops:
|
18
|
+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
19
|
+
# to ignore them, so only the ones explicitly set in this file are enabled.
|
20
|
+
DisabledByDefault: true
|
21
|
+
SuggestExtensions: false
|
22
|
+
Exclude:
|
23
|
+
- '**/tmp/**/*'
|
24
|
+
- '**/templates/**/*'
|
25
|
+
- '**/vendor/**/*'
|
26
|
+
- 'actionmailbox/test/dummy/**/*'
|
27
|
+
- 'activestorage/test/dummy/**/*'
|
28
|
+
- 'actiontext/test/dummy/**/*'
|
29
|
+
- 'tools/rail_inspector/test/fixtures/*'
|
30
|
+
- guides/source/debugging_rails_applications.md
|
31
|
+
- guides/source/active_support_instrumentation.md
|
32
|
+
- '**/node_modules/**/*'
|
33
|
+
- '**/CHANGELOG.md'
|
34
|
+
- '**/2_*_release_notes.md'
|
35
|
+
- '**/3_*_release_notes.md'
|
36
|
+
- '**/4_*_release_notes.md'
|
37
|
+
- '**/5_*_release_notes.md'
|
38
|
+
- '**/6_*_release_notes.md'
|
39
|
+
|
40
|
+
|
41
|
+
Performance:
|
42
|
+
Exclude:
|
43
|
+
- '**/test/**/*'
|
44
|
+
|
45
|
+
# Prefer assert_not over assert !
|
46
|
+
Rails/AssertNot:
|
47
|
+
Include:
|
48
|
+
- '**/test/**/*'
|
49
|
+
|
50
|
+
# Prefer assert_not_x over refute_x
|
51
|
+
Rails/RefuteMethods:
|
52
|
+
Include:
|
53
|
+
- '**/test/**/*'
|
54
|
+
|
55
|
+
Rails/IndexBy:
|
56
|
+
Enabled: true
|
57
|
+
|
58
|
+
Rails/IndexWith:
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
# Prefer &&/|| over and/or.
|
62
|
+
Style/AndOr:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Layout/ClosingHeredocIndentation:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
Layout/ClosingParenthesisIndentation:
|
69
|
+
Enabled: true
|
70
|
+
|
71
|
+
# Align comments with method definitions.
|
72
|
+
Layout/CommentIndentation:
|
73
|
+
Enabled: true
|
74
|
+
|
75
|
+
Layout/DefEndAlignment:
|
76
|
+
Enabled: true
|
77
|
+
|
78
|
+
Layout/ElseAlignment:
|
79
|
+
Enabled: true
|
80
|
+
|
81
|
+
# Align `end` with the matching keyword or starting expression except for
|
82
|
+
# assignments, where it should be aligned with the LHS.
|
83
|
+
Layout/EndAlignment:
|
84
|
+
Enabled: true
|
85
|
+
EnforcedStyleAlignWith: variable
|
86
|
+
AutoCorrect: true
|
87
|
+
|
88
|
+
Layout/EndOfLine:
|
89
|
+
Enabled: true
|
90
|
+
|
91
|
+
Layout/EmptyLineAfterMagicComment:
|
92
|
+
Enabled: true
|
93
|
+
|
94
|
+
Layout/EmptyLinesAroundAccessModifier:
|
95
|
+
Enabled: true
|
96
|
+
EnforcedStyle: only_before
|
97
|
+
|
98
|
+
Layout/EmptyLinesAroundBlockBody:
|
99
|
+
Enabled: true
|
100
|
+
|
101
|
+
# In a regular class definition, no empty lines around the body.
|
102
|
+
Layout/EmptyLinesAroundClassBody:
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
# In a regular method definition, no empty lines around the body.
|
106
|
+
Layout/EmptyLinesAroundMethodBody:
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
# In a regular module definition, no empty lines around the body.
|
110
|
+
Layout/EmptyLinesAroundModuleBody:
|
111
|
+
Enabled: true
|
112
|
+
|
113
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
114
|
+
Style/HashSyntax:
|
115
|
+
Enabled: true
|
116
|
+
EnforcedShorthandSyntax: either
|
117
|
+
|
118
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
119
|
+
# extra level of indentation.
|
120
|
+
Layout/IndentationConsistency:
|
121
|
+
Enabled: true
|
122
|
+
EnforcedStyle: indented_internal_methods
|
123
|
+
Exclude:
|
124
|
+
- '**/*.md'
|
125
|
+
|
126
|
+
# Two spaces, no tabs (for indentation).
|
127
|
+
Layout/IndentationWidth:
|
128
|
+
Enabled: true
|
129
|
+
|
130
|
+
Layout/LeadingCommentSpace:
|
131
|
+
Enabled: true
|
132
|
+
|
133
|
+
Layout/SpaceAfterColon:
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
Layout/SpaceAfterComma:
|
137
|
+
Enabled: true
|
138
|
+
|
139
|
+
Layout/SpaceAfterSemicolon:
|
140
|
+
Enabled: true
|
141
|
+
|
142
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
143
|
+
Enabled: true
|
144
|
+
|
145
|
+
Layout/SpaceAroundKeyword:
|
146
|
+
Enabled: true
|
147
|
+
|
148
|
+
Layout/SpaceAroundOperators:
|
149
|
+
Enabled: true
|
150
|
+
|
151
|
+
Layout/SpaceBeforeComma:
|
152
|
+
Enabled: true
|
153
|
+
|
154
|
+
Layout/SpaceBeforeComment:
|
155
|
+
Enabled: true
|
156
|
+
|
157
|
+
Layout/SpaceBeforeFirstArg:
|
158
|
+
Enabled: true
|
159
|
+
|
160
|
+
Style/DefWithParentheses:
|
161
|
+
Enabled: true
|
162
|
+
|
163
|
+
# Defining a method with parameters needs parentheses.
|
164
|
+
Style/MethodDefParentheses:
|
165
|
+
Enabled: true
|
166
|
+
|
167
|
+
Style/ExplicitBlockArgument:
|
168
|
+
Enabled: true
|
169
|
+
|
170
|
+
Style/FrozenStringLiteralComment:
|
171
|
+
Enabled: true
|
172
|
+
EnforcedStyle: always
|
173
|
+
Exclude:
|
174
|
+
- 'actionview/test/**/*.builder'
|
175
|
+
- 'actionview/test/**/*.ruby'
|
176
|
+
- 'actionpack/test/**/*.builder'
|
177
|
+
- 'actionpack/test/**/*.ruby'
|
178
|
+
- 'activestorage/db/migrate/**/*.rb'
|
179
|
+
- 'activestorage/db/update_migrate/**/*.rb'
|
180
|
+
- 'actionmailbox/db/migrate/**/*.rb'
|
181
|
+
- 'actiontext/db/migrate/**/*.rb'
|
182
|
+
- '**/*.md'
|
183
|
+
|
184
|
+
Style/MapToHash:
|
185
|
+
Enabled: true
|
186
|
+
|
187
|
+
Style/RedundantFreeze:
|
188
|
+
Enabled: true
|
189
|
+
|
190
|
+
# Use `foo {}` not `foo{}`.
|
191
|
+
Layout/SpaceBeforeBlockBraces:
|
192
|
+
Enabled: true
|
193
|
+
|
194
|
+
# Use `foo { bar }` not `foo {bar}`.
|
195
|
+
Layout/SpaceInsideBlockBraces:
|
196
|
+
Enabled: true
|
197
|
+
EnforcedStyleForEmptyBraces: space
|
198
|
+
|
199
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
200
|
+
Layout/SpaceInsideHashLiteralBraces:
|
201
|
+
Enabled: true
|
202
|
+
|
203
|
+
Layout/SpaceInsideParens:
|
204
|
+
Enabled: true
|
205
|
+
|
206
|
+
# Check quotes usage according to lint rule below.
|
207
|
+
Style/StringLiterals:
|
208
|
+
Enabled: true
|
209
|
+
EnforcedStyle: double_quotes
|
210
|
+
|
211
|
+
# Detect hard tabs, no hard tabs.
|
212
|
+
Layout/IndentationStyle:
|
213
|
+
Enabled: true
|
214
|
+
|
215
|
+
# Empty lines should not have any spaces.
|
216
|
+
Layout/TrailingEmptyLines:
|
217
|
+
Enabled: true
|
218
|
+
|
219
|
+
# No trailing whitespace.
|
220
|
+
Layout/TrailingWhitespace:
|
221
|
+
Enabled: true
|
222
|
+
|
223
|
+
# Use quotes for string literals when they are enough.
|
224
|
+
Style/RedundantPercentQ:
|
225
|
+
Enabled: true
|
226
|
+
|
227
|
+
Lint/AmbiguousOperator:
|
228
|
+
Enabled: true
|
229
|
+
|
230
|
+
Lint/AmbiguousRegexpLiteral:
|
231
|
+
Enabled: true
|
232
|
+
|
233
|
+
Lint/Debugger:
|
234
|
+
Enabled: true
|
235
|
+
DebuggerRequires:
|
236
|
+
- debug
|
237
|
+
|
238
|
+
Lint/DuplicateRequire:
|
239
|
+
Enabled: true
|
240
|
+
|
241
|
+
Lint/DuplicateMagicComment:
|
242
|
+
Enabled: true
|
243
|
+
|
244
|
+
Lint/DuplicateMethods:
|
245
|
+
Enabled: true
|
246
|
+
|
247
|
+
Lint/ErbNewArguments:
|
248
|
+
Enabled: true
|
249
|
+
|
250
|
+
Lint/EnsureReturn:
|
251
|
+
Enabled: true
|
252
|
+
|
253
|
+
Lint/MissingCopEnableDirective:
|
254
|
+
Enabled: true
|
255
|
+
|
256
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
257
|
+
Lint/RequireParentheses:
|
258
|
+
Enabled: true
|
259
|
+
|
260
|
+
Lint/RedundantCopDisableDirective:
|
261
|
+
Enabled: true
|
262
|
+
|
263
|
+
Lint/RedundantCopEnableDirective:
|
264
|
+
Enabled: true
|
265
|
+
|
266
|
+
Lint/RedundantRequireStatement:
|
267
|
+
Enabled: true
|
268
|
+
|
269
|
+
Lint/RedundantStringCoercion:
|
270
|
+
Enabled: true
|
271
|
+
|
272
|
+
Lint/RedundantSafeNavigation:
|
273
|
+
Enabled: true
|
274
|
+
|
275
|
+
Lint/UriEscapeUnescape:
|
276
|
+
Enabled: true
|
277
|
+
|
278
|
+
Lint/UselessAssignment:
|
279
|
+
Enabled: true
|
280
|
+
|
281
|
+
Lint/DeprecatedClassMethods:
|
282
|
+
Enabled: true
|
283
|
+
|
284
|
+
Lint/InterpolationCheck:
|
285
|
+
Enabled: true
|
286
|
+
Exclude:
|
287
|
+
- '**/test/**/*'
|
288
|
+
|
289
|
+
Lint/SafeNavigationChain:
|
290
|
+
Enabled: true
|
291
|
+
|
292
|
+
Style/EvalWithLocation:
|
293
|
+
Enabled: true
|
294
|
+
Exclude:
|
295
|
+
- '**/test/**/*'
|
296
|
+
|
297
|
+
Style/ParenthesesAroundCondition:
|
298
|
+
Enabled: true
|
299
|
+
|
300
|
+
Style/HashTransformKeys:
|
301
|
+
Enabled: true
|
302
|
+
|
303
|
+
Style/HashTransformValues:
|
304
|
+
Enabled: true
|
305
|
+
|
306
|
+
Style/RedundantBegin:
|
307
|
+
Enabled: true
|
308
|
+
|
309
|
+
Style/RedundantReturn:
|
310
|
+
Enabled: true
|
311
|
+
AllowMultipleReturnValues: true
|
312
|
+
|
313
|
+
Style/RedundantRegexpEscape:
|
314
|
+
Enabled: true
|
315
|
+
|
316
|
+
Style/Semicolon:
|
317
|
+
Enabled: true
|
318
|
+
AllowAsExpressionSeparator: true
|
319
|
+
|
320
|
+
# Prefer Foo.method over Foo::method
|
321
|
+
Style/ColonMethodCall:
|
322
|
+
Enabled: true
|
323
|
+
|
324
|
+
Style/TrivialAccessors:
|
325
|
+
Enabled: true
|
326
|
+
|
327
|
+
# Prefer a = b || c over a = b ? b : c
|
328
|
+
Style/RedundantCondition:
|
329
|
+
Enabled: true
|
330
|
+
|
331
|
+
Style/RedundantDoubleSplatHashBraces:
|
332
|
+
Enabled: true
|
333
|
+
|
334
|
+
Style/OpenStructUse:
|
335
|
+
Enabled: true
|
336
|
+
|
337
|
+
Style/ArrayIntersect:
|
338
|
+
Enabled: true
|
339
|
+
|
340
|
+
Performance/BindCall:
|
341
|
+
Enabled: true
|
342
|
+
|
343
|
+
Performance/FlatMap:
|
344
|
+
Enabled: true
|
345
|
+
|
346
|
+
Performance/MapCompact:
|
347
|
+
Enabled: true
|
348
|
+
|
349
|
+
Performance/SelectMap:
|
350
|
+
Enabled: true
|
351
|
+
|
352
|
+
Performance/RedundantMerge:
|
353
|
+
Enabled: true
|
354
|
+
|
355
|
+
Performance/StartWith:
|
356
|
+
Enabled: true
|
357
|
+
|
358
|
+
Performance/EndWith:
|
359
|
+
Enabled: true
|
360
|
+
|
361
|
+
Performance/RegexpMatch:
|
362
|
+
Enabled: true
|
363
|
+
|
364
|
+
Performance/ReverseEach:
|
365
|
+
Enabled: true
|
366
|
+
|
367
|
+
Performance/StringReplacement:
|
368
|
+
Enabled: true
|
369
|
+
|
370
|
+
Performance/DeletePrefix:
|
371
|
+
Enabled: true
|
372
|
+
|
373
|
+
Performance/DeleteSuffix:
|
374
|
+
Enabled: true
|
375
|
+
|
376
|
+
Performance/InefficientHashSearch:
|
377
|
+
Enabled: true
|
378
|
+
|
379
|
+
Performance/ConstantRegexp:
|
380
|
+
Enabled: true
|
381
|
+
|
382
|
+
Performance/RedundantStringChars:
|
383
|
+
Enabled: true
|
384
|
+
|
385
|
+
Performance/StringInclude:
|
386
|
+
Enabled: true
|
387
|
+
|
388
|
+
Minitest/AssertPredicate:
|
389
|
+
Enabled: true
|
390
|
+
|
391
|
+
Minitest/AssertRaisesWithRegexpArgument:
|
392
|
+
Enabled: true
|
393
|
+
|
394
|
+
Minitest/AssertWithExpectedArgument:
|
395
|
+
Enabled: true
|
396
|
+
|
397
|
+
Minitest/LiteralAsActualArgument:
|
398
|
+
Enabled: true
|
399
|
+
|
400
|
+
Minitest/NonExecutableTestMethod:
|
401
|
+
Enabled: true
|
402
|
+
|
403
|
+
Minitest/SkipEnsure:
|
404
|
+
Enabled: true
|
405
|
+
|
406
|
+
Minitest/UnreachableAssertion:
|
407
|
+
Enabled: true
|
408
|
+
|
409
|
+
Markdown:
|
410
|
+
# Whether to run RuboCop against non-valid snippets
|
411
|
+
WarnInvalid: true
|
412
|
+
# Whether to lint codeblocks without code attributes
|
413
|
+
Autodetect: false
|
414
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Constants
|
4
|
+
LIST_GEMS_ADD = [
|
5
|
+
{ name: 'ransack', version: '~> 4.2', condition: '>= 4.2.1' },
|
6
|
+
{ name: 'devise', version: '~> 4.9', condition: '>= 4.9.4' },
|
7
|
+
{ name: 'pagy', version: '~> 9.1' },
|
8
|
+
{ name: 'pundit', version: '~> 2.4' },
|
9
|
+
{ name: 'rack-cors', version: '~> 2.0', condition: '>= 2.0.1' },
|
10
|
+
{ name: 'redis', version: '~> 5.3' },
|
11
|
+
{ name: 'sidekiq', version: '~> 7.3', condition: '>= 7.3.2' },
|
12
|
+
{ name: 'draper', version: '~> 4.0', condition: '>= 4.0.2' },
|
13
|
+
{ name: 'paranoia', version: '~> 3.0' },
|
14
|
+
{ name: 'activeadmin', version: '~> 3.2', condition: '>= 3.2.5' }
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
LIST_GEMS_ADD_DEVELOP = [
|
18
|
+
{ name: 'pry' },
|
19
|
+
{ name: 'letter_opener', version: '~> 1.10' },
|
20
|
+
{ name: 'bullet', version: '~> 7.2' },
|
21
|
+
{ name: 'better_errors', version: '~> 2.10', condition: '>= 2.10.1' },
|
22
|
+
{ name: 'binding_of_caller', version: '~> 1.0', condition: '>= 1.0.1' }
|
23
|
+
].freeze
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
module UpdaterGf
|
5
|
+
# class HandleRubocop
|
6
|
+
class HandleRubocop
|
7
|
+
attr_reader :project_root
|
8
|
+
|
9
|
+
def initialize(project_root)
|
10
|
+
@project_root = project_root
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
unless project_root
|
15
|
+
puts 'Project root is not specified'
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
rubocop_yml_path = File.join(project_root, '.rubocop.yml')
|
20
|
+
new_rubocop_yml_path = File.expand_path('../../.rubocop.yml', __FILE__)
|
21
|
+
|
22
|
+
if File.exist?(rubocop_yml_path) && File.exist?(new_rubocop_yml_path)
|
23
|
+
FileUtils.cp(new_rubocop_yml_path, rubocop_yml_path)
|
24
|
+
puts 'Updated .rubocop.yml'
|
25
|
+
else
|
26
|
+
puts 'Either .rubocop.yml does not exist'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'constants'
|
4
|
+
require_relative 'handle_rubocop'
|
5
|
+
|
6
|
+
module UpdaterGf
|
7
|
+
# HandleUpdate class
|
8
|
+
class HandleUpdate
|
9
|
+
attr_reader :is_add_gem, :is_add_robocop
|
10
|
+
|
11
|
+
def initialize(is_add_gem, is_add_robocop)
|
12
|
+
@is_add_gem = is_add_gem
|
13
|
+
@is_add_robocop = is_add_robocop
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
gemfile_path = find_gemfile_path
|
18
|
+
content = File.read(gemfile_path)
|
19
|
+
|
20
|
+
# Replace all double quotes with single quotes
|
21
|
+
updated_content = content.gsub(/"/, "'")
|
22
|
+
updated_content = update_final_content(updated_content) if is_add_gem
|
23
|
+
File.write(gemfile_path, updated_content)
|
24
|
+
HandleRubocop.new(find_project_root).run if is_add_robocop
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def update_final_content(updated_content)
|
30
|
+
lines = updated_content.lines
|
31
|
+
group_test_end_index = find_group_test_end_index(lines)
|
32
|
+
return updated_content if group_test_end_index.nil?
|
33
|
+
|
34
|
+
below_group_test_lines = lines[(group_test_end_index + 1)..]
|
35
|
+
other_lines = get_other_lines(below_group_test_lines)
|
36
|
+
sorted_gem_lines = sorted_gem_lines(below_group_test_lines)
|
37
|
+
final_lines = lines[0..group_test_end_index] + other_lines + sorted_gem_lines
|
38
|
+
|
39
|
+
# Add gems from list_gems_add if not already present
|
40
|
+
final_lines += add_missing_gems(final_lines, Constants::LIST_GEMS_ADD)
|
41
|
+
|
42
|
+
# Sort gem lines alphabetically after adding new gems, but only those after the group :test block
|
43
|
+
final_lines = sort_gem_lines_after_test_block(final_lines, group_test_end_index)
|
44
|
+
|
45
|
+
# Add gems from list_gems_add_develop to group :development if not already present
|
46
|
+
final_lines = add_gems_to_development_group(final_lines, Constants::LIST_GEMS_ADD_DEVELOP)
|
47
|
+
|
48
|
+
final_lines.join
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_gemfile_path
|
52
|
+
current_dir = Dir.pwd
|
53
|
+
|
54
|
+
until File.exist?(File.join(current_dir, 'Gemfile'))
|
55
|
+
parent_dir = File.expand_path('..', current_dir)
|
56
|
+
break if current_dir == parent_dir # Reached the root directory
|
57
|
+
|
58
|
+
current_dir = parent_dir
|
59
|
+
end
|
60
|
+
|
61
|
+
gemfile_path = File.join(current_dir, 'Gemfile')
|
62
|
+
raise Error, 'Gemfile not found' unless File.exist?(gemfile_path)
|
63
|
+
|
64
|
+
gemfile_path
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_project_root
|
68
|
+
current_dir = Dir.pwd
|
69
|
+
until File.exist?(File.join(current_dir, 'Gemfile'))
|
70
|
+
parent_dir = File.expand_path('..', current_dir)
|
71
|
+
return nil if current_dir == parent_dir # Reached the root directory
|
72
|
+
|
73
|
+
current_dir = parent_dir
|
74
|
+
end
|
75
|
+
current_dir
|
76
|
+
end
|
77
|
+
|
78
|
+
def find_group_test_end_index(lines)
|
79
|
+
group_test_start_index = lines.index { |line| line.strip == 'group :test do' }
|
80
|
+
return nil if group_test_start_index.nil?
|
81
|
+
|
82
|
+
group_test_end_index = lines[group_test_start_index..].index { |line| line.strip == 'end' }
|
83
|
+
return nil if group_test_end_index.nil?
|
84
|
+
|
85
|
+
group_test_start_index + group_test_end_index
|
86
|
+
end
|
87
|
+
|
88
|
+
def sorted_gem_lines(below_group_test_lines)
|
89
|
+
get_gem_lines(below_group_test_lines).sort_by { |line| line.match(/gem '([^']+)'/)[1] }
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_gem_lines(below_group_test_lines)
|
93
|
+
below_group_test_lines.select { |line| line.strip.start_with?("gem '") && !line.strip.start_with?('#') }
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_other_lines(below_group_test_lines)
|
97
|
+
below_group_test_lines.reject { |line| line.strip.start_with?("gem '") && !line.strip.start_with?('#') }
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_missing_gems(final_lines, gems_list)
|
101
|
+
existing_gems = final_lines.select { |line| line.strip.start_with?("gem '") }.map do |line|
|
102
|
+
match = line.match(/gem '([^']+)'/)
|
103
|
+
match[1]
|
104
|
+
end
|
105
|
+
missing_gems = gems_list.reject do |gem|
|
106
|
+
existing_gems.include?(gem[:name])
|
107
|
+
end
|
108
|
+
missing_gems.map do |gem|
|
109
|
+
version_string = gem[:version] ? ", '#{gem[:version]}'" : ''
|
110
|
+
condition_string = gem[:condition] ? ", '#{gem[:condition]}'" : ''
|
111
|
+
"gem '#{gem[:name]}'#{version_string}#{condition_string}\n"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def sort_gem_lines_after_test_block(final_lines, group_test_end_index)
|
116
|
+
lines_after_test_block = final_lines[(group_test_end_index + 1)..]
|
117
|
+
gem_lines = lines_after_test_block.select { |line| line.strip.start_with?("gem '") }
|
118
|
+
other_lines = lines_after_test_block.reject { |line| line.strip.start_with?("gem '") }
|
119
|
+
sorted_gem_lines = gem_lines.sort_by { |line| line.match(/gem '([^']+)'/)[1] }
|
120
|
+
final_lines[0..group_test_end_index] + other_lines + sorted_gem_lines
|
121
|
+
end
|
122
|
+
|
123
|
+
def add_gems_to_development_group(final_lines, gems_list)
|
124
|
+
development_group_start_index = final_lines.index { |line| line.strip == 'group :development do' }
|
125
|
+
return final_lines if development_group_start_index.nil?
|
126
|
+
|
127
|
+
development_group_end_index = final_lines[development_group_start_index..].index { |line| line.strip == 'end' }
|
128
|
+
return final_lines if development_group_end_index.nil?
|
129
|
+
|
130
|
+
development_group_end_index += development_group_start_index
|
131
|
+
|
132
|
+
development_group_lines = final_lines[(development_group_start_index + 1)...development_group_end_index]
|
133
|
+
existing_gems = development_group_lines.select { |line| line.strip.start_with?("gem '") }.map do |line|
|
134
|
+
match = line.match(/gem '([^']+)'/)
|
135
|
+
match[1]
|
136
|
+
end
|
137
|
+
|
138
|
+
missing_gems = gems_list.reject do |gem|
|
139
|
+
existing_gems.include?(gem[:name])
|
140
|
+
end
|
141
|
+
new_gem_lines = missing_gems.map do |gem|
|
142
|
+
version_string = gem[:version] ? ", '#{gem[:version]}'" : ''
|
143
|
+
condition_string = gem[:condition] ? ", '#{gem[:condition]}'" : ''
|
144
|
+
" gem '#{gem[:name]}'#{version_string}#{condition_string}\n"
|
145
|
+
end
|
146
|
+
|
147
|
+
final_lines[0..development_group_start_index] +
|
148
|
+
development_group_lines +
|
149
|
+
new_gem_lines +
|
150
|
+
final_lines[development_group_end_index..]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/lib/updater_gf/version.rb
CHANGED
data/lib/updater_gf.rb
CHANGED
@@ -1,124 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
|
3
|
+
require_relative 'updater_gf/version'
|
4
|
+
require_relative 'updater_gf/handle_update'
|
5
5
|
module UpdaterGf
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
|
+
# class Updater
|
8
9
|
class Updater
|
9
10
|
class << self
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
until File.exist?(File.join(current_dir, 'Gemfile'))
|
14
|
-
parent_dir = File.expand_path('..', current_dir)
|
15
|
-
break if current_dir == parent_dir # Reached the root directory
|
16
|
-
|
17
|
-
current_dir = parent_dir
|
18
|
-
end
|
19
|
-
|
20
|
-
gemfile_path = File.join(current_dir, 'Gemfile')
|
21
|
-
raise Error, 'Gemfile not found' unless File.exist?(gemfile_path)
|
22
|
-
|
23
|
-
gemfile_path
|
24
|
-
end
|
25
|
-
|
26
|
-
def update_gemfile
|
27
|
-
gemfile_path = find_gemfile_path
|
28
|
-
content = File.read(gemfile_path)
|
29
|
-
|
30
|
-
# Replace all double quotes with single quotes
|
31
|
-
updated_content = content.gsub(/"/, "'")
|
32
|
-
|
33
|
-
final_content = update_final_content(updated_content)
|
34
|
-
|
35
|
-
File.write(gemfile_path, final_content)
|
36
|
-
end
|
37
|
-
|
38
|
-
def update_final_content(updated_content)
|
39
|
-
lines = updated_content.lines
|
40
|
-
group_test_end_index = find_group_test_end_index(lines)
|
41
|
-
return updated_content if group_test_end_index.nil?
|
42
|
-
|
43
|
-
below_group_test_lines = lines[(group_test_end_index + 1)..]
|
44
|
-
other_lines = get_other_lines(below_group_test_lines)
|
45
|
-
sorted_gem_lines = sorted_gem_lines(below_group_test_lines)
|
46
|
-
final_lines = lines[0..group_test_end_index] + other_lines + sorted_gem_lines
|
47
|
-
|
48
|
-
# Add gems from list_gems_add if not already present
|
49
|
-
final_lines += add_missing_gems(final_lines, list_gems_add)
|
50
|
-
|
51
|
-
# Sort gem lines alphabetically after adding new gems, but only those after the group :test block
|
52
|
-
final_lines = sort_gem_lines_after_test_block(final_lines, group_test_end_index)
|
53
|
-
|
54
|
-
# Add gems from list_gems_add_develop to group :development if not already present
|
55
|
-
final_lines = add_gems_to_development_group(final_lines, list_gems_add_develop)
|
56
|
-
|
57
|
-
final_lines.join
|
58
|
-
end
|
59
|
-
|
60
|
-
def find_group_test_end_index(lines)
|
61
|
-
group_test_start_index = lines.index { |line| line.strip == 'group :test do' }
|
62
|
-
return nil if group_test_start_index.nil?
|
63
|
-
|
64
|
-
group_test_end_index = lines[group_test_start_index..].index { |line| line.strip == 'end' }
|
65
|
-
return nil if group_test_end_index.nil?
|
66
|
-
|
67
|
-
group_test_start_index + group_test_end_index
|
68
|
-
end
|
69
|
-
|
70
|
-
def sorted_gem_lines(below_group_test_lines)
|
71
|
-
get_gem_lines(below_group_test_lines).sort_by { |line| line.match(/gem '([^']+)'/)[1] }
|
72
|
-
end
|
73
|
-
|
74
|
-
def get_gem_lines(below_group_test_lines)
|
75
|
-
below_group_test_lines.select { |line| line.strip.start_with?("gem '") && !line.strip.start_with?('#') }
|
76
|
-
end
|
77
|
-
|
78
|
-
def get_other_lines(below_group_test_lines)
|
79
|
-
below_group_test_lines.reject { |line| line.strip.start_with?("gem '") && !line.strip.start_with?('#') }
|
80
|
-
end
|
81
|
-
|
82
|
-
def add_missing_gems(final_lines, gems_list)
|
83
|
-
existing_gems = final_lines.select { |line| line.strip.start_with?("gem '") }.map { |line| line.match(/gem '([^']+)'/)[1] }
|
84
|
-
missing_gems = gems_list - existing_gems
|
85
|
-
missing_gems.map { |gem| "gem '#{gem}'\n" }
|
86
|
-
end
|
87
|
-
|
88
|
-
def sort_gem_lines_after_test_block(final_lines, group_test_end_index)
|
89
|
-
lines_after_test_block = final_lines[(group_test_end_index + 1)..]
|
90
|
-
gem_lines = lines_after_test_block.select { |line| line.strip.start_with?("gem '") }
|
91
|
-
other_lines = lines_after_test_block.reject { |line| line.strip.start_with?("gem '") }
|
92
|
-
sorted_gem_lines = gem_lines.sort_by { |line| line.match(/gem '([^']+)'/)[1] }
|
93
|
-
final_lines[0..group_test_end_index] + other_lines + sorted_gem_lines
|
94
|
-
end
|
95
|
-
|
96
|
-
def add_gems_to_development_group(final_lines, gems_list)
|
97
|
-
development_group_start_index = final_lines.index { |line| line.strip == 'group :development do' }
|
98
|
-
return final_lines if development_group_start_index.nil?
|
99
|
-
|
100
|
-
development_group_end_index = final_lines[development_group_start_index..].index { |line| line.strip == 'end' }
|
101
|
-
return final_lines if development_group_end_index.nil?
|
102
|
-
|
103
|
-
development_group_end_index += development_group_start_index
|
104
|
-
|
105
|
-
development_group_lines = final_lines[(development_group_start_index + 1)...development_group_end_index]
|
106
|
-
existing_gems = development_group_lines.select { |line| line.strip.start_with?("gem '") }.map { |line| line.match(/gem '([^']+)'/)[1] }
|
107
|
-
missing_gems = gems_list - existing_gems
|
108
|
-
new_gem_lines = missing_gems.map { |gem| " gem '#{gem}'\n" }
|
109
|
-
|
110
|
-
final_lines[0..development_group_start_index] +
|
111
|
-
development_group_lines +
|
112
|
-
new_gem_lines +
|
113
|
-
final_lines[development_group_end_index..]
|
114
|
-
end
|
115
|
-
|
116
|
-
def list_gems_add
|
117
|
-
%w[ransack devise pagy pundit rack-cors redis sidekiq draper paranoia active_admin]
|
118
|
-
end
|
119
|
-
|
120
|
-
def list_gems_add_develop
|
121
|
-
%w[pry letter_opener bullet better_errors binding_of_caller]
|
11
|
+
def run(add_gem = '', add_robocop = '')
|
12
|
+
HandleUpdate.new(add_gem == '-a', add_robocop == '-r').process
|
122
13
|
end
|
123
14
|
end
|
124
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: updater_gf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- devhoanglv92
|
@@ -25,6 +25,10 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- bin/updater_gf
|
27
27
|
- lib/updater_gf.rb
|
28
|
+
- lib/updater_gf/.rubocop.yml
|
29
|
+
- lib/updater_gf/constants.rb
|
30
|
+
- lib/updater_gf/handle_rubocop.rb
|
31
|
+
- lib/updater_gf/handle_update.rb
|
28
32
|
- lib/updater_gf/version.rb
|
29
33
|
- sig/updater_gf.rbs
|
30
34
|
- updater_gf.gemspec
|