jekyll-browsersync 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +47 -0
- data/lib/jekyll-browsersync/command.rb +129 -0
- data/lib/jekyll-browsersync/version.rb +7 -0
- data/lib/jekyll-browsersync.rb +2 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef4e2533e894b7a00104e9665fbbf20d2c8ad3d0
|
4
|
+
data.tar.gz: 8b6dd382b6c26f75c9ad7baa4f5745b7528e993c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7af612def7489b52db670a105b48a92427d2f661a7e40028a93c1ab575b179af8672fb903484845d93b9d98cc1711664a79771552d8def01c32b595d4965bdc9
|
7
|
+
data.tar.gz: 62031004e1188ff064a2d90608c960e4cbc935f630cf7cc8c26ec2312dfb0c9a7c449f2e58f91d9d08e0d205ca9a36d8f046644dc54ce0e5e5bf96180b6e50f6
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2016 Matthew Loberg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Jekyll Browsersync
|
2
|
+
|
3
|
+
Add live reloading to your Jekyll development using [Browsersync](https://www.browsersync.io/).
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* Jekyll >= 3
|
8
|
+
* [Browsersync](https://www.browsersync.io/) installed
|
9
|
+
* globally (`npm install -g browser-sync` ) **OR**
|
10
|
+
* locally (`npm install browser-sync`)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'jekyll-browsersync', group: [:jekyll_plugins]
|
17
|
+
|
18
|
+
Then install it
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Once you have it installed, you should have a new `browser-sync` command under Jekyll.
|
25
|
+
|
26
|
+
$ bundle exec jekyll browser-sync
|
27
|
+
|
28
|
+
If you have Browsersync installed in a custom location, you can specify this with the
|
29
|
+
`--browser-sync` option.
|
30
|
+
|
31
|
+
$ bundle exec jekyll browsersync --browser-sync ~/bin/browser-sync
|
32
|
+
|
33
|
+
If you would like to serve the site using https, use the `--https` option.
|
34
|
+
|
35
|
+
$ bundle exec jekyll bs --https
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it (https://github.com/mloberg/jekyll-browsersync/fork)
|
40
|
+
2. Create your feature branch (`git checkout -b feature/my-awesome-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin feature/my-awesome-feature`)
|
43
|
+
5. Create new Pull Request
|
44
|
+
|
45
|
+
## TODO
|
46
|
+
|
47
|
+
* Write tests
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'pty'
|
2
|
+
|
3
|
+
module Mlo
|
4
|
+
module Jekyll
|
5
|
+
module BrowserSync
|
6
|
+
class Command < ::Jekyll::Command
|
7
|
+
class << self
|
8
|
+
DEFAULT_BROWSERSYNC_PATH = 'node_modules/.bin/browser-sync'
|
9
|
+
COMMAND_OPTIONS = {
|
10
|
+
"https" => ["--https", "Use HTTPS"],
|
11
|
+
"host" => ["host", "-H", "--host [HOST]", "Host to bind to"],
|
12
|
+
"open_url" => ["-o", "--open-url", "Launch your site in a browser"],
|
13
|
+
"port" => ["-P", "--port [PORT]", "Port to listen on"],
|
14
|
+
"show_dir_listing" => ["--show-dir-listing",
|
15
|
+
"Show a directory listing instead of loading your index file."],
|
16
|
+
"skip_initial_build" => ["skip_initial_build", "--skip-initial-build",
|
17
|
+
"Skips the initial site build which occurs before the server is started."],
|
18
|
+
"ui_port" => ["--ui-port [PORT]",
|
19
|
+
"The port for Browsersync UI to run on"],
|
20
|
+
"browsersync" => ["--browser-sync [PATH]",
|
21
|
+
"Specify the path to the Browsersync binary if in custom location."],
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
def init_with_program(prog)
|
25
|
+
prog.command("browser-sync") do |cmd|
|
26
|
+
cmd.syntax "browser-sync [options]"
|
27
|
+
cmd.description 'Serve a Jekyll site using Browsersync.'
|
28
|
+
cmd.alias :browsersync
|
29
|
+
cmd.alias :bs
|
30
|
+
|
31
|
+
add_build_options(cmd)
|
32
|
+
|
33
|
+
COMMAND_OPTIONS.each do |key, val|
|
34
|
+
cmd.option key, *val
|
35
|
+
end
|
36
|
+
|
37
|
+
cmd.action do |_, opts|
|
38
|
+
opts['serving'] = true
|
39
|
+
opts['watch'] = true unless opts.key?('watch')
|
40
|
+
opts['incremental'] = true unless opts.key?('incremental')
|
41
|
+
opts['port'] = 4000 unless opts.key?('port')
|
42
|
+
opts['host'] = '127.0.0.1' unless opts.key?('host')
|
43
|
+
opts['ui_port'] = 3001 unless opts.key?('ui_port')
|
44
|
+
opts['browsersync'] = locate_browsersync unless opts.key?('browsersync')
|
45
|
+
|
46
|
+
validate!(opts)
|
47
|
+
|
48
|
+
config = opts['config']
|
49
|
+
::Jekyll::Commands::Build.process(opts)
|
50
|
+
opts['config'] = config
|
51
|
+
Command.process(opts)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def process(opts)
|
57
|
+
opts = configuration_from_options(opts)
|
58
|
+
destination = opts['destination']
|
59
|
+
|
60
|
+
cmd = [
|
61
|
+
opts['browsersync'],
|
62
|
+
'start',
|
63
|
+
"--server #{destination}",
|
64
|
+
"--files #{destination}",
|
65
|
+
"--port #{opts['port']}",
|
66
|
+
"--host #{opts['host']}",
|
67
|
+
"--ui-port #{opts['ui_port']}",
|
68
|
+
]
|
69
|
+
|
70
|
+
cmd << '--https' if opts['https']
|
71
|
+
cmd << '--no-open' unless opts['open_url']
|
72
|
+
cmd << '--directory' if opts['show_dir_listing']
|
73
|
+
|
74
|
+
PTY.spawn(cmd.join(' ')) do |stdout, stdin, pid|
|
75
|
+
trap("INT") { Process.kill 'INT', pid }
|
76
|
+
|
77
|
+
::Jekyll.logger.info "Server address:", server_address(opts)
|
78
|
+
::Jekyll.logger.info "UI address:", server_address(opts, 'ui')
|
79
|
+
|
80
|
+
begin
|
81
|
+
stdout.each { |line| ::Jekyll.logger.debug line.rstrip }
|
82
|
+
rescue
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def locate_browsersync
|
90
|
+
return DEFAULT_BROWSERSYNC_PATH if File.exists?(DEFAULT_BROWSERSYNC_PATH)
|
91
|
+
return which('browser-sync')
|
92
|
+
end
|
93
|
+
|
94
|
+
# Validate command options
|
95
|
+
def validate!(opts)
|
96
|
+
browsersync_version = `#{opts['browsersync']} --version 2>/dev/null`
|
97
|
+
|
98
|
+
raise RuntimeError.new('Unable to locate browser-sync binary.') if browsersync_version.empty?
|
99
|
+
end
|
100
|
+
|
101
|
+
def server_address(opts, server = nil)
|
102
|
+
format("%{protocol}://%{address}:%{port}%{baseurl}", {
|
103
|
+
:protocol => opts['https'] ? 'https' : 'http',
|
104
|
+
:address => opts['host'],
|
105
|
+
:port => server == 'ui' ? opts['ui_port'] : opts['port'],
|
106
|
+
:baseurl => opts['baseurl'] ? "#{opts["baseurl"]}/" : '',
|
107
|
+
})
|
108
|
+
end
|
109
|
+
|
110
|
+
# Cross-platform way of finding an executable in the $PATH.
|
111
|
+
#
|
112
|
+
# See: http://stackoverflow.com/a/5471032/1264736
|
113
|
+
#
|
114
|
+
# which('ruby') #=> /usr/bin/ruby
|
115
|
+
def which(cmd)
|
116
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
117
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
118
|
+
exts.each { |ext|
|
119
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
120
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
121
|
+
}
|
122
|
+
end
|
123
|
+
return nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-browsersync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Loberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.5'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
description: Add live reloading to Jekyll using Browsersync.
|
62
|
+
email:
|
63
|
+
- loberg.matt@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- lib/jekyll-browsersync/command.rb
|
69
|
+
- lib/jekyll-browsersync/version.rb
|
70
|
+
- lib/jekyll-browsersync.rb
|
71
|
+
- README.md
|
72
|
+
- LICENSE
|
73
|
+
homepage: https://github.com/mloberg/jekyll-browsersync
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.14
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Add live reloading to Jekyll using Browsersync.
|
97
|
+
test_files: []
|