jekyll-ghdeploy 0.1.0 → 1.0.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/lib/jekyll-ghdeploy.rb +176 -127
- data/lib/jekyll-ghdeploy/version.rb +1 -1
- data/lib/jekyll/commands/ghdeploy.rb +17 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d07363aaf80d478a0b9845916d0e2c3e3b0ca657f534c784f74ece868521f67
|
4
|
+
data.tar.gz: 60e6aa00338e3dbec820c49bd43617a0df7faaa4c1de1c8065b4b20d180e0355
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7da5efb415bf796bcf67764250f85e2256c1e059f43985d993bb07277003e78a46b8932da653d1b27ae8535e17449da64b93d86bed96e97160364ab3514fdf34
|
7
|
+
data.tar.gz: 8c89bba0827f521b8be9b150ff12b949414ce14394bd090bdb2ceb35cd5edb68315e40b7c4eccad2dc6fdee4e9e3de97e7255b6ace8934e83a3bf5228a59a058
|
data/lib/jekyll-ghdeploy.rb
CHANGED
@@ -1,130 +1,179 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'jekyll'
|
3
|
+
require 'jekyll/commands/ghdeploy'
|
4
4
|
|
5
5
|
module JekyllGhDeploy
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
puts "\n\e[1m\e[33mWelcome to Jekyll GhDeploy\e[39m\e[0m"
|
11
|
-
|
12
|
-
@repo = "https://github.com/" + repo
|
13
|
-
@message = message
|
14
|
-
end
|
15
|
-
|
16
|
-
def deploy
|
17
|
-
clone
|
18
|
-
|
19
|
-
Dir.chdir("clone/") do
|
20
|
-
prepare
|
21
|
-
|
22
|
-
if !system("cd _site; git log>/dev/null")
|
23
|
-
initial_commits
|
24
|
-
else
|
25
|
-
build
|
26
|
-
commit
|
27
|
-
end
|
28
|
-
|
29
|
-
push
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def clone
|
34
|
-
puts "\n\e[1mCloning repository\e[0m\n\n"
|
35
|
-
|
36
|
-
FileUtils.rm_rf("clone")
|
37
|
-
|
38
|
-
exit unless system("git clone '.git/' 'clone/'")
|
39
|
-
end
|
40
|
-
|
41
|
-
def initial_commits
|
42
|
-
puts "\n\e[1mBuilding and commiting for every commit in master branch\e[0m\n\n"
|
43
|
-
|
44
|
-
n = -1 + `git rev-list --count master`.to_i
|
45
|
-
#n = n-1
|
46
|
-
commit_hash=Array.new()
|
47
|
-
message=Array.new()
|
48
|
-
|
49
|
-
#This is an iteration through every commit inside of master branch
|
50
|
-
#To get the ith commit message we need to skip n-i commits starting from HEAD
|
51
|
-
|
52
|
-
for i in 0..n do
|
53
|
-
commit_hash[i]=`git log --skip=#{n-i} --max-count=1 --pretty=%H`
|
54
|
-
message[i] =`git log --skip=#{n-i} --max-count=1 --pretty=%s`
|
55
|
-
end
|
56
|
-
|
57
|
-
for i in 0..n do
|
58
|
-
@message = message[i]
|
59
|
-
system("
|
60
|
-
git reset --hard #{commit_hash[i]}
|
61
|
-
echo -e '\n'
|
62
|
-
")
|
63
|
-
build
|
64
|
-
commit
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def prepare
|
69
|
-
puts "\n\e[1mPreparing _site\e[0m\n\n"
|
70
|
-
|
71
|
-
FileUtils.rm_rf("_site")
|
72
|
-
Dir.mkdir "_site"
|
73
|
-
|
74
|
-
Dir.chdir("_site/") do
|
75
|
-
exit unless system("
|
76
|
-
git init
|
77
|
-
echo -e '\n'
|
78
|
-
git remote add origin #{@repo}
|
79
|
-
git checkout -b gh-pages
|
80
|
-
echo -e '\n'
|
81
|
-
")
|
82
|
-
|
83
|
-
remote_branch = `git ls-remote --heads origin gh-pages`
|
84
|
-
|
85
|
-
if remote_branch.empty?
|
86
|
-
system("touch .nojekyll")
|
87
|
-
else
|
88
|
-
exit unless system("git pull --rebase origin gh-pages")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def build
|
94
|
-
puts "\n\e[1mBuilding\e[0m\n\n"
|
95
|
-
|
96
|
-
Jekyll::Commands::Build.process(options = {})
|
97
|
-
end
|
98
|
-
|
99
|
-
def commit
|
100
|
-
puts "\n\e[1mCommiting changes\e[0m\n\n"
|
101
|
-
|
102
|
-
Dir.chdir("_site/") do
|
103
|
-
exit unless system("
|
104
|
-
git status
|
105
|
-
echo -e '\n'
|
106
|
-
git add -A
|
107
|
-
echo -e '\n'
|
108
|
-
git status
|
109
|
-
echo -e '\n'
|
110
|
-
git commit -m '#{@message}'
|
111
|
-
")
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def push
|
116
|
-
puts "\n\e[1mPushing to #{@repo} gh-pages branch\e[0m\n\n"
|
117
|
-
|
118
|
-
Dir.chdir("_site/") do
|
119
|
-
exit unless system("git push origin gh-pages")
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def clean
|
124
|
-
puts "\n\n\e[1mQuiting...\e[0m\n\n"
|
125
|
-
|
126
|
-
FileUtils.rm_rf("clone")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
6
|
+
class Site
|
7
|
+
def initialize(repo, options = {})
|
8
|
+
system 'clear'
|
9
|
+
puts "\n\e[1m\e[33mWelcome to Jekyll GhDeploy\e[39m\e[0m"
|
130
10
|
|
11
|
+
@repo = 'https://github.com/' + repo
|
12
|
+
|
13
|
+
if options['docs'] == true
|
14
|
+
@dir = 'docs'
|
15
|
+
@branch = 'master'
|
16
|
+
@message = options['message']
|
17
|
+
else
|
18
|
+
@dir = '_site'
|
19
|
+
@branch = 'gh-pages'
|
20
|
+
@message = `git log -1 --pretty=%s`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def deploy
|
25
|
+
clone
|
26
|
+
|
27
|
+
case @dir
|
28
|
+
when 'docs'
|
29
|
+
deploy_docs
|
30
|
+
when '_site'
|
31
|
+
deploy_site
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def deploy_docs
|
36
|
+
Dir.chdir('clone/') do
|
37
|
+
exit unless system 'git remote remove origin'
|
38
|
+
exit unless system "git remote add origin #{@repo}"
|
39
|
+
|
40
|
+
FileUtils.rm_rf('docs')
|
41
|
+
build
|
42
|
+
|
43
|
+
Dir.chdir('docs') { system 'touch .nojekyll' }
|
44
|
+
|
45
|
+
commit
|
46
|
+
push
|
47
|
+
end
|
48
|
+
|
49
|
+
puts "\n\e[1mUpdating local repository\e[0m"
|
50
|
+
|
51
|
+
exit unless system 'git stash'
|
52
|
+
exit unless system "git pull --rebase origin #{@branch}"
|
53
|
+
exit unless system 'git stash pop'
|
54
|
+
end
|
55
|
+
|
56
|
+
def deploy_site
|
57
|
+
Dir.chdir('clone/') do
|
58
|
+
prepare_site
|
59
|
+
|
60
|
+
if !system 'cd _site; git log>/dev/null'
|
61
|
+
initial_commits
|
62
|
+
else
|
63
|
+
build
|
64
|
+
commit
|
65
|
+
end
|
66
|
+
|
67
|
+
push
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def clone
|
72
|
+
puts "\n\e[1mCloning repository\e[0m"
|
73
|
+
|
74
|
+
FileUtils.rm_rf('clone')
|
75
|
+
|
76
|
+
exit unless system "git clone '.git/' 'clone/'"
|
77
|
+
|
78
|
+
copy_staged_files if @dir == 'docs'
|
79
|
+
end
|
80
|
+
|
81
|
+
def copy_staged_files
|
82
|
+
staged_files = []
|
83
|
+
|
84
|
+
`git diff --name-only --cached`.each_line do |line|
|
85
|
+
staged_files.push(line.chomp)
|
86
|
+
end
|
87
|
+
|
88
|
+
FileUtils.cp_r staged_files, 'clone'
|
89
|
+
end
|
90
|
+
|
91
|
+
def initial_commits
|
92
|
+
puts "\n\e[1mBuilding and commiting for every commit in master branch\e[0m"
|
93
|
+
|
94
|
+
n = -1 + `git rev-list --count master`.to_i
|
95
|
+
|
96
|
+
commit_hash = []
|
97
|
+
message = []
|
98
|
+
|
99
|
+
# This is an iteration through every commit inside of master branch
|
100
|
+
# To get the ith commit message we need to skip n-i commits starting from HEAD
|
101
|
+
|
102
|
+
for i in 0..n do
|
103
|
+
commit_hash[i] = `git log --skip=#{n - i} --max-count=1 --pretty=%H`
|
104
|
+
message[i] = `git log --skip=#{n - i} --max-count=1 --pretty=%s`
|
105
|
+
end
|
106
|
+
|
107
|
+
for i in 0..n do
|
108
|
+
@message = message[i]
|
109
|
+
|
110
|
+
exit unless system "git reset --hard #{commit_hash[i]}"
|
111
|
+
puts
|
112
|
+
|
113
|
+
build
|
114
|
+
commit
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def prepare_site
|
119
|
+
puts "\n\e[1mPreparing _site\e[0m"
|
120
|
+
|
121
|
+
FileUtils.rm_rf(@dir)
|
122
|
+
Dir.mkdir(@dir)
|
123
|
+
|
124
|
+
Dir.chdir(@dir) do
|
125
|
+
exit unless system 'git init'
|
126
|
+
exit unless system "git remote add origin #{@repo}"
|
127
|
+
exit unless system "git checkout -b #{@branch}"
|
128
|
+
|
129
|
+
remote_branch = `git ls-remote --heads origin gh-pages`
|
130
|
+
|
131
|
+
if remote_branch.empty?
|
132
|
+
system 'touch .nojekyll'
|
133
|
+
else
|
134
|
+
exit unless system 'git pull --rebase origin gh-pages'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def build
|
140
|
+
puts "\n\e[1mBuilding\e[0m"
|
141
|
+
|
142
|
+
options = {}
|
143
|
+
options['serving'] = false
|
144
|
+
options['destination'] = @dir
|
145
|
+
|
146
|
+
Jekyll::Commands::Build.process(options)
|
147
|
+
end
|
148
|
+
|
149
|
+
def commit
|
150
|
+
puts "\n\e[1mCommiting changes\e[0m"
|
151
|
+
|
152
|
+
Dir.chdir(@dir) do
|
153
|
+
system 'git add -A'
|
154
|
+
system 'git status'
|
155
|
+
|
156
|
+
if @message.nil?
|
157
|
+
puts 'Enter your commit message: '
|
158
|
+
@message = gets
|
159
|
+
end
|
160
|
+
|
161
|
+
exit unless system "git commit -m '#{@message}'"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def push
|
166
|
+
puts "\n\e[1mPushing to #{@repo} #{@branch} branch\e[0m"
|
167
|
+
|
168
|
+
Dir.chdir(@dir) do
|
169
|
+
exit unless system "git push origin #{@branch}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def clean
|
174
|
+
puts "\n\n\e[1mQuiting...\e[0m"
|
175
|
+
|
176
|
+
FileUtils.rm_rf('clone')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -5,11 +5,12 @@ module Jekyll
|
|
5
5
|
class << self
|
6
6
|
def init_with_program(prog)
|
7
7
|
prog.command(:ghdeploy) do |c|
|
8
|
+
c.syntax 'deploy REPOSITORY'
|
9
|
+
c.description 'Deploys your site to your gh-pages branch'
|
10
|
+
|
11
|
+
c.option 'docs', '--docs', '-d', 'Built site is stored into docs directory'
|
12
|
+
c.option 'message', '--message MESSAGE', '-m MESSAGE', 'Specify a commit message'
|
8
13
|
|
9
|
-
c.syntax "deploy REPOSITORY"
|
10
|
-
|
11
|
-
c.description "Deploys your site to your gh-pages branch"
|
12
|
-
|
13
14
|
c.action do |args, options|
|
14
15
|
Jekyll::Commands::GhDeploy.process(args, options)
|
15
16
|
end
|
@@ -17,29 +18,26 @@ module Jekyll
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def process(args, options = {})
|
20
|
-
|
21
|
-
config = YAML.load_file('_config.yml')
|
22
|
-
message = `git log -1 --pretty=%s`
|
21
|
+
config = YAML.load_file('_config.yml')
|
23
22
|
|
24
23
|
if args.empty? && config['repository'].blank?
|
25
|
-
raise ArgumentError,
|
24
|
+
raise ArgumentError, 'You must specify a repository.'
|
26
25
|
elsif args.empty?
|
27
26
|
repo = config['repository']
|
28
|
-
else
|
27
|
+
else
|
29
28
|
repo = args[0]
|
30
29
|
end
|
31
30
|
|
32
|
-
site = JekyllGhDeploy::Site.new(repo,
|
33
|
-
|
31
|
+
site = JekyllGhDeploy::Site.new(repo, options)
|
32
|
+
|
34
33
|
at_exit do
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
site.deploy
|
34
|
+
site.clean
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
site.deploy
|
38
|
+
# site.build
|
39
|
+
end
|
40
|
+
end
|
43
41
|
end
|
44
42
|
end
|
45
|
-
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-ghdeploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Garlis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|