claiss 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -26
  3. data/lib/claiss/version.rb +2 -2
  4. data/lib/claiss.rb +55 -10
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4676e0b9c189aef43c1e7fc47b8335e6b06326a7037b8c5c8bc43d546fec9e03
4
- data.tar.gz: 1b0aced8f24d95a68a9b3b378d70562020d9c1b0f32be955e5d7b98f291e4fe9
3
+ metadata.gz: b196fd14a391ce3804f055af6109513aa11d3b9555a31bcd0cdfcd99aebf4e3d
4
+ data.tar.gz: 7dd699a7ea98feeb55c974a726ff0d40a8b239d960e21bd3ebc6d994883c29cf
5
5
  SHA512:
6
- metadata.gz: daaec06de788e6d5710b17094fcb7948365fdec7099fff35da7a89dfe4aba78bff7ef9b1114836196eddfba7b490bb7d42177248d39778006516b0879c5ef55d
7
- data.tar.gz: b8f1c356aa5f6d8b1b94bed86c085b8f6035fa1fd324d945c1879a0cd2de29141c36854b1ca4a13cfc89b9b04f6a3b1107373a21ad0b7a496ba3fdb1ad12c61e
6
+ metadata.gz: 3886071f8e207af613f1e9da94e29fc72f6d95e7f3ca3e79e2e9e3f19b72b2f37c59c3375625feed9440329d07387d1fb1dea7cf4f4f1a98a16c8d3ce5307748
7
+ data.tar.gz: 44cafb7662557876102c52385966d4712b1cd58448c77bc5228ff60ed18263072682055eb64a438cdd3cce8f59b59fb58f506380f3f7048570d14c6c49651680
data/README.md CHANGED
@@ -1,56 +1,73 @@
1
- # CLAISS AI CLI Application Toolbox
1
+ # CLAISS CLI Refactor Application Toolbox
2
2
 
3
- CLAISS is a Ruby CLI application & Toolbox to manage CLAISS AI applications and deployments. Please note that some features may not work in all environments. Use with caution!
3
+ **CLAISS** is a Ruby-based CLI application and toolbox designed to manage CLAISS Refactored applications and deployments. Please note that some features may have limited compatibility depending on the environment. Use with caution!
4
4
 
5
5
  ## Installation
6
6
 
7
- Install the gem by running the following command in your terminal:
7
+ Install the CLAISS gem by running the following command in your terminal:
8
8
 
9
- Copy
10
-
11
- `$ gem install claiss`
9
+ ```sh
10
+ $ gem install claiss
11
+ ```
12
12
 
13
13
  ## Usage
14
14
 
15
15
  ### Refactor
16
16
 
17
- The `refactor` command changes text terms in files within a folder, creating a new "refactored-..." folder with the modified files. Note that this command will change all exact occurrences of the specified terms. For example, "Abc" is treated differently from "AbC " or " ABc" or "abc" or "ABC".
17
+ The `refactor` command allows you to rename and replace text terms within files and filenames in a specified directory. This command will refactor all exact occurrences of specified terms, including filenames. For example, "Abc" is treated differently from "AbC", "ABc", or "abc".
18
18
 
19
- Basic usage:
19
+ **Note:** The `refactor` command ignores the `.git/` and `node_modules/` directories to avoid modifying critical or third-party files.
20
20
 
21
- Copy
21
+ Basic usage:
22
22
 
23
- `$ claiss refactor ./project/`
23
+ ```sh
24
+ $ claiss refactor ./project/ ./my_changes.json
25
+ ```
24
26
 
25
27
  #### Using a JSON Dictionary
26
28
 
27
- You can create a JSON file with a list of terms to refactor. This file should be formatted as a one-level JSON object. The terms are processed in order from top to bottom.
29
+ You can create a JSON file that specifies the terms you want to refactor. This JSON file should be structured as a simple key-value pair object, where each key is the term to be replaced and the value is the replacement term. The terms are processed in the order they appear in the file.
28
30
 
29
- Example `myapp.json` file:
31
+ Example `my_changes.json`:
30
32
 
31
- Copy
33
+ ```json
34
+ {
35
+ "system pro": "system b2b",
36
+ "System Pro": "System B2b",
37
+ "System": "Laiss",
38
+ "system": "laiss",
39
+ "2010 Moevo Silver": "2023 Júlio Papel",
40
+ "Jared Moevo": "Júlio Papel",
41
+ "3dtester@gmail.com": "info@mynewsite.pt",
42
+ "https://somelivesite.com": "https://api.mynewsite.pt",
43
+ "This is your Rails project.": "Multi Layered Software Services.",
44
+ "This is your Rails project for your business.": "A Multi Layered Software Services ready to be deployed for any business.",
45
+ "MIT-LICENSE": "LICENSE",
46
+ "https://somesite.com": "https://api.mynewsite.pt"
47
+ }
48
+ ```
32
49
 
33
- `{ "system pro": "system b2b", "System Pro": "System B2b", "System": "Laiss", "system": "laiss", "2010 Moevo Silver": "2023 Júlio Papel", "Jared Moevo": "Júlio Papel", "3dtester@gmail.com": "info@mynewsite.pt", "https://somelivesite.com": "https://api.mynewsite.pt", "This is your Rails project.": "Multi Layered Software Services.", "This is your Rails project for your business.": "A Multi Layered Software Services ready to be deployed for any business.", "MIT-LICENSE": "LICENSE", "https://somesite.com": "https://api.mynewsite.pt" }`
50
+ To apply the changes using the dictionary file:
34
51
 
35
- To use this dictionary file:
52
+ ```sh
53
+ $ claiss refactor ./project/ ./my_changes.json
54
+ ```
36
55
 
37
- Copy
38
-
39
- `$ claiss refactor ./project/ ./myapp.json`
56
+ **Important:** After refactoring, any empty directories left behind will be automatically removed to keep your project structure clean.
40
57
 
41
58
  ### Fix Ruby Permissions
42
59
 
43
- The `fix_ruby_permissions` command adjusts file permissions for a Ruby & Rails project:
44
-
45
- Copy
60
+ The `fix_ruby_permissions` command adjusts file permissions for a Ruby or Rails project. It ensures that directories have the correct execute permissions and that files retain their appropriate read/write/execute permissions.
46
61
 
47
- `$ claiss fix_ruby_permissions ./refactored-1688375056/`
62
+ ```sh
63
+ $ claiss fix_ruby_permissions ./project/
64
+ ```
48
65
 
49
- **Note:** This command uses `chmod` and may not work correctly on systems that support filename spaces and ignore capitals (like some end-user operating systems). For example, a file called 'MyImage copy.svg' may cause errors. In such cases, manually fix the permissions for problematic files and then re-run the command.
66
+ **Note:** This command uses `chmod` and may encounter issues on systems that do not distinguish between uppercase and lowercase filenames or support spaces in filenames (e.g., certain end-user operating systems). If you encounter errors, particularly with filenames like `MyImage copy.svg`, manually fix those file permissions and re-run the command.
50
67
 
51
68
  ## Upcoming Features
52
69
 
53
- We're continually working to improve CLAISS and add new functionalities. Stay tuned for updates!
70
+ We are continuously working to improve CLAISS and add new functionalities. Stay tuned for updates!
54
71
 
55
72
  ## Contributing
56
73
 
@@ -58,8 +75,8 @@ Bug reports and pull requests are welcome on GitHub at [https://github.com/Julio
58
75
 
59
76
  ## License
60
77
 
61
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
78
+ This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
62
79
 
63
80
  ## Author
64
81
 
65
- Júlio Papel
82
+ Júlio Papel
@@ -1,3 +1,3 @@
1
1
  module CLAISS
2
- VERSION = "1.1.1"
3
- end
2
+ VERSION = "1.1.2"
3
+ end
data/lib/claiss.rb CHANGED
@@ -22,12 +22,11 @@ module CLAISS
22
22
  def call(path:, json_file: nil, **)
23
23
  dict = load_dictionary(json_file)
24
24
  origin_path = File.expand_path(path)
25
- destination_path = File.expand_path("./refactored-#{Time.now.to_i}")
26
25
 
27
- dict[origin_path] = destination_path
28
26
  process_files(origin_path, dict)
27
+ remove_empty_directories(origin_path)
29
28
 
30
- puts "Done! Your project is in the #{destination_path} folder"
29
+ puts "Done! Files have been refactored in place."
31
30
  end
32
31
 
33
32
  private
@@ -56,25 +55,53 @@ module CLAISS
56
55
  def process_files(origin_path, dict)
57
56
  Dir.glob(File.join(origin_path, "**", "*"), File::FNM_DOTMATCH).each do |file_name|
58
57
  next if File.directory?(file_name)
58
+ next if file_name.include?(".git/") || file_name.include?("node_modules/") # Ignore .git and node_modules folders
59
59
  process_file(file_name, dict)
60
60
  end
61
61
  end
62
62
 
63
63
  def process_file(file_name, dict)
64
- destination = file_name.gsub(dict.keys.first, dict.values.first)
65
64
  text = File.read(file_name)
66
65
 
67
66
  dict.each do |search, replace|
68
- destination.gsub!(search, replace)
69
67
  text.gsub!(search, replace)
70
68
  end
71
69
 
72
- FileUtils.mkdir_p(File.dirname(destination))
73
- File.write(destination, text)
74
- puts "File: #{destination}, OK"
70
+ new_file_name = file_name.dup
71
+
72
+ dict.each do |search, replace|
73
+ new_file_name.gsub!(search, replace)
74
+ end
75
+
76
+ # Create the directory for the new file if it doesn't exist
77
+ new_dir = File.dirname(new_file_name)
78
+ FileUtils.mkdir_p(new_dir) unless File.directory?(new_dir)
79
+
80
+ # Write the changes to the new file name
81
+ File.write(new_file_name, text)
82
+
83
+ # If the filename has changed, delete the original file
84
+ unless new_file_name == file_name
85
+ File.delete(file_name) # Delete the original file
86
+ puts "File renamed from #{file_name} to #{new_file_name}, OK"
87
+ else
88
+ puts "File: #{file_name}, OK"
89
+ end
90
+ end
91
+
92
+ def remove_empty_directories(origin_path)
93
+ Dir.glob(File.join(origin_path, '**', '*'), File::FNM_DOTMATCH).reverse_each do |dir_name|
94
+ next unless File.directory?(dir_name)
95
+ next if dir_name.include?(".git/") || dir_name.include?("node_modules/") # Ignore .git and node_modules folders
96
+ if (Dir.entries(dir_name) - %w[. ..]).empty?
97
+ Dir.rmdir(dir_name)
98
+ puts "Removed empty directory: #{dir_name}"
99
+ end
100
+ end
75
101
  end
76
102
  end
77
103
 
104
+
78
105
  class FixRubyPermissions < Dry::CLI::Command
79
106
  desc "Fix permissions for a Ruby project"
80
107
  argument :path, required: true, desc: "The path of your Ruby project"
@@ -85,10 +112,11 @@ module CLAISS
85
112
 
86
113
  Dir.glob(File.join(path, '**', '*'), File::FNM_DOTMATCH) do |item|
87
114
  next if item == '.' || item == '..'
115
+ next if item.include?("node_modules/") # Ignore node_modules folder
88
116
  if File.directory?(item)
89
117
  File.chmod(0755, item)
90
118
  else
91
- File.chmod(0644, item)
119
+ fix_file_permissions(item)
92
120
  end
93
121
  end
94
122
 
@@ -100,9 +128,26 @@ module CLAISS
100
128
 
101
129
  puts "Permissions fixed for #{path}"
102
130
  end
131
+
132
+ private
133
+
134
+ def fix_file_permissions(file)
135
+ current_permissions = File.stat(file).mode
136
+
137
+ if current_permissions & 0o100 != 0 # Check if the owner has execute permission
138
+ File.chmod(0755, file) # Maintain execution permission for owner, group, and others
139
+ elsif current_permissions & 0o010 != 0 # Check if the group has execute permission
140
+ File.chmod(0755, file) # Maintain execution permission for group and others
141
+ elsif current_permissions & 0o001 != 0 # Check if others have execute permission
142
+ File.chmod(0755, file) # Maintain execution permission for others
143
+ else
144
+ File.chmod(0644, file) # Otherwise, apply standard read/write permissions
145
+ end
146
+ end
103
147
  end
148
+
104
149
  end
105
150
 
106
151
  require_relative "claiss/version"
107
152
  require_relative "claiss/commands"
108
- require_relative "claiss/cli"
153
+ require_relative "claiss/cli"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: claiss
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Júlio Papel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-25 00:00:00.000000000 Z
11
+ date: 2024-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.1.2
92
+ rubygems_version: 3.5.3
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: CLAISS AI CLI application Toolbox