jekyll-git-deploy 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9373d96cf9be3eb302f9463eab2503af3fdb65d
4
+ data.tar.gz: 6b15970dbdb092f1437a48d428060c6df2c63ee2
5
+ SHA512:
6
+ metadata.gz: de59a4f1666e02e22399de95379d35a328f25c85ea0f8dea7a1c1ca4585c9abb9c505c897d54636893858ddc796d4db89940a7288ba5b28c1b0efbdf5fca574c
7
+ data.tar.gz: bb36bab8c8691003868b9f2b3c018123e1229fbd47d135408f68a2cc5ad57971abfb437543f060bf872f5c4e203a7c1f1b3ddc560ecbe6179f17558e135c542e
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ jekyll-git-deploy-*.gem
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env
2
+
3
+ require 'jekyll_git_deploy'
4
+ include JekyllGitDeploy
5
+
6
+ def print_usage
7
+ puts "Usage: jekyll-git-deploy [#{AVAILABLE_SUB_COMMANDS.join(' | ')}]".yellow
8
+ end
9
+
10
+ AVAILABLE_SUB_COMMANDS = %w(init deploy)
11
+ if ARGV.length < 1
12
+ puts "Please specify a sub command:"
13
+ print_usage
14
+ elsif !AVAILABLE_SUB_COMMANDS.include? ARGV.first
15
+ puts "Unpermitted command \"#{ARGV.first}\", you can only use #{AVAILABLE_SUB_COMMANDS.join(' or ')}".red
16
+ print_usage
17
+ else
18
+ send ARGV.first
19
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'jekyll-git-deploy'
3
+ s.version = '0.0.1'
4
+ s.date = '2015-01-18'
5
+ s.summary = "Deploy jekyll site through git push"
6
+ s.description = "Executable commands to help you to deploy your jekyll blog through git push way conveniently!"
7
+ s.authors = ["Martin Hong"]
8
+ s.email = 'hongzeqin@gmail.com'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.homepage = "https://github.com/Martin91/jekyll-git-deploy"
11
+ s.executables = ['jekyll-git-deploy']
12
+ s.license = 'MIT'
13
+ end
@@ -0,0 +1,40 @@
1
+ module CommonTasks
2
+ CONFIG_FILE = "_config.yml"
3
+
4
+ CONFIG_DEFAULTS = {
5
+ "destination" => "_site",
6
+ "deploy_branch" => "pages",
7
+ "deploy_remote_name" => "deploy",
8
+ "touch_file" => "Staticfile"
9
+ }
10
+
11
+ REQUIRED_CONFIGS = %w(destination deploy_repo deploy_branch deploy_remote_name touch_file )
12
+
13
+ def read_configs
14
+ return @configs if @configs
15
+
16
+ unless File.file?(CONFIG_FILE)
17
+ raise "Can not find a config file, please check your current working directoy and ensure it is under the root of your jekyll site!".red
18
+ end
19
+
20
+ @configs = CONFIG_DEFAULTS.merge YAML.load_file("./#{CONFIG_FILE}")
21
+ end
22
+
23
+ def commit_newest_site
24
+ message = "Genereted site at #{Time.now}"
25
+ puts "\ncommit the site: #{message}".yellow
26
+ `git add -A . && git commit -m "#{message}"`
27
+ end
28
+
29
+ def current_branch
30
+ `git rev-parse --abbrev-ref HEAD`.strip
31
+ end
32
+
33
+ def self.included(base)
34
+ REQUIRED_CONFIGS.each do |method|
35
+ define_method method do
36
+ read_configs[method]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,84 @@
1
+ require 'yaml'
2
+ require 'support/ansi_colors'
3
+ require 'helpers/common_tasks'
4
+
5
+ module JekyllGitDeploy
6
+ include CommonTasks
7
+
8
+ # Initialize the deploy environment
9
+ #
10
+ def init
11
+ configs = read_configs
12
+
13
+ puts "Start to initialize the git repo at #{destination}".yellow
14
+ unless deploy_repo && !deploy_repo.strip.empty?
15
+ raise "You haven't specify any deploy repo in _config.yml file, the action can not continue!".red
16
+ end
17
+
18
+ file = File.open('.gitignore', 'r+')
19
+ existed_line = file.readlines.select{|line| line.strip == destination}
20
+ unless existed_line
21
+ puts "\nadd #{destination} directory to .gitignore".yellow
22
+ file.puts destination
23
+ end
24
+ file.close
25
+
26
+ `mkdir -p #{Dir.pwd}/#{destination}`
27
+ puts "\nruning `cd #{destination}`".yellow
28
+ Dir.chdir destination do
29
+ # Determine if there has been any git repo existed
30
+ unless File.directory? ".git"
31
+ `git init`
32
+ end
33
+
34
+ puts "\nStart to add remote url".yellow
35
+ `git remote add #{deploy_remote_name} #{deploy_repo} 2> /dev/null`
36
+
37
+ puts "\nCurrent git remotes:\n==========================".yellow
38
+ puts `git remote -v`
39
+
40
+ puts "\nFinished deploy initialization for the current site".green
41
+ end
42
+ end
43
+
44
+ # Build and push(deploy) the newest generated site
45
+ #
46
+ def deploy
47
+ puts "\nGenerating the newest site".yellow
48
+ `jekyll build`
49
+
50
+ # This step is only for sites requiring some special file to detect running environment
51
+ unless destination.empty?
52
+ puts "\nTouching Staticfile".yellow
53
+ `touch #{destination}/Staticfile`
54
+ end
55
+
56
+ puts "\nruning `cd #{destination}`".yellow
57
+ Dir.chdir destination do
58
+ if `git branch`.empty? # Fully new git repo
59
+ commit_newest_site
60
+
61
+ puts "\nThis is a new git repo, creating new branch #{deploy_branch} now".yellow
62
+ `git checkout -b #{deploy_branch} &> /dev/null && git merge #{current_branch}`
63
+ else
64
+ unless current_branch == deploy_branch
65
+ puts "\nStart to checkout to deploy branch: #{deploy_branch}".yellow
66
+ if `git show-branch #{deploy_branch} 2> /dev/null`.empty? # the deploy branch didn't exist
67
+ `git checkout -b #{deploy_branch}`
68
+ else
69
+ `git checkout #{deploy_branch}`
70
+ end
71
+ end
72
+
73
+ commit_newest_site
74
+ end
75
+
76
+ puts "\nPushing newest generated site:".yellow
77
+ `git push -u #{deploy_remote_name} #{deploy_branch}`
78
+
79
+ puts "\nThe deploy is finished!".green
80
+ baseurl = read_configs['baseurl'] || ""
81
+ `open "#{baseurl}"` if baseurl =~ /https?:\/\/\S+/
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,58 @@
1
+ # ansi_colors.rb
2
+ # Implement add ansi color escape code to normal string
3
+ #
4
+ # Created by Martin Hong on 1/17/2015
5
+ # Copyright (c) 2015 Martin Hong. All rights reserved.
6
+ #
7
+
8
+ String.class_eval do
9
+ # ==== Start colors with ANSI escape code ====
10
+ #
11
+ # ANSI colors excape code format:
12
+ # => Color=\033[code;前景;背景m
13
+ #
14
+ # More details can be retrieved from: http://en.wikipedia.org/wiki/ANSI_escape_code
15
+ #
16
+ # ANSI
17
+ # Foreground Background Color
18
+ # ---------------------------------------
19
+ # 30 40 Black
20
+ # 31 41 Red
21
+ # 32 42 Green
22
+ # 33 43 Yellow
23
+ # 34 44 Blue
24
+ # 35 45 Purple
25
+ # 36 46 Blue-Green
26
+ # 37 47 White
27
+ # 1 1 Transparent
28
+ #
29
+ # Code Function
30
+ # -------------------------
31
+ # 0 OFF
32
+ # 1 Highline
33
+ # 4 Underline
34
+ # 5 Flash
35
+ # 7 Reverse Display
36
+ # 8 Invisiable
37
+ #
38
+ RED = "\033[0;31;1m" # Dangerous Color
39
+ YELLOW = "\033[0;33;1m" # Warning Color
40
+ GREEN = "\033[0;32;1m" # Infos Color
41
+ DEFAULT = "\033[0;39;49m" # RESET COLOR
42
+ # ==== End colors with ANSI escape code ====
43
+
44
+ # Usages:
45
+ #
46
+ # "Hello world".red
47
+ # "Hello world".green
48
+ # "Hello world".yellow
49
+ #
50
+ %w(red yellow green).each do |method|
51
+ unless method_defined?(method)
52
+ define_method method do
53
+ prepend self.class.const_get(method.upcase)
54
+ concat DEFAULT
55
+ end
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-git-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Hong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Executable commands to help you to deploy your jekyll blog through git
14
+ push way conveniently!
15
+ email: hongzeqin@gmail.com
16
+ executables:
17
+ - jekyll-git-deploy
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - bin/jekyll-git-deploy
23
+ - jekyll-git-deploy.gemspec
24
+ - lib/helpers/common_tasks.rb
25
+ - lib/jekyll_git_deploy.rb
26
+ - lib/support/ansi_colors.rb
27
+ homepage: https://github.com/Martin91/jekyll-git-deploy
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.2.2
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Deploy jekyll site through git push
51
+ test_files: []