jekyll-postcss 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40a31b02e606d19f4ad21d91e81bd795664bc41d7bfff60e7b4c7c85e17689ad
4
- data.tar.gz: e4a7b58085f0068b69b8e9e669570de8ccc59c488a3ccd9bb5c6cf91109ee11a
3
+ metadata.gz: 635d3d12852e6842c6d3b24493c98b986578b6209ad1628c7005e4ea7f3db7ce
4
+ data.tar.gz: bbafa3ff24e1186926a16ca4c9d9ae240035d95ded1e5e9005c814fe777e780f
5
5
  SHA512:
6
- metadata.gz: d5457966cfe09b1a8a96ae0185a91f587fc6316b5753d714e87c9dea4a8a9f5744674b0215b7d788df51abbaad29562e986a804fd623ade77f186f76364891f9
7
- data.tar.gz: 24e2c81a3efb38fab5190745fce7b31af5083311d12db6e226383fe562655ded4a4b326e1cc8db271449194315dd70fcdf9f1ebce61c0b5410baefab8c83a3cc
6
+ metadata.gz: fcb25b23596d06b8703b9a72697e614f7733ef7c07ece2ae4537934f4758c478bef4569da98bf99f0ccedfc1d8049d8d6782c349f69685a20f11ac1821004369
7
+ data.tar.gz: 669475b69a173d0aab8ea11aba25f40fadc68167ab0c099e95d94757032eefdbcce8441b487fadb5bbd00e5164e43c94d4953bbd4fa561391cf16744a9f6d609
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
 
13
13
  Gemfile.lock
14
+ node_modules/
15
+ yarn-error.log
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1
4
+
5
+ - Only run development server in development
6
+
3
7
  ## 0.3.0
4
8
 
5
9
  - Update rake
data/README.md CHANGED
@@ -43,9 +43,9 @@ module.exports = {
43
43
 
44
44
  All files with the `.css` extension will now be processed by PostCSS.
45
45
 
46
- ### Note
46
+ ### Notes
47
47
 
48
- `jekyll-postcss` will cache your styles to avoid rebuilding when nothing has changed.
48
+ jekyll-postcss will run a development server when `JEKYLL_ENV` is set to `development`. This is the default value if you don't set it elsewhere. When building your site for production or staging, make sure to set the `JEKYLL_ENV` appropriately, or else your deploy may fail, e.g., `JEKYLL_ENV=production bundle exec jekyll build`.
49
49
 
50
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
51
 
@@ -1,31 +1,50 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const postcss = require(require.resolve("postcss", {paths: [process.cwd()]}));
3
+ const postcss = require(require.resolve("postcss", { paths: [process.cwd()] }));
4
4
  const config = require(`${process.cwd()}/postcss.config.js`);
5
5
  const net = require("net");
6
6
 
7
- const server = net.createServer((c) => {
8
- c.on('data', (data) => {
7
+ class PostCSS {
8
+ static process(data, write) {
9
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());
10
+ .process(JSON.parse(data).raw_content, { from: "stdin" })
11
+ .then((result) => write(result))
12
+ .catch((error) => {
13
+ console.error("PostCSS Error!\n");
14
+ console.error(error.toString());
20
15
  });
21
- });
22
- });
16
+ }
23
17
 
24
- server.on('error', (err) => {
25
- console.log("PostCSS Server Error!\n");
26
- throw err;
27
- });
18
+ static startServer() {
19
+ const server = net.createServer((c) => {
20
+ c.on("data", (data) => {
21
+ this.process(data, function (result) {
22
+ const packet = { compiled_css: result.toString() };
28
23
 
29
- server.listen(8124, () => {
30
- console.log("PostCSS Server listening on port 8124...");
31
- });
24
+ c.write(`${JSON.stringify(packet)}\n`);
25
+ });
26
+ });
27
+ });
28
+
29
+ server.on("error", (err) => {
30
+ console.error("PostCSS Server Error!\n");
31
+ throw err;
32
+ });
33
+
34
+ server.listen(8124, () => {
35
+ console.log("PostCSS Server listening on port 8124...");
36
+ });
37
+ }
38
+ }
39
+
40
+ switch (process.argv[2]) {
41
+ case "--development":
42
+ PostCSS.startServer();
43
+ break;
44
+ default:
45
+ PostCSS.process(process.argv[2], function (result) {
46
+ const packet = { compiled_css: result.toString() };
47
+
48
+ process.stdout.write(`${JSON.stringify(packet)}`);
49
+ });
50
+ }
@@ -2,15 +2,57 @@
2
2
 
3
3
  require "socket"
4
4
  require "json"
5
+ require "open3"
5
6
 
6
7
  module PostCss
7
8
  class Socket
9
+ class PostCssRuntimeError; end
8
10
  START_SCRIPT = File.expand_path("../../bin/command", __dir__)
9
11
  POSTCSS_SCRIPT = File.expand_path("../../bin/postcss", __dir__)
10
12
 
11
13
  def initialize
14
+ start_dev_server if development?
15
+ end
16
+
17
+ def write(data)
18
+ if development?
19
+ @postcss.puts encode(data)
20
+ else
21
+ @compiled_css = `#{POSTCSS_SCRIPT} '#{encode(data)}'`
22
+ end
23
+
24
+ nil
25
+ end
26
+
27
+ def read
28
+ if development?
29
+ decode(@postcss.gets.chomp)
30
+ else
31
+ raise "You must call PostCss#write before calling PostCss#read" if @compiled_css.nil?
32
+
33
+ @compiled_css
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def encode(data)
40
+ JSON.dump(:raw_content => data)
41
+ end
42
+
43
+ def decode(data)
44
+ JSON.parse(data)["compiled_css"]
45
+ end
46
+
47
+ def development?
48
+ @env ||= Jekyll.env
49
+
50
+ @env == "development"
51
+ end
52
+
53
+ def start_dev_server
12
54
  Thread.new do
13
- system "#{START_SCRIPT} #{POSTCSS_SCRIPT}"
55
+ system "#{START_SCRIPT} #{POSTCSS_SCRIPT} --development"
14
56
  end
15
57
 
16
58
  @postcss = nil
@@ -22,13 +64,5 @@ module PostCss
22
64
  end
23
65
  end
24
66
  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
67
  end
34
68
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module PostCss
5
- VERSION = "0.3.0"
5
+ VERSION = "0.3.1"
6
6
  end
7
7
  end
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "jekyll-postcss",
3
+ "version": "0.3.0",
4
+ "repository": "git@github.com:mhanberg/jekyll-postcss.git",
5
+ "author": "Mitchell Hanberg <mitch@mitchellhanberg.com>",
6
+ "license": "MIT",
7
+ "devDependencies": {
8
+ "prettier": "^2.0.5"
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
5
+ prettier@^2.0.5:
6
+ version "2.0.5"
7
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
8
+ integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hanberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-16 00:00:00.000000000 Z
11
+ date: 2020-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,6 +107,8 @@ files:
107
107
  - lib/jekyll-postcss/socket.rb
108
108
  - lib/jekyll-postcss/version.rb
109
109
  - lib/jekyll/converters/postcss.rb
110
+ - package.json
111
+ - yarn.lock
110
112
  homepage: https://github.com/mhanberg/jekyll-postcss
111
113
  licenses:
112
114
  - MIT