avo_upgrade 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/lib/avo_upgrade/railtie.rb +8 -0
- data/lib/avo_upgrade/upgrade29to30.rb +113 -0
- data/lib/avo_upgrade/upgrade_tool.rb +80 -0
- data/lib/avo_upgrade/version.rb +3 -0
- data/lib/avo_upgrade.rb +12 -0
- data/lib/tasks/avo_upgrade_tasks.rake +4 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7c4c205f4c99041d674a65cd96474518f4694c14b63134e09f33c35b54f9308
|
4
|
+
data.tar.gz: a8aeb29143b89d99422223c63fe59a9e8773663b5eea19a6966b6dd85a147306
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44266214d009dd85c00aeff57aa83b981b414a05eab37ac9d048e2b3193d62d418fc00465efbed077638a390f9c400524b6e6a7a581effdb408e3dde047f3926
|
7
|
+
data.tar.gz: a554b83067e15a6992e01a88a2e9b9c5eb54426d8634da5d0865db13abd1ec92e3a3aeea6093e35732f5c7f16df8a15e13d1e88c26f28a1704b29294b6e1ad36
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2023 Adrian Marin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# AvoUpgrade
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "avo_upgrade"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install avo_upgrade
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
module AvoUpgrade
|
2
|
+
class Upgrade29to30 < AvoUpgrade::UpgradeTool
|
3
|
+
def run
|
4
|
+
# Replace all resource files with the new ones without the _resource suffix
|
5
|
+
replace_in_filename "_resource", "", path: resources_path
|
6
|
+
|
7
|
+
# Replace all "Avo::Dashboards::" with "AvoDashboards::" in all files
|
8
|
+
replace_text_on(avo_global_files, { "Avo::Dashboards::" => "AvoDashboards::" }, exact_match: false)
|
9
|
+
|
10
|
+
# Create a hash with old class names as keys and new class names as values
|
11
|
+
# Example: { "Avo::Resources::UserResource" => "Avo::Resources::User" }
|
12
|
+
old_text_new_text_hash = class_names_for(:resources).map do |class_name|
|
13
|
+
[class_name, "Avo::Resources::#{class_name.sub(/Resource$/, '')}"]
|
14
|
+
end.to_h
|
15
|
+
|
16
|
+
# Same as above but for all components, class name don't change, only the namespace
|
17
|
+
[:actions, :filters, :resource_tools, :dashboards, :cards].each do |component|
|
18
|
+
old_text_new_text_hash.merge! change_class_name_hash_for(component)
|
19
|
+
end
|
20
|
+
|
21
|
+
replace_text_on(files_from(actions_path), {"model" => "record"}, exact_match: false)
|
22
|
+
replace_text_on(
|
23
|
+
files_from(resources_path),
|
24
|
+
{
|
25
|
+
"model." => "record.",
|
26
|
+
"model_class." => "query.",
|
27
|
+
"scope." => "query.",
|
28
|
+
"resolve_query_scope" => "index_query",
|
29
|
+
},
|
30
|
+
exact_match: false
|
31
|
+
)
|
32
|
+
replace_text_on(avo_global_files, old_text_new_text_hash)
|
33
|
+
|
34
|
+
# Remove arguments from the blocks
|
35
|
+
remove_text = [
|
36
|
+
"(resource:)",
|
37
|
+
"(model_class:, id:, params:)",
|
38
|
+
"(model_class:)",
|
39
|
+
"(value)",
|
40
|
+
"|model|",
|
41
|
+
"|model, resource|",
|
42
|
+
"|model, resource, view|",
|
43
|
+
"|model, resource, view, field|",
|
44
|
+
"|model, &args|"
|
45
|
+
]
|
46
|
+
remove_text_on(files_from(resources_path) + files_from(actions_path) + files_from(filters_path), remove_text)
|
47
|
+
|
48
|
+
print "\n\nUpgrade to Avo 3.0 completed! 🚀\n\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
def summary
|
52
|
+
# Get the names of all the resources, actions, filters, resource tools, dashboards and cards
|
53
|
+
resources_names = class_names_for(:resources)
|
54
|
+
actions_names = class_names_for(:actions)
|
55
|
+
filters_names = class_names_for(:filters)
|
56
|
+
resource_tools_names = class_names_for(:resource_tools)
|
57
|
+
dashboards_names = class_names_for(:dashboards)
|
58
|
+
cards_names = class_names_for(:cards)
|
59
|
+
|
60
|
+
# Print a summary of the upgrade process
|
61
|
+
puts "\n\nSummary of changes:\n" +
|
62
|
+
"---------------------\n" +
|
63
|
+
"Renaming Avo::Dashboards:: to AvoDashboards::\n" +
|
64
|
+
"Renaming resources naming from ClassNameResource to Avo::Resources::ClassName\n" +
|
65
|
+
"Renaming actions naming from ClassName to Avo::Actions::ClassName\n" +
|
66
|
+
"Renaming filters naming from ClassName to Avo::Filters::ClassName\n" +
|
67
|
+
"Renaming resource tools naming from ClassName to Avo::ResourceTools::ClassName\n" +
|
68
|
+
"Renaming dashboards naming from ClassName to Avo::Dashboards::ClassName\n" +
|
69
|
+
"Renaming cards naming from ClassName to Avo::Cards::ClassName\n" +
|
70
|
+
"Renaming 'resolve_query_scope' method in resource files to 'index_query'\n" +
|
71
|
+
"Removing unused arguments from blocks in resource, action and filter files\n" +
|
72
|
+
"Updating resource and action files to use 'record' instead of 'model'\n" +
|
73
|
+
"Updating resource files to use 'query' instead of 'model_class' and 'scope'\n" +
|
74
|
+
"Renaming resource files to remove the '_resource' suffix\n" +
|
75
|
+
"\n" +
|
76
|
+
" - There are 2 ways of renaming the resource files:\n" +
|
77
|
+
" 1. Using `git mv` command, that automaticly stage the changes and makes the commit review process easier.\n" +
|
78
|
+
" 2. Using `mv` command, that will rename the files without relying on any specific version control system. You will have to stage the changes manually.\n"
|
79
|
+
@mv_cmd = nil
|
80
|
+
while @mv_cmd != "1" && @mv_cmd != "2"
|
81
|
+
print " Choose the one you prefer (1 or 2) and press enter: "
|
82
|
+
@mv_cmd = gets.chomp
|
83
|
+
end
|
84
|
+
puts "---------------------\n" +
|
85
|
+
"The following components will be upgraded:\n" +
|
86
|
+
"\nResources: \n -#{resources_names.join("\n -")}\n"
|
87
|
+
enter_to_continue
|
88
|
+
puts "\nActions: \n -#{actions_names.join("\n -")}\n"
|
89
|
+
enter_to_continue
|
90
|
+
puts "\nFilters: \n -#{filters_names.join("\n -")}\n"
|
91
|
+
enter_to_continue
|
92
|
+
puts "\nResource tools: \n -#{resource_tools_names.join("\n -")}\n"
|
93
|
+
enter_to_continue
|
94
|
+
puts "\nDashboards: \n -#{dashboards_names.join("\n -")}\n"
|
95
|
+
enter_to_continue
|
96
|
+
puts "\nCards: \n -#{cards_names.join("\n -")}\n"
|
97
|
+
enter_to_continue
|
98
|
+
puts "\nThis upgrade will NOT:\n" +
|
99
|
+
"- Apply the `def fields` and `def cards` API\n" +
|
100
|
+
"- Remove the argument from lambda functions if they are not as we specify them on docs.\n" +
|
101
|
+
"- Remove the index_text_align option\n" +
|
102
|
+
"- Swap disabled with readonly\n\n"
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def change_class_name_hash_for(component)
|
108
|
+
pluralized_component = component.to_s.camelize.pluralize
|
109
|
+
|
110
|
+
class_names_for(component).map { |class_name| [class_name, "Avo::#{pluralized_component}::#{class_name}"] }.to_h
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
# class generated by ChatGPT. Update it as you see fit.
|
4
|
+
module AvoUpgrade
|
5
|
+
class UpgradeTool
|
6
|
+
class << self
|
7
|
+
def run
|
8
|
+
upgrade_tool = new
|
9
|
+
puts "DISCLAIMER: Please be aware that this is an automated upgrade and may make unintended changes to your files. We recommend that you carefully review all changes before committing them. While we have taken steps to ensure that the upgrade process is safe and reliable, there is always a possibility of unintended consequences. It is your responsibility to ensure that the modifications made by the upgrade are acceptable for your use case."
|
10
|
+
upgrade_tool.enter_to_continue
|
11
|
+
print upgrade_tool.summary
|
12
|
+
puts "Please make sure you commited all your changes before running this upgrade."
|
13
|
+
print "Do you want to run this upgrade? [y/n]: "
|
14
|
+
input = gets.chomp
|
15
|
+
return unless input == "y" || input == "Y"
|
16
|
+
upgrade_tool.run
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def avo_global_files
|
21
|
+
Dir.glob(File.join(Rails.root.join("app", "avo"), '**/*')).select { |f| File.file?(f) } +
|
22
|
+
Dir.glob(File.join(Rails.root.join("app", "controllers", "avo"), '**/*')).select { |f| File.file?(f) } +
|
23
|
+
Dir.glob(File.join(Rails.root.join("app", "views", "avo"), '**/*')).select { |f| File.file?(f) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def class_names_for(component)
|
27
|
+
names = []
|
28
|
+
|
29
|
+
Dir.glob(File.join(send("#{component}_path"), '**/*.rb')).each do |file|
|
30
|
+
# Match class definitions in the file
|
31
|
+
File.read(file).scan(/class\s+(\w+)/).each do |match|
|
32
|
+
# Add the matched class names to the list
|
33
|
+
names << match.first
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
names
|
38
|
+
end
|
39
|
+
|
40
|
+
# Dynamicly create path method for each component
|
41
|
+
# def resources_path, def actions_path, def filters_path, def resource_tools_path def dashboards_path, def cards_path
|
42
|
+
[:resources, :actions, :filters, :resource_tools, :dashboards, :cards].each do |component|
|
43
|
+
define_method "#{component}_path" do
|
44
|
+
Rails.root.join("app", "avo", component.to_s)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def files_from(path)
|
49
|
+
Dir.glob("#{path}/*.rb").select { |file| File.file?(file) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def replace_text_on(files, hash, exact_match: true)
|
53
|
+
files.each do |file|
|
54
|
+
text = File.read(file)
|
55
|
+
|
56
|
+
hash.each do |old_text, new_text|
|
57
|
+
old_text = /\b#{Regexp.escape(old_text)}\b/ if exact_match
|
58
|
+
text.gsub!(old_text, new_text)
|
59
|
+
end
|
60
|
+
|
61
|
+
File.open(file, 'w') { |f| f.write(text) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def remove_text_on(files, text_array)
|
66
|
+
replace_text_on(files, text_array.map { |text| [text, ""] }.to_h, exact_match: false)
|
67
|
+
end
|
68
|
+
|
69
|
+
def replace_in_filename(old_text, new_text, path:)
|
70
|
+
Dir.glob("#{path}/*.rb").each do |file_path|
|
71
|
+
`#{@mv_cmd == "1" ? "git mv" : "mv"} #{file_path} #{file_path.gsub(/#{old_text}/, new_text)}`
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def enter_to_continue
|
76
|
+
print "\nPress ENTER to continue."
|
77
|
+
gets.chomp
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/avo_upgrade.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: avo_upgrade
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Marin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zeitwerk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: The friendly upgrade helper for Avo.
|
42
|
+
email:
|
43
|
+
- adrian@adrianthedev.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/avo_upgrade.rb
|
52
|
+
- lib/avo_upgrade/railtie.rb
|
53
|
+
- lib/avo_upgrade/upgrade29to30.rb
|
54
|
+
- lib/avo_upgrade/upgrade_tool.rb
|
55
|
+
- lib/avo_upgrade/version.rb
|
56
|
+
- lib/tasks/avo_upgrade_tasks.rake
|
57
|
+
homepage: https://avohq.io
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata:
|
61
|
+
homepage_uri: https://avohq.io
|
62
|
+
source_code_uri: https://github.com/avo-hq/avo_upgrade
|
63
|
+
changelog_uri: https://github.com/avo-hq/avo_upgrade
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.4.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: The friendly upgrade helper for Avo.
|
83
|
+
test_files: []
|