codeshift 0.1.8 → 0.2.0
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/.github/dependabot.yml +11 -0
- data/.github/workflows/gem-push.yml +45 -0
- data/Gemfile +2 -0
- data/README.md +21 -14
- data/codeshift.gemspec +1 -1
- data/lib/codeshift/cli.rb +3 -2
- data/lib/codeshift/transformer.rb +1 -2
- data/lib/codeshift/version.rb +3 -1
- data/lib/codeshift.rb +5 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09160e4f1daa03101fdcf2d1d6cd43ba664bac73d96d8de24885b6a695a1d869'
|
4
|
+
data.tar.gz: 6582cb9a1b60bb904e30ced7a55d7fbef9d1c5f44d5254410417c49dee176718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b88bcaa1f32e8b120d7f1d2ede3f947c33d51d8dfabb40776ff02cda7f8e1e01a810e58f3e0a89cb76982cb9626f602417d60544e688988c2e835d54397db8
|
7
|
+
data.tar.gz: 4f9af39477612d3138840307d7a4bc8f8b04dc0c73083e2709b56bd9d34dc81a795d4c118d7ecd74dd5cb0c0540a9b718af71083bf15b62b3e77124500427a7d
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
3
|
+
# Please see the documentation for all configuration options:
|
4
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
+
|
6
|
+
version: 2
|
7
|
+
updates:
|
8
|
+
- package-ecosystem: "bundler" # See documentation for possible values
|
9
|
+
directory: "/" # Location of package manifests
|
10
|
+
schedule:
|
11
|
+
interval: "weekly"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
permissions:
|
14
|
+
contents: read
|
15
|
+
packages: write
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
- name: Set up Ruby 2.6
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: '2.6'
|
23
|
+
|
24
|
+
- name: Publish to GPR
|
25
|
+
run: |
|
26
|
+
mkdir -p $HOME/.gem
|
27
|
+
touch $HOME/.gem/credentials
|
28
|
+
chmod 0600 $HOME/.gem/credentials
|
29
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
30
|
+
gem build *.gemspec
|
31
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
32
|
+
env:
|
33
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
34
|
+
OWNER: ${{ github.repository_owner }}
|
35
|
+
|
36
|
+
- name: Publish to RubyGems
|
37
|
+
run: |
|
38
|
+
mkdir -p $HOME/.gem
|
39
|
+
touch $HOME/.gem/credentials
|
40
|
+
chmod 0600 $HOME/.gem/credentials
|
41
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
42
|
+
gem build *.gemspec
|
43
|
+
gem push *.gem
|
44
|
+
env:
|
45
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# Codeshift
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/codeshift)
|
4
|
+
[](https://travis-ci.org/rajasegar/codeshift)
|
5
|
+

|
6
|
+
[](https://coveralls.io/github/rajasegar/codeshift?branch=master)
|
4
7
|
|
5
8
|
A Ruby codemod CLI to transform your source code using AST(Abstract Syntax Trees) and the [parser](https://github.com/whitequark/parser) gem.
|
6
|
-
It is typically used on
|
9
|
+
It is typically used on Ruby codebase like RAILS applications and other stuff.
|
7
10
|
|
8
11
|
## Installation
|
9
12
|
|
@@ -23,15 +26,15 @@ $ codeshift -t [TRANSFORM FILE] [PATHS]
|
|
23
26
|
To apply the transform logic on your `app/models` files
|
24
27
|
|
25
28
|
```sh
|
26
|
-
$ codeshift -t transform.rb app/models
|
29
|
+
$ codeshift -t transform.rb app/models
|
27
30
|
```
|
28
31
|
|
29
32
|
For example if you want to reverse the local variable names and method names in your code
|
30
33
|
you will be doing something like this:
|
31
34
|
|
32
|
-
Create a new
|
33
|
-
AST of the source code. For writing transforms you can make use of
|
34
|
-
[Ruby AST Explorer](https://ruby-ast-explorer.herokuapp.com/)
|
35
|
+
Create a new Ruby file with the tranformation logic to be applied on the
|
36
|
+
AST of the source code. For writing transforms you can make use of
|
37
|
+
[Ruby AST Explorer](https://ruby-ast-explorer.herokuapp.com/) and [cybertron](https://github.com/rajasegar/cybertron)
|
35
38
|
|
36
39
|
### transform.rb
|
37
40
|
```ruby
|
@@ -40,11 +43,11 @@ AST of the source code. For writing transforms you can make use of the
|
|
40
43
|
class Transform < Parser::TreeRewriter
|
41
44
|
def on_lvasgn(node)
|
42
45
|
# Reverse the variable names
|
43
|
-
replace(node.loc.
|
46
|
+
replace(node.loc.name, node.children[0].to_s.reverse)
|
44
47
|
end
|
45
48
|
|
46
49
|
def on_def(node)
|
47
|
-
replace(node.loc.
|
50
|
+
replace(node.loc.name, node.children[0].to_s.reverse)
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
@@ -60,10 +63,10 @@ def print_tips
|
|
60
63
|
end
|
61
64
|
```
|
62
65
|
|
63
|
-
Then use
|
66
|
+
Then use the transform against your source code
|
64
67
|
|
65
68
|
```sh
|
66
|
-
$ codeshift -t transform.rb ~/Desktop/test/ruby
|
69
|
+
$ codeshift -t transform.rb ~/Desktop/test/ruby
|
67
70
|
```
|
68
71
|
|
69
72
|
Then your source will be transformed something like:
|
@@ -84,24 +87,28 @@ Usage: codeshift -t <transform-file> [path]
|
|
84
87
|
(default: ./transform.rb)
|
85
88
|
* -h, --help Prints this help
|
86
89
|
|
87
|
-
###
|
88
|
-
The transform file could be a local file or a remote url. For example you can use like
|
90
|
+
### transform-file
|
91
|
+
The transform file could be a local file or a remote url. For example you can use a remote transform like below:
|
89
92
|
|
90
93
|
```sh
|
91
|
-
$ codeshift -t https://gist.githubusercontent.com/[user]/.../transform.rb ~/Desktop/test/ruby
|
94
|
+
$ codeshift -t https://gist.githubusercontent.com/[user]/.../transform.rb ~/Desktop/test/ruby
|
92
95
|
```
|
93
96
|
|
94
97
|
### path
|
95
98
|
The path could be a list of directories or files separated by space.
|
96
99
|
|
97
100
|
```sh
|
98
|
-
$ codeshift -t transform.rb ~/app/legacy/ruby
|
101
|
+
$ codeshift -t transform.rb ~/app/legacy/ruby ~/app/old
|
99
102
|
```
|
100
103
|
|
101
104
|
```sh
|
102
105
|
$ codeshift -t transform.rb ~/code/legacy/app/models/account.rb ~/old/app/models/customer.rb
|
103
106
|
```
|
104
107
|
|
108
|
+
## Related tools
|
109
|
+
- [ruby-ast-explorer](https://github.com/rajasegar/ruby-ast-explorer)
|
110
|
+
- [cybertron](https://github.com/rajasegar/cybertron)
|
111
|
+
|
105
112
|
## Development
|
106
113
|
|
107
114
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -118,4 +125,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
118
125
|
|
119
126
|
## Code of Conduct
|
120
127
|
|
121
|
-
Everyone interacting in the Codeshift project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
128
|
+
Everyone interacting in the Codeshift project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rajasegar/codeshift/blob/master/CODE_OF_CONDUCT.md).
|
data/codeshift.gemspec
CHANGED
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_runtime_dependency 'parser', '~> 2.6'
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
-
spec.add_development_dependency "rake", "~>
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
34
|
end
|
data/lib/codeshift/cli.rb
CHANGED
@@ -23,7 +23,7 @@ module CodeShift
|
|
23
23
|
@options.transform = f
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on(
|
26
|
+
opts.on('-h', '--help', 'Prints this help') do
|
27
27
|
puts opts
|
28
28
|
exit
|
29
29
|
end
|
@@ -46,7 +46,8 @@ module CodeShift
|
|
46
46
|
paths = @files.empty? ? [] : @files
|
47
47
|
paths.each do |path|
|
48
48
|
if File.directory?(path)
|
49
|
-
|
49
|
+
glob_path = File.join(path, '**', '*.rb')
|
50
|
+
Dir.glob(glob_path) do |file_path|
|
50
51
|
process_file file_path
|
51
52
|
end
|
52
53
|
else
|
data/lib/codeshift/version.rb
CHANGED
data/lib/codeshift.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeshift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajasegar Chandran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +75,8 @@ executables:
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
+
- ".github/dependabot.yml"
|
79
|
+
- ".github/workflows/gem-push.yml"
|
78
80
|
- ".gitignore"
|
79
81
|
- ".rspec"
|
80
82
|
- ".travis.yml"
|
@@ -113,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
115
|
- !ruby/object:Gem::Version
|
114
116
|
version: '0'
|
115
117
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.7.6.2
|
118
|
+
rubygems_version: 3.0.3.1
|
118
119
|
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: A tool to run Ruby codemods.
|