makegit 0.1.1.pre → 1.0.2
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/makegit +1 -2
- data/lib/makegit.rb +32 -80
- data/lib/makegit/config.rb +49 -0
- data/lib/makegit/fs_builder.rb +67 -0
- data/lib/makegit/repo_builder.rb +43 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3398ad6997162e0f3ebcb4eb4e0fab18e910b76
|
4
|
+
data.tar.gz: 6074fa2d287cbe84ecab351152320d56d5ffd59b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f6b6f8ccfde7a428179b33371a52b99407f146d6466e1e0f68f4222dbad4ecd116a5e24f61f877c5536f4ea20515c622887b81d15885854c8ec0fd6cfed3244
|
7
|
+
data.tar.gz: a1bc6d1ecf87fe1e9e68e5c862a08e40148c99ef69c2093203c8ac5aee4764143a02682bafbc60a4e310461b852c6f953e1697164061f749c21e573854cdf741
|
data/bin/makegit
CHANGED
data/lib/makegit.rb
CHANGED
@@ -1,96 +1,48 @@
|
|
1
1
|
module Application
|
2
|
-
|
3
|
-
|
2
|
+
require 'makegit/config'
|
3
|
+
require 'makegit/fs_builder'
|
4
|
+
require 'makegit/repo_builder'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
@git_user = get_git_user
|
8
|
-
@git_token = get_git_token
|
9
|
-
new_dir
|
10
|
-
new_local_repo
|
11
|
-
new_remote_repo
|
12
|
-
end
|
6
|
+
require 'json'
|
7
|
+
require 'optparse'
|
13
8
|
|
14
|
-
|
15
|
-
user = `git config github.user`.strip
|
16
|
-
if user.empty? || user.nil?
|
17
|
-
STDOUT.puts "Warning: git config --global github.user not set"
|
18
|
-
STDOUT.puts "Let's set it now..."
|
19
|
-
STDOUT.puts "Please enter your GitHub username:"
|
20
|
-
user = STDIN.gets.strip
|
21
|
-
set_git_config_user(user)
|
22
|
-
end
|
23
|
-
user
|
24
|
-
end
|
9
|
+
class Makegit
|
25
10
|
|
26
|
-
|
27
|
-
token = `git config github.token`.strip
|
28
|
-
if token.empty? || token.nil?
|
29
|
-
STDOUT.puts "Warning: git config --global github.token not set"
|
30
|
-
STDOUT.puts "Let's set it now..."
|
31
|
-
STDOUT.puts "Visit https://help.github.com/articles/creating-an-access-token-for-command-line-use/"
|
32
|
-
STDOUT.puts "Then create a personal access token with the \"repo\" role set"
|
33
|
-
STDOUT.puts "Please enter your GitHub token:"
|
34
|
-
token = STDIN.gets.strip
|
35
|
-
set_git_config_token(token)
|
36
|
-
end
|
37
|
-
token
|
38
|
-
end
|
11
|
+
attr_reader :params, :project_name, :git_user, :git_token
|
39
12
|
|
40
|
-
def
|
41
|
-
|
13
|
+
def initialize(argv)
|
14
|
+
@params, @project_name = parse_options(argv)
|
15
|
+
@git_user, @git_token = Config.new.login
|
42
16
|
end
|
43
17
|
|
44
|
-
def
|
45
|
-
|
18
|
+
def run
|
19
|
+
FSBuilder.new(project_name, params[:template]).build
|
20
|
+
RepoBuilder.new(project_name, git_user, git_token).build
|
21
|
+
STDOUT.puts "Project successfully created. Type \"cd #{project_name}\" and get to work!"
|
46
22
|
end
|
47
23
|
|
48
|
-
def
|
49
|
-
if
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
name = STDIN.gets.strip
|
54
|
-
end
|
55
|
-
end
|
24
|
+
def parse_options(argv)
|
25
|
+
argv << '-h' if argv.empty?
|
26
|
+
params = {}
|
27
|
+
OptionParser.new do |opts|
|
28
|
+
opts.banner = "Usage: [project_name] [options]"
|
56
29
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
Dir.chdir(project_name)
|
62
|
-
STDOUT.puts Dir.pwd
|
63
|
-
end
|
30
|
+
opts.on("-h", "--help", "Prints this help") do
|
31
|
+
puts opts
|
32
|
+
exit
|
33
|
+
end
|
64
34
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
STDOUT.puts "Creating README.md"
|
69
|
-
File.open("README.md", "w"){ |f| f.puts "#{project_name} by #{git_user}"}
|
70
|
-
STDOUT.puts "README.md created"
|
71
|
-
end
|
35
|
+
opts.on("--rubygem", "Creates RubyGem project template") do
|
36
|
+
params[:template] = "rubygem"
|
37
|
+
end
|
72
38
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
puts response['message']
|
80
|
-
response['errors'] && response['errors'].each do |err|
|
81
|
-
puts "#{err['message']}"
|
82
|
-
end
|
83
|
-
else
|
84
|
-
system("git add .")
|
85
|
-
system("git commit -m \'Initial commit\'")
|
86
|
-
system("git remote add origin git@github.com:#{git_user}/#{current_dir}.git")
|
87
|
-
system("git push -u origin master")
|
88
|
-
STDOUT.puts "************** SUCCESS! ********************"
|
89
|
-
STDOUT.puts "Project Created! Now \'cd #{response['html_url']}\' and get to work."
|
90
|
-
end
|
91
|
-
end
|
39
|
+
end.parse!
|
40
|
+
|
41
|
+
project_name = argv[0]
|
42
|
+
raise ArgumentError, "No Project Name Given", caller if project_name == nil || project_name.empty?
|
43
|
+
|
44
|
+
[params, project_name]
|
92
45
|
|
93
|
-
def run
|
94
46
|
end
|
95
47
|
end
|
96
48
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Application
|
2
|
+
class Config
|
3
|
+
attr_reader :user, :token
|
4
|
+
|
5
|
+
def initialize()
|
6
|
+
@user = git_user
|
7
|
+
@token = git_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def login
|
11
|
+
[user, token]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def git_user
|
16
|
+
user = `git config github.user`.strip
|
17
|
+
if user.empty? || user.nil?
|
18
|
+
STDOUT.puts "Warning: git config --global github.user not set"
|
19
|
+
STDOUT.puts "Let's set it now..."
|
20
|
+
STDOUT.puts "Please enter your GitHub username:"
|
21
|
+
user = STDIN.gets.strip
|
22
|
+
set_git_config_user(user)
|
23
|
+
end
|
24
|
+
user
|
25
|
+
end
|
26
|
+
|
27
|
+
def git_token
|
28
|
+
token = `git config github.token`.strip
|
29
|
+
if token.empty? || token.nil?
|
30
|
+
STDOUT.puts "Warning: git config --global github.token not set"
|
31
|
+
STDOUT.puts "Let's set it now..."
|
32
|
+
STDOUT.puts "Visit https://help.github.com/articles/creating-an-access-token-for-command-line-use/"
|
33
|
+
STDOUT.puts "Then create a personal access token with the \"repo\" role set"
|
34
|
+
STDOUT.puts "Please enter your GitHub token:"
|
35
|
+
token = STDIN.gets.strip
|
36
|
+
set_git_config_token(token)
|
37
|
+
end
|
38
|
+
token
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_git_config_user(user)
|
42
|
+
system("git config --global github.user #{user}")
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_git_config_token(token)
|
46
|
+
system("git config --global github.token #{token}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Application
|
2
|
+
class FSBuilder
|
3
|
+
attr_reader :project_name, :template
|
4
|
+
|
5
|
+
def initialize(project_name, template)
|
6
|
+
@project_name = project_name
|
7
|
+
@template = template || "bare"
|
8
|
+
end
|
9
|
+
|
10
|
+
def build
|
11
|
+
if template == "bare"
|
12
|
+
bare
|
13
|
+
elsif template == "rubygem"
|
14
|
+
rubygem
|
15
|
+
else
|
16
|
+
raise ArgumentError, "Could not find a template to build"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def bare
|
21
|
+
STDOUT.puts "Building a bare project template"
|
22
|
+
Dir.mkdir(project_name)
|
23
|
+
Dir.chdir(project_name) do
|
24
|
+
File.open("README.md", "w"){ |f| f.puts "\# #{project_name}"}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def rubygem
|
29
|
+
STDOUT.puts "Building a RubyGem project template"
|
30
|
+
Dir.mkdir(project_name)
|
31
|
+
Dir.chdir(project_name) do
|
32
|
+
File.open("#{project_name}.gemspec", "w"){ |f|
|
33
|
+
f << "Gem::Specification.new do |s|\n"
|
34
|
+
f << "\ts.name = \'\'\n"
|
35
|
+
f << "\ts.version = \'\'\n"
|
36
|
+
f << "\ts.date = \'\'\n"
|
37
|
+
f << "\ts.summary = \'\'\n"
|
38
|
+
f << "\ts.description = \'\'\n"
|
39
|
+
f << "\ts.authors = \'[]\'\n"
|
40
|
+
f << "\ts.email = \'\'\n"
|
41
|
+
f << "\ts.files = \'[]\'\n"
|
42
|
+
f << "\ts.executables << \'#{project_name}\'\n"
|
43
|
+
f << "\ts.homepage = \'\'\n"
|
44
|
+
f << "\ts.license = \'\'\n"
|
45
|
+
f << "end"
|
46
|
+
}
|
47
|
+
File.open("Rakefile", "w")
|
48
|
+
File.open("README.md", "w"){ |f| f.puts "\# #{project_name}: A RubyGem"}
|
49
|
+
|
50
|
+
Dir.mkdir("bin")
|
51
|
+
Dir.chdir("bin") do
|
52
|
+
File.open(project_name, "w"){ |f| f.puts "\#!/usr/bin/env ruby"}
|
53
|
+
end
|
54
|
+
|
55
|
+
Dir.mkdir("lib")
|
56
|
+
Dir.chdir("lib") do
|
57
|
+
File.open("#{project_name}.rb", "w")
|
58
|
+
end
|
59
|
+
|
60
|
+
Dir.mkdir("test")
|
61
|
+
Dir.chdir("test") do
|
62
|
+
File.open("test_#{project_name}.rb", "w")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Application
|
2
|
+
class RepoBuilder
|
3
|
+
attr_reader :project_name, :git_user, :git_token
|
4
|
+
|
5
|
+
def initialize(project_name, git_user, git_token)
|
6
|
+
@project_name = project_name
|
7
|
+
@git_user = git_user
|
8
|
+
@git_token = git_token
|
9
|
+
end
|
10
|
+
|
11
|
+
def build
|
12
|
+
Dir.chdir(project_name) do
|
13
|
+
new_local_repo
|
14
|
+
new_remote_repo
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def new_local_repo
|
19
|
+
STDOUT.puts "Creating local git repository"
|
20
|
+
system("git init")
|
21
|
+
end
|
22
|
+
|
23
|
+
def new_remote_repo
|
24
|
+
current_dir = File.basename(Dir.getwd)
|
25
|
+
STDOUT.puts "Creating remote git repository"
|
26
|
+
repo_req = `curl -u #{git_user}:#{git_token} https://api.github.com/user/repos -d '{\"name\":\"#{current_dir}\"}'`
|
27
|
+
response = JSON.parse(repo_req)
|
28
|
+
if response['message'] || response['errors']
|
29
|
+
puts response['message']
|
30
|
+
response['errors'] && response['errors'].each do |err|
|
31
|
+
puts "#{err['message']}"
|
32
|
+
end
|
33
|
+
raise "Error creating GitHub repository"
|
34
|
+
else
|
35
|
+
system("git add --all")
|
36
|
+
system("git commit -m \'Initial commit\'")
|
37
|
+
system("git remote add origin git@github.com:#{git_user}/#{current_dir}.git")
|
38
|
+
system("git push -u origin master")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: makegit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gaddis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: MakeGit is CLI Project & GitHub Repo Creator
|
14
14
|
email: justinkgaddis@gmail.com
|
@@ -19,6 +19,9 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- bin/makegit
|
21
21
|
- lib/makegit.rb
|
22
|
+
- lib/makegit/config.rb
|
23
|
+
- lib/makegit/fs_builder.rb
|
24
|
+
- lib/makegit/repo_builder.rb
|
22
25
|
homepage: https://github.com/jkgaddis/makegit
|
23
26
|
licenses:
|
24
27
|
- Unlicense
|
@@ -34,9 +37,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
37
|
version: '0'
|
35
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
39
|
requirements:
|
37
|
-
- - "
|
40
|
+
- - ">="
|
38
41
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
42
|
+
version: '0'
|
40
43
|
requirements: []
|
41
44
|
rubyforge_project:
|
42
45
|
rubygems_version: 2.4.8
|