jekyll-postcss 0.2.2 → 0.3.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/CHANGELOG.md +5 -0
- data/README.md +17 -3
- data/bin/command +36 -0
- data/bin/postcss +31 -0
- data/jekyll-postcss.gemspec +1 -1
- data/lib/jekyll-postcss/socket.rb +34 -0
- data/lib/jekyll-postcss/version.rb +1 -1
- data/lib/jekyll/converters/postcss.rb +5 -8
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40a31b02e606d19f4ad21d91e81bd795664bc41d7bfff60e7b4c7c85e17689ad
|
4
|
+
data.tar.gz: e4a7b58085f0068b69b8e9e669570de8ccc59c488a3ccd9bb5c6cf91109ee11a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5457966cfe09b1a8a96ae0185a91f587fc6316b5753d714e87c9dea4a8a9f5744674b0215b7d788df51abbaad29562e986a804fd623ade77f186f76364891f9
|
7
|
+
data.tar.gz: 24e2c81a3efb38fab5190745fce7b31af5083311d12db6e226383fe562655ded4a4b326e1cc8db271449194315dd70fcdf9f1ebce61c0b5410baefab8c83a3cc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,27 +24,41 @@ plugins:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
Make sure you have [postcss
|
27
|
+
Make sure you have [postcss](https://github.com/postcss/postcss) installed.
|
28
28
|
|
29
29
|
Add your PostCSS plugins to a `postcss.config.js` file in the root of your repository.
|
30
30
|
|
31
31
|
```javascript
|
32
32
|
// postcss.config.js
|
33
33
|
|
34
|
-
module.exports {
|
34
|
+
module.exports = {
|
35
35
|
plugins: [
|
36
36
|
require("autoprefixer") // example of plugin you might use
|
37
|
+
...(process.env.JEKYLL_ENV == "production" // example of only using a plugin in production
|
38
|
+
? [require("cssnano")({ preset: "default" })]
|
39
|
+
: [])
|
37
40
|
]
|
38
41
|
};
|
39
42
|
```
|
40
43
|
|
41
44
|
All files with the `.css` extension will now be processed by PostCSS.
|
42
45
|
|
43
|
-
|
44
46
|
### Note
|
45
47
|
|
46
48
|
`jekyll-postcss` will cache your styles to avoid rebuilding when nothing has changed.
|
47
49
|
|
50
|
+
Also note that your `.css` files still need to have a [front matter](https://jekyllrb.com/docs/step-by-step/03-front-matter/) for them to be processed by Jekyll.
|
51
|
+
|
52
|
+
```
|
53
|
+
---
|
54
|
+
---
|
55
|
+
|
56
|
+
/* Example using Tailwind */
|
57
|
+
@tailwind base;
|
58
|
+
@tailwind components;
|
59
|
+
@tailwind utilities;
|
60
|
+
```
|
61
|
+
|
48
62
|
## Development
|
49
63
|
|
50
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/bin/command
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
script_status="running"
|
4
|
+
|
5
|
+
# Start the program in the background
|
6
|
+
exec "$@" &
|
7
|
+
pid1=$!
|
8
|
+
|
9
|
+
shutdown(){
|
10
|
+
local pid1=$1
|
11
|
+
local pid2=$2
|
12
|
+
|
13
|
+
if [ $script_status = "running" ]; then
|
14
|
+
script_status="shutting down"
|
15
|
+
wait "$pid1"
|
16
|
+
ret=$?
|
17
|
+
kill -KILL "$pid2"
|
18
|
+
exit $ret
|
19
|
+
fi
|
20
|
+
}
|
21
|
+
|
22
|
+
# Silence warnings from here on
|
23
|
+
exec >/dev/null 2>&1
|
24
|
+
|
25
|
+
# Read from stdin in the background and
|
26
|
+
# kill running program when stdin closes
|
27
|
+
exec 0<&0 "$(
|
28
|
+
while read -r; do :; done
|
29
|
+
kill -KILL "$pid1"
|
30
|
+
)" &
|
31
|
+
pid2=$!
|
32
|
+
|
33
|
+
# Clean up
|
34
|
+
trap 'shutdown $pid1 $pid2' INT HUP TERM
|
35
|
+
shutdown "$pid1" "$pid2"
|
36
|
+
|
data/bin/postcss
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const postcss = require(require.resolve("postcss", {paths: [process.cwd()]}));
|
4
|
+
const config = require(`${process.cwd()}/postcss.config.js`);
|
5
|
+
const net = require("net");
|
6
|
+
|
7
|
+
const server = net.createServer((c) => {
|
8
|
+
c.on('data', (data) => {
|
9
|
+
postcss(config.plugins)
|
10
|
+
.process(JSON.parse(data).raw_content, {from: "stdin"})
|
11
|
+
.then(result => {
|
12
|
+
const packet = { compiled_css: result.toString() };
|
13
|
+
c.write(`${JSON.stringify(packet)}\n`);
|
14
|
+
|
15
|
+
return;
|
16
|
+
})
|
17
|
+
.catch(error => {
|
18
|
+
console.log("PostCSS Error!\n");
|
19
|
+
console.log(error.toString());
|
20
|
+
});
|
21
|
+
});
|
22
|
+
});
|
23
|
+
|
24
|
+
server.on('error', (err) => {
|
25
|
+
console.log("PostCSS Server Error!\n");
|
26
|
+
throw err;
|
27
|
+
});
|
28
|
+
|
29
|
+
server.listen(8124, () => {
|
30
|
+
console.log("PostCSS Server listening on port 8124...");
|
31
|
+
});
|
data/jekyll-postcss.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.17"
|
33
33
|
spec.add_development_dependency "jekyll",
|
34
34
|
ENV["JEKYLL_VERSION"] ? "~> #{ENV["JEKYLL_VERSION"]}" : ">= 2.0"
|
35
|
-
spec.add_development_dependency "rake", "
|
35
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
36
36
|
spec.add_development_dependency "rspec", "~> 3.0"
|
37
37
|
spec.add_development_dependency "rubocop-jekyll", "~> 0.5.1"
|
38
38
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "socket"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module PostCss
|
7
|
+
class Socket
|
8
|
+
START_SCRIPT = File.expand_path("../../bin/command", __dir__)
|
9
|
+
POSTCSS_SCRIPT = File.expand_path("../../bin/postcss", __dir__)
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
Thread.new do
|
13
|
+
system "#{START_SCRIPT} #{POSTCSS_SCRIPT}"
|
14
|
+
end
|
15
|
+
|
16
|
+
@postcss = nil
|
17
|
+
while @postcss.nil?
|
18
|
+
begin
|
19
|
+
@postcss = TCPSocket.open("localhost", 8124)
|
20
|
+
rescue StandardError
|
21
|
+
nil # Suppressing exceptions
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def write(data)
|
27
|
+
@postcss.puts JSON.dump(:raw_content => data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def read
|
31
|
+
JSON.parse(@postcss.gets.chomp)["compiled_css"]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "open3"
|
4
3
|
require "digest"
|
4
|
+
require_relative "../../jekyll-postcss/socket"
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
module Converters
|
@@ -12,6 +12,7 @@ module Jekyll
|
|
12
12
|
def initialize(config = {})
|
13
13
|
super
|
14
14
|
|
15
|
+
@socket = config.fetch("socket") { ::PostCss::Socket.new }
|
15
16
|
@raw_cache = nil
|
16
17
|
@import_raw_cache = {}
|
17
18
|
@converted_cache = nil
|
@@ -26,7 +27,7 @@ module Jekyll
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def convert(content)
|
29
|
-
raise PostCssNotFoundError unless
|
30
|
+
raise PostCssNotFoundError unless Dir.exist?("./node_modules/postcss")
|
30
31
|
|
31
32
|
@raw_digest = Digest::MD5.hexdigest content
|
32
33
|
@raw_import_digests = import_digests(content)
|
@@ -35,12 +36,9 @@ module Jekyll
|
|
35
36
|
@raw_cache = @raw_digest.dup
|
36
37
|
@import_raw_cache = @raw_import_digests.dup
|
37
38
|
|
38
|
-
|
39
|
-
Open3.capture2("./node_modules/.bin/postcss", :stdin_data => content)
|
39
|
+
@socket.write content
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
@converted_cache = compiled_css
|
41
|
+
@converted_cache = @socket.read
|
44
42
|
end
|
45
43
|
|
46
44
|
reset
|
@@ -75,4 +73,3 @@ module Jekyll
|
|
75
73
|
end
|
76
74
|
|
77
75
|
class PostCssNotFoundError < RuntimeError; end
|
78
|
-
class PostCssRuntimeError < RuntimeError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-postcss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mitchell Hanberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 12.3.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,10 +98,13 @@ files:
|
|
98
98
|
- LICENSE.txt
|
99
99
|
- README.md
|
100
100
|
- Rakefile
|
101
|
+
- bin/command
|
101
102
|
- bin/console
|
103
|
+
- bin/postcss
|
102
104
|
- bin/setup
|
103
105
|
- jekyll-postcss.gemspec
|
104
106
|
- lib/jekyll-postcss.rb
|
107
|
+
- lib/jekyll-postcss/socket.rb
|
105
108
|
- lib/jekyll-postcss/version.rb
|
106
109
|
- lib/jekyll/converters/postcss.rb
|
107
110
|
homepage: https://github.com/mhanberg/jekyll-postcss
|