gito 0.2.4 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -11
- data/detector.json +32 -0
- data/detector.rb +16 -0
- data/extras/recordit.gif +0 -0
- data/extras/recordit2.gif +0 -0
- data/gito.gemspec +2 -1
- data/lib/gito.rb +35 -5
- data/lib/gito/config_manager.rb +36 -0
- data/lib/gito/project.rb +18 -28
- data/lib/gito/version.rb +1 -1
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4416faef1ce8a1f742961c8166aa3748191d61cd
|
4
|
+
data.tar.gz: ed9a120d580ae5f28dd6ba95ad9786755146eadd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52da36d58def0e2b8bf201966118a247ff1904bf896354a75923850f3fe853d5b48a9dc579da6f49b9dd6aa3e69076483acc3985b2825c227ae996fb43747c88
|
7
|
+
data.tar.gz: 69966fb5f99e3c5aac8a00de16a30b42f1ed5149dcef2256f8712b48c1d7b7d9205d13a0eafb5debedebbe9802901bad658f67795e4080a9f0dd659fbf326422
|
data/README.md
CHANGED
@@ -4,20 +4,19 @@
|
|
4
4
|
[![Code Climate](https://codeclimate.com/github/cesarferreira/gito/badges/gpa.svg)](https://codeclimate.com/github/cesarferreira/gito)
|
5
5
|
[![Inline docs](http://inch-ci.org/github/cesarferreira/gito.svg?branch=master)](http://inch-ci.org/github/cesarferreira/gito)
|
6
6
|
|
7
|
-
git helper tool to **clone**/**open**/**install**/**edit** a git project with a one-liner.
|
7
|
+
git helper tool to **clone**/**open**/**auto-install**/**edit** a git project with a one-liner.
|
8
8
|
|
9
|
-
-----------
|
10
9
|
|
11
10
|
<p align="center">
|
12
|
-
|
11
|
+
<img src="extras/recordit2.gif" width="100%" />
|
13
12
|
</p>
|
14
13
|
|
15
14
|
<p align="center">
|
16
|
-
<
|
15
|
+
> <strong>gito</strong> <i>cesarferreira/dryrun -e</i>
|
17
16
|
</p>
|
18
17
|
|
19
18
|
## Why?
|
20
|
-
A lot of times I find myself wanting to try some code from github and in order to do so I have to copy the git URL, go to the terminal, git clone, find out the folder name, go to the folder and based on the type of project I need to `bundle install`, `./gradlew assemble`, `npm install
|
19
|
+
A lot of times I find myself wanting to try some code from github and in order to do so I have to copy the git URL, go to the terminal, git clone, find out the folder name, go to the folder and based on the type of project I need to `bundle install`, `./gradlew assemble`, `npm install`, `pip install .`, `mix deps.get`, `make install`, you name it. And after that opening it in my text editor of choice... Not anymore!
|
21
20
|
|
22
21
|
|
23
22
|
## Usage
|
@@ -27,9 +26,10 @@ $ gito -h
|
|
27
26
|
Usage: gito GIT_URL [OPTIONS]
|
28
27
|
|
29
28
|
Options
|
29
|
+
-s, --set-editor EDITOR Set a custom editor to open the project (e.g. "atom", "subl", "vim", etc.
|
30
30
|
-e, --edit Open the project on an editor
|
31
31
|
-o, --open Open the project on Finder
|
32
|
-
-d, --dryrun
|
32
|
+
-d, --dryrun Does not install the dependencies
|
33
33
|
-h, --help Displays help
|
34
34
|
-v, --version Displays the version
|
35
35
|
```
|
@@ -42,10 +42,13 @@ gito cesarferreira/dryrun
|
|
42
42
|
# git clone, install, open and edit the project
|
43
43
|
gito cesarferreira/dryrun --edit --open
|
44
44
|
|
45
|
-
#
|
45
|
+
# set the editor to be 'subl' from now on
|
46
|
+
gito cesarferreira/dryrun -s subl
|
47
|
+
|
48
|
+
# git clone, install, open and edit the project from github
|
46
49
|
gito https://github.com/cesarferreira/dryrun -e -o
|
47
50
|
|
48
|
-
# git clone, install
|
51
|
+
# git clone, install from another git source
|
49
52
|
gito https://bitbucket.org/username/project
|
50
53
|
```
|
51
54
|
|
@@ -53,12 +56,26 @@ gito https://bitbucket.org/username/project
|
|
53
56
|
|
54
57
|
$ gem install gito
|
55
58
|
|
56
|
-
##
|
59
|
+
## Supported type detections/auto-intalls
|
60
|
+
So far it auto-installs these types:
|
61
|
+
- Ruby
|
62
|
+
- Gradle
|
63
|
+
- node.js
|
64
|
+
- C
|
65
|
+
- Elixir
|
66
|
+
- Python
|
57
67
|
|
58
|
-
|
68
|
+
Create a pull request by editing [detector.json](detector.json) file if you want more types to be added.
|
69
|
+
|
70
|
+
## Internally what happens?
|
59
71
|
|
72
|
+
When you run this:
|
60
73
|
```bash
|
61
|
-
|
74
|
+
gito cesarferreira/dryrun --edit --open
|
75
|
+
```
|
76
|
+
This will happen:
|
77
|
+
```bash
|
78
|
+
# clone
|
62
79
|
git clone http://github.com/cesarferreira/dryrun
|
63
80
|
|
64
81
|
# change directory
|
@@ -77,6 +94,9 @@ project_type_detector
|
|
77
94
|
bundle install
|
78
95
|
```
|
79
96
|
|
97
|
+
## todo
|
98
|
+
- `-t` to clone into a temp directory
|
99
|
+
|
80
100
|
## Contributing
|
81
101
|
I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:
|
82
102
|
1. If its a feature, bugfix, or anything please only change code to what you specify.
|
data/detector.json
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"file_requirement": "Gemfile",
|
4
|
+
"installation_command": "bundle install",
|
5
|
+
"type": "ruby"
|
6
|
+
},
|
7
|
+
{
|
8
|
+
"file_requirement": "build.gradle",
|
9
|
+
"installation_command": "./gradlew assemble",
|
10
|
+
"type": "gradle"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"file_requirement": "package.json",
|
14
|
+
"installation_command": "yarn",
|
15
|
+
"type": "node"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"file_requirement": "Makefile",
|
19
|
+
"installation_command": "make",
|
20
|
+
"type": "c"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"file_requirement": "mix.exs",
|
24
|
+
"installation_command": "mix deps.get",
|
25
|
+
"type": "elixir"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"file_requirement": "setup.py",
|
29
|
+
"installation_command": "pip install .",
|
30
|
+
"type": "python"
|
31
|
+
}
|
32
|
+
]
|
data/detector.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
file = File.read('detector.json')
|
4
|
+
types = JSON.parse(file)
|
5
|
+
chosen = nil
|
6
|
+
types.each do |item|
|
7
|
+
if File.exist? (item['file_requirement'])
|
8
|
+
chosen = item
|
9
|
+
break
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
unless chosen.nil?
|
14
|
+
puts "Found: " + chosen['type']
|
15
|
+
puts "how to install: " + chosen['installation']
|
16
|
+
end
|
data/extras/recordit.gif
ADDED
Binary file
|
Binary file
|
data/gito.gemspec
CHANGED
@@ -8,7 +8,7 @@ spec = Gem::Specification.new do |s|
|
|
8
8
|
s.homepage = 'https://github.com/cesarferreira/gito'
|
9
9
|
s.license = 'MIT'
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.summary = 'git helper tool to clone/open/install/edit a git project with a one-liner'
|
11
|
+
s.summary = 'git helper tool to clone/open/auto-install/edit a git project with a one-liner'
|
12
12
|
s.files = `git ls-files`.split("
|
13
13
|
")
|
14
14
|
s.require_paths << 'lib'
|
@@ -22,4 +22,5 @@ spec = Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.add_dependency 'bundler', '~> 1.7'
|
24
24
|
s.add_dependency 'colorize', '~> 0.7'
|
25
|
+
s.add_dependency 'safe_yaml', '~> 1.0.4'
|
25
26
|
end
|
data/lib/gito.rb
CHANGED
@@ -3,6 +3,7 @@ require 'tmpdir'
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'gito/version'
|
5
5
|
require 'gito/project'
|
6
|
+
require 'gito/config_manager'
|
6
7
|
require 'openssl'
|
7
8
|
require 'open3'
|
8
9
|
require 'optparse'
|
@@ -17,6 +18,8 @@ class MainApp
|
|
17
18
|
@should_edit = false
|
18
19
|
@should_open = false
|
19
20
|
@dryrun = false
|
21
|
+
@editor = nil
|
22
|
+
@setting_up = false
|
20
23
|
|
21
24
|
# Parse Options
|
22
25
|
create_options_parser(arguments)
|
@@ -28,7 +31,12 @@ class MainApp
|
|
28
31
|
opts.separator ''
|
29
32
|
opts.separator 'Options'
|
30
33
|
|
31
|
-
opts.on('-
|
34
|
+
opts.on('-s EDITOR', '--set-editor EDITOR', 'Set a custom editor to open the project (e.g. "atom", "subl", "vim", etc.') do |editor|
|
35
|
+
@editor = editor.nil? ? nil : editor
|
36
|
+
@setting_up = true
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-e', '--edit', 'Open the project on an editor') do |editor|
|
32
40
|
@should_edit = true
|
33
41
|
end
|
34
42
|
|
@@ -54,24 +62,46 @@ class MainApp
|
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
65
|
+
def update_configuration
|
66
|
+
config_manager = ConfigManager.new
|
67
|
+
app_config = config_manager.get
|
68
|
+
|
69
|
+
if @editor.nil?
|
70
|
+
@editor = app_config[:editor]
|
71
|
+
else
|
72
|
+
config_manager.write_editor @editor
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
57
76
|
def call
|
58
77
|
|
78
|
+
if @setting_up
|
79
|
+
if @editor.nil?
|
80
|
+
puts 'New new editor can\'t be empty'.red
|
81
|
+
else
|
82
|
+
update_configuration
|
83
|
+
puts 'Updated the editor to: ' + @editor.yellow
|
84
|
+
end
|
85
|
+
exit 1
|
86
|
+
end
|
87
|
+
|
59
88
|
if @url.nil?
|
60
89
|
puts 'You need to insert a valid GIT URL/folder'
|
61
90
|
exit 1
|
62
91
|
end
|
63
92
|
|
93
|
+
# handle the configuration
|
94
|
+
update_configuration
|
95
|
+
|
64
96
|
project = Project.new(@url)
|
65
97
|
|
66
98
|
# Clone the repository
|
67
99
|
project.clone
|
68
100
|
|
69
|
-
# Detect project type
|
70
|
-
project.detect_project_type
|
71
|
-
|
72
101
|
# Open in editor
|
73
102
|
if @should_edit
|
74
|
-
|
103
|
+
# binding.pry
|
104
|
+
project.open_editor @editor
|
75
105
|
end
|
76
106
|
|
77
107
|
# Open in Finder
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'safe_yaml'
|
2
|
+
|
3
|
+
class ConfigManager
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
SafeYAML::OPTIONS[:default_mode] = :safe
|
7
|
+
SafeYAML::OPTIONS[:deserialize_symbols] = true
|
8
|
+
|
9
|
+
@conf_path = "#{Dir.home}/.gito.yml"
|
10
|
+
@default_config = {"editor": "atom"}
|
11
|
+
end
|
12
|
+
|
13
|
+
def write_editor(new_editor)
|
14
|
+
current_config = get
|
15
|
+
current_config[:editor] = new_editor
|
16
|
+
write(current_config)
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(config)
|
20
|
+
new_config = config.to_yaml
|
21
|
+
File.open(@conf_path, 'w') { |file| file.write(new_config)}
|
22
|
+
end
|
23
|
+
|
24
|
+
def get
|
25
|
+
if File.exists? (@conf_path)
|
26
|
+
file = File.open(@conf_path, "rb")
|
27
|
+
contents = file.read
|
28
|
+
config = YAML.load(contents, :safe => true)
|
29
|
+
else
|
30
|
+
write @default_config
|
31
|
+
config = @default_config
|
32
|
+
end
|
33
|
+
|
34
|
+
config
|
35
|
+
end
|
36
|
+
end
|
data/lib/gito/project.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tmpdir'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'uri'
|
4
|
+
require 'json'
|
4
5
|
require_relative './app_utils'
|
5
6
|
require 'pry'
|
6
7
|
|
@@ -9,7 +10,7 @@ class Project
|
|
9
10
|
@base_url = sanitize_url(url)
|
10
11
|
@destination_dir = nil
|
11
12
|
@destination = destination
|
12
|
-
@
|
13
|
+
@detector_json_path = '../detector.json'
|
13
14
|
end
|
14
15
|
|
15
16
|
def sanitize_url(url)
|
@@ -46,43 +47,32 @@ class Project
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def change_directory
|
49
|
-
# TODO aparently this doesn't work because ruby forks the terminal process and
|
50
|
+
# TODO aparently this doesn't work because ruby forks the terminal process and can't communicate with his parent
|
50
51
|
|
51
52
|
# temp_script_name = './temp.sh'
|
52
53
|
# AppUtils::execute 'echo "cd '+@destination+'" > ' + temp_script_name
|
53
54
|
# AppUtils::execute '. '+temp_script_name
|
54
55
|
# AppUtils::execute 'rm -rf ' + temp_script_name
|
55
56
|
|
56
|
-
puts "
|
57
|
+
puts "-------------------------------------------"
|
58
|
+
puts "Please change directory"
|
57
59
|
puts "cd #{destination.yellow}"
|
60
|
+
puts "-------------------------------------------"
|
58
61
|
end
|
59
62
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
def install_dependencies
|
64
|
+
file = File.read(@detector_json_path)
|
65
|
+
types = JSON.parse(file)
|
66
|
+
chosen = nil
|
64
67
|
|
65
|
-
|
66
|
-
@project_type = :gradle
|
67
|
-
elsif File.exists?('package.json')
|
68
|
-
@project_type = :node
|
69
|
-
elsif File.exists?('Gemfile')
|
70
|
-
@project_type = :ruby
|
71
|
-
end
|
68
|
+
Dir.chdir(@destination_dir)
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def install_dependencies
|
78
|
-
case @project_type
|
79
|
-
when :gradle
|
80
|
-
go_inside_and_run('./gradlew assemble')
|
81
|
-
when :node
|
82
|
-
go_inside_and_run('npm install')
|
83
|
-
when :ruby
|
84
|
-
go_inside_and_run('bundle install')
|
70
|
+
types.each do |item|
|
71
|
+
if File.exists? (item['file_requirement'])
|
72
|
+
puts "#{item['type']} detected...".yellow
|
73
|
+
go_inside_and_run item['installation_command']
|
85
74
|
end
|
75
|
+
end
|
86
76
|
end
|
87
77
|
|
88
78
|
def cloneable_url
|
@@ -115,9 +105,9 @@ class Project
|
|
115
105
|
@destination_dir
|
116
106
|
end
|
117
107
|
|
118
|
-
def open_editor
|
108
|
+
def open_editor(app)
|
119
109
|
puts "Opening editor...".yellow
|
120
|
-
go_inside_and_run
|
110
|
+
go_inside_and_run "#{app} ."
|
121
111
|
end
|
122
112
|
|
123
113
|
def open_folder
|
data/lib/gito/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cesar ferreira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: safe_yaml
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.4
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.4
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- cesar.manuel.ferreira@gmail.com
|
@@ -95,10 +109,15 @@ files:
|
|
95
109
|
- README.md
|
96
110
|
- Rakefile
|
97
111
|
- bin/gito
|
112
|
+
- detector.json
|
113
|
+
- detector.rb
|
114
|
+
- extras/recordit.gif
|
115
|
+
- extras/recordit2.gif
|
98
116
|
- extras/screenshot.png
|
99
117
|
- gito.gemspec
|
100
118
|
- lib/gito.rb
|
101
119
|
- lib/gito/app_utils.rb
|
120
|
+
- lib/gito/config_manager.rb
|
102
121
|
- lib/gito/project.rb
|
103
122
|
- lib/gito/version.rb
|
104
123
|
homepage: https://github.com/cesarferreira/gito
|
@@ -125,5 +144,5 @@ rubyforge_project:
|
|
125
144
|
rubygems_version: 2.6.10
|
126
145
|
signing_key:
|
127
146
|
specification_version: 4
|
128
|
-
summary: git helper tool to clone/open/install/edit a git project with a one-liner
|
147
|
+
summary: git helper tool to clone/open/auto-install/edit a git project with a one-liner
|
129
148
|
test_files: []
|